|  | 
| 11 | 11 | using System.IO; | 
| 12 | 12 | using System.Linq; | 
| 13 | 13 | using System.Net; | 
|  | 14 | +using System.Net.NetworkInformation; | 
| 14 | 15 | using System.Net.Sockets; | 
|  | 16 | +using System.Runtime.InteropServices; | 
| 15 | 17 | using System.Security; | 
|  | 18 | +using System.Security.Principal; | 
|  | 19 | +using System.Text; | 
| 16 | 20 | using System.Threading; | 
| 17 | 21 | using System.Threading.Tasks; | 
|  | 22 | +using Azure.Core; | 
|  | 23 | +using Azure.Identity; | 
| 18 | 24 | using Microsoft.Data.SqlClient.TestUtilities; | 
| 19 | 25 | using Microsoft.Identity.Client; | 
| 20 | 26 | using Xunit; | 
| 21 |  | -using System.Net.NetworkInformation; | 
| 22 |  | -using System.Text; | 
| 23 |  | -using System.Security.Principal; | 
| 24 |  | -using System.Runtime.InteropServices; | 
| 25 |  | -using Azure.Identity; | 
| 26 |  | -using Azure.Core; | 
| 27 | 27 | 
 | 
| 28 | 28 | namespace Microsoft.Data.SqlClient.ManualTesting.Tests | 
| 29 | 29 | { | 
| @@ -77,10 +77,6 @@ public static class DataTestUtility | 
| 77 | 77 |         public const string AKVEventSourceName = "Microsoft.Data.SqlClient.AlwaysEncrypted.AzureKeyVaultProvider.EventSource"; | 
| 78 | 78 |         private const string ManagedNetworkingAppContextSwitch = "Switch.Microsoft.Data.SqlClient.UseManagedNetworkingOnWindows"; | 
| 79 | 79 | 
 | 
| 80 |  | -        // uap constant | 
| 81 |  | -        const long APPMODEL_ERROR_NO_PACKAGE = 15700L; | 
| 82 |  | -        public static readonly bool IsRunningAsUWPApp = RunningAsUWPApp(); | 
| 83 |  | - | 
| 84 | 80 |         private static Dictionary<string, bool> AvailableDatabases; | 
| 85 | 81 |         private static BaseEventListener TraceListener; | 
| 86 | 82 | 
 | 
| @@ -676,10 +672,6 @@ public static string GetUserIdentityAccessToken() | 
| 676 | 672 | 
 | 
| 677 | 673 |         public static bool IsAccessTokenSetup() => !string.IsNullOrEmpty(GetAccessToken()); | 
| 678 | 674 | 
 | 
| 679 |  | -        public static bool IsSystemIdentityTokenSetup() => !string.IsNullOrEmpty(GetSystemIdentityAccessToken()); | 
| 680 |  | - | 
| 681 |  | -        public static bool IsUserIdentityTokenSetup() => !string.IsNullOrEmpty(GetUserIdentityAccessToken()); | 
| 682 |  | - | 
| 683 | 675 |         public static bool IsFileStreamSetup() => !string.IsNullOrEmpty(FileStreamDirectory) && IsNotAzureServer() && IsNotAzureSynapse(); | 
| 684 | 676 | 
 | 
| 685 | 677 |         private static bool CheckException<TException>(Exception ex, string exceptionMessage, bool innerExceptionMustBeNull) where TException : Exception | 
| @@ -780,58 +772,6 @@ public static TException ExpectFailure<TException>(Action actionThatFails, strin | 
| 780 | 772 |             } | 
| 781 | 773 |         } | 
| 782 | 774 | 
 | 
| 783 |  | -        public static TException ExpectFailure<TException, TInnerException>(Action actionThatFails, string exceptionMessage = null, string innerExceptionMessage = null, bool innerInnerExceptionMustBeNull = false) where TException : Exception where TInnerException : Exception | 
| 784 |  | -        { | 
| 785 |  | -            try | 
| 786 |  | -            { | 
| 787 |  | -                actionThatFails(); | 
| 788 |  | -                Assert.Fail("ERROR: Did not get expected exception"); | 
| 789 |  | -                return null; | 
| 790 |  | -            } | 
| 791 |  | -            catch (Exception ex) | 
| 792 |  | -            { | 
| 793 |  | -                if ((CheckException<TException>(ex, exceptionMessage, false)) && (CheckException<TInnerException>(ex.InnerException, innerExceptionMessage, innerInnerExceptionMustBeNull))) | 
| 794 |  | -                { | 
| 795 |  | -                    return (ex as TException); | 
| 796 |  | -                } | 
| 797 |  | -                else | 
| 798 |  | -                { | 
| 799 |  | -                    throw; | 
| 800 |  | -                } | 
| 801 |  | -            } | 
| 802 |  | -        } | 
| 803 |  | - | 
| 804 |  | -        public static TException ExpectFailure<TException, TInnerException, TInnerInnerException>(Action actionThatFails, string exceptionMessage = null, string innerExceptionMessage = null, string innerInnerExceptionMessage = null, bool innerInnerInnerExceptionMustBeNull = false) where TException : Exception where TInnerException : Exception where TInnerInnerException : Exception | 
| 805 |  | -        { | 
| 806 |  | -            try | 
| 807 |  | -            { | 
| 808 |  | -                actionThatFails(); | 
| 809 |  | -                Assert.Fail("ERROR: Did not get expected exception"); | 
| 810 |  | -                return null; | 
| 811 |  | -            } | 
| 812 |  | -            catch (Exception ex) | 
| 813 |  | -            { | 
| 814 |  | -                if ((CheckException<TException>(ex, exceptionMessage, false)) && (CheckException<TInnerException>(ex.InnerException, innerExceptionMessage, false)) && (CheckException<TInnerInnerException>(ex.InnerException.InnerException, innerInnerExceptionMessage, innerInnerInnerExceptionMustBeNull))) | 
| 815 |  | -                { | 
| 816 |  | -                    return (ex as TException); | 
| 817 |  | -                } | 
| 818 |  | -                else | 
| 819 |  | -                { | 
| 820 |  | -                    throw; | 
| 821 |  | -                } | 
| 822 |  | -            } | 
| 823 |  | -        } | 
| 824 |  | - | 
| 825 |  | -        public static void ExpectAsyncFailure<TException>(Func<Task> actionThatFails, string exceptionMessage = null, bool innerExceptionMustBeNull = false) where TException : Exception | 
| 826 |  | -        { | 
| 827 |  | -            ExpectFailure<AggregateException, TException>(() => actionThatFails().Wait(), null, exceptionMessage, innerExceptionMustBeNull); | 
| 828 |  | -        } | 
| 829 |  | - | 
| 830 |  | -        public static void ExpectAsyncFailure<TException, TInnerException>(Func<Task> actionThatFails, string exceptionMessage = null, string innerExceptionMessage = null, bool innerInnerExceptionMustBeNull = false) where TException : Exception where TInnerException : Exception | 
| 831 |  | -        { | 
| 832 |  | -            ExpectFailure<AggregateException, TException, TInnerException>(() => actionThatFails().Wait(), null, exceptionMessage, innerExceptionMessage, innerInnerExceptionMustBeNull); | 
| 833 |  | -        } | 
| 834 |  | - | 
| 835 | 775 |         public static string GenerateObjectName() | 
| 836 | 776 |         { | 
| 837 | 777 |             return string.Format("TEST_{0}{1}{2}", Environment.GetEnvironmentVariable("ComputerName"), Environment.TickCount, Guid.NewGuid()).Replace('-', '_'); | 
| @@ -1093,44 +1033,5 @@ public static string GetMachineFQDN(string hostname) | 
| 1093 | 1033 |             } | 
| 1094 | 1034 |             return fqdn.ToString(); | 
| 1095 | 1035 |         } | 
| 1096 |  | - | 
| 1097 |  | -        public static bool IsNotLocalhost() | 
| 1098 |  | -        { | 
| 1099 |  | -            // get the tcp connection string | 
| 1100 |  | -            SqlConnectionStringBuilder builder = new(DataTestUtility.TCPConnectionString); | 
| 1101 |  | - | 
| 1102 |  | -            string hostname = ""; | 
| 1103 |  | - | 
| 1104 |  | -            // parse the datasource | 
| 1105 |  | -            ParseDataSource(builder.DataSource, out hostname, out _, out _); | 
| 1106 |  | - | 
| 1107 |  | -            // hostname must not be localhost, ., 127.0.0.1 nor ::1 | 
| 1108 |  | -            return !(new string[] { "localhost", ".", "127.0.0.1", "::1" }).Contains(hostname.ToLowerInvariant()); | 
| 1109 |  | - | 
| 1110 |  | -        } | 
| 1111 |  | - | 
| 1112 |  | -        private static bool RunningAsUWPApp() | 
| 1113 |  | -        { | 
| 1114 |  | -            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) | 
| 1115 |  | -            { | 
| 1116 |  | -                return false; | 
| 1117 |  | -            } | 
| 1118 |  | -            else | 
| 1119 |  | -            { | 
| 1120 |  | -                [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)] | 
| 1121 |  | -                static extern int GetCurrentPackageFullName(ref int packageFullNameLength, StringBuilder packageFullName); | 
| 1122 |  | - | 
| 1123 |  | -                { | 
| 1124 |  | -                    int length = 0; | 
| 1125 |  | -                    StringBuilder sb = new(0); | 
| 1126 |  | -                    _ = GetCurrentPackageFullName(ref length, sb); | 
| 1127 |  | - | 
| 1128 |  | -                    sb = new StringBuilder(length); | 
| 1129 |  | -                    int result = GetCurrentPackageFullName(ref length, sb); | 
| 1130 |  | - | 
| 1131 |  | -                    return result != APPMODEL_ERROR_NO_PACKAGE; | 
| 1132 |  | -                } | 
| 1133 |  | -            } | 
| 1134 |  | -        } | 
| 1135 | 1036 |     } | 
| 1136 | 1037 | } | 
0 commit comments