/// <summary> /// Return a local WebDriver of the given browser type with default settings. /// </summary> /// <param name="browser"></param> /// <param name="windowSize"></param> /// <param name="headless"></param> /// <param name="windowCustomSize"></param> /// <returns></returns> public virtual IWebDriver GetWebDriver(Browser browser, WindowSize windowSize = WindowSize.Hd, bool headless = false, Size windowCustomSize = new Size()) { if (headless && !(browser == Browser.Chrome || browser == Browser.Edge || browser == Browser.Firefox)) { Exception ex = new ArgumentException($"Headless mode is not currently supported for {browser}."); Logger.Fatal("Invalid WebDriver Configuration requested.", ex); throw ex; } switch (browser) { case Browser.Firefox: return(GetWebDriver(DriverOptionsFactory.GetLocalDriverOptions <FirefoxOptions>(headless), windowSize, windowCustomSize)); case Browser.Chrome: return(GetWebDriver(DriverOptionsFactory.GetLocalDriverOptions <ChromeOptions>(headless), windowSize, windowCustomSize)); case Browser.InternetExplorer: return(GetWebDriver(DriverOptionsFactory.GetLocalDriverOptions <InternetExplorerOptions>(), windowSize, windowCustomSize)); case Browser.Edge: return(GetWebDriver(DriverOptionsFactory.GetLocalDriverOptions <EdgeOptions>(headless), windowSize, windowCustomSize)); case Browser.Safari: return(GetWebDriver(DriverOptionsFactory.GetLocalDriverOptions <SafariOptions>(), windowSize, windowCustomSize)); default: Exception ex = new PlatformNotSupportedException($"{browser} is not currently supported."); Logger.Fatal("Invalid WebDriver Configuration requested.", ex); throw ex; } }
public bool PosTest1() { bool retVal = true; const string c_TEST_ID = "P001"; string c_TEST_DESC = "PosTest1: initialize an instance of type PlatformNotSupportedException using an emtpy string message"; string errorDesc; string message = string.Empty; TestLibrary.TestFramework.BeginScenario(c_TEST_DESC); try { PlatformNotSupportedException e = new PlatformNotSupportedException(message); if (null == e || e.Message != message) { errorDesc = "Failed to initialize an instance of type PlatformNotSupportedException."; errorDesc += "\nInput message is emtpy string"; TestLibrary.TestFramework.LogError("001" + " TestId-" + c_TEST_ID, errorDesc); retVal = false; } } catch (Exception e) { errorDesc = "Unexpected exception: " + e; errorDesc += "\nInput message is emtpy string"; TestLibrary.TestFramework.LogError("002" + " TestId-" + c_TEST_ID, errorDesc); retVal = false; } return retVal; }
public void LogException_WithException_CreatesExceptionTelemetry() { // Arrange string platform = $"platform-id-{Guid.NewGuid()}"; var exception = new PlatformNotSupportedException(platform); var spySink = new InMemoryLogSink(); string operationId = $"operation-id-{Guid.NewGuid()}"; ILogger logger = CreateLogger(spySink, config => config.Enrich.WithProperty(ContextProperties.Correlation.OperationId, operationId)); logger.LogCritical(exception, exception.Message); LogEvent logEvent = Assert.Single(spySink.CurrentLogEmits); Assert.NotNull(logEvent); var converter = ApplicationInsightsTelemetryConverter.Create(); // Act IEnumerable <ITelemetry> telemetries = converter.Convert(logEvent, formatProvider: null); // Assert Assert.Collection(telemetries, telemetry => { var exceptionTelemetryType = Assert.IsType <ExceptionTelemetry>(telemetry); Assert.NotNull(exceptionTelemetryType); Assert.NotNull(exceptionTelemetryType.Exception); Assert.Equal(exception.Message, exceptionTelemetryType.Exception.Message); AssertOperationContext(exceptionTelemetryType, operationId); }); }
public async Task LogExceptionWithComponentName_SinksToApplicationInsights_ResultsInTelemetryWithComponentName() { // Arrange string message = BogusGenerator.Lorem.Sentence(); string componentName = BogusGenerator.Commerce.ProductName(); var exception = new PlatformNotSupportedException(message); using (ILoggerFactory loggerFactory = CreateLoggerFactory(config => config.Enrich.WithComponentName(componentName))) { ILogger logger = loggerFactory.CreateLogger <ApplicationInsightsSinkTests>(); // Act logger.LogCritical(exception, exception.Message); } // Assert using (ApplicationInsightsDataClient client = CreateApplicationInsightsClient()) { await RetryAssertUntilTelemetryShouldBeAvailableAsync(async() => { EventsResults <EventsExceptionResult> results = await client.Events.GetExceptionEventsAsync(ApplicationId, filter: OnlyLastHourFilter); Assert.NotEmpty(results.Value); Assert.Contains(results.Value, result => result.Exception.OuterMessage == exception.Message && result.Cloud.RoleName == componentName); }); } }
public bool PosTest1() { bool retVal = true; const string c_TEST_ID = "P001"; string c_TEST_DESC = "PosTest1: initialize an instance of type PlatformNotSupportedException using an emtpy string message"; string errorDesc; string message = string.Empty; Exception innerException = new ArgumentNullException(); TestLibrary.TestFramework.BeginScenario(c_TEST_DESC); try { PlatformNotSupportedException e = new PlatformNotSupportedException(message, innerException); if (null == e || e.Message != message || e.InnerException != innerException) { errorDesc = "Failed to initialize an instance of type PlatformNotSupportedException."; errorDesc += "\nInput message is emtpy string"; errorDesc += "\nInner exception is " + innerException; TestLibrary.TestFramework.LogError("001" + " TestId-" + c_TEST_ID, errorDesc); retVal = false; } } catch (Exception e) { errorDesc = "Unexpected exception: " + e; errorDesc += "\nInput message is emtpy string"; errorDesc += "\nInner exception is " + innerException; TestLibrary.TestFramework.LogError("002" + " TestId-" + c_TEST_ID, errorDesc); retVal = false; } return(retVal); }
public bool PosTest2() { bool retVal = true; const string c_TEST_ID = "P002"; string c_TEST_DESC = "PosTest2: initialize an instance of type PlatformNotSupportedException using a string containing special character"; string errorDesc; string message = "Not supported exception occurs here \n\r\0\t\v"; TestLibrary.TestFramework.BeginScenario(c_TEST_DESC); try { PlatformNotSupportedException e = new PlatformNotSupportedException(message); if (null == e || e.Message != message) { errorDesc = "Failed to initialize an instance of type PlatformNotSupportedException."; errorDesc += "\nInput message is \"" + message + "\""; TestLibrary.TestFramework.LogError("003" + " TestId-" + c_TEST_ID, errorDesc); retVal = false; } } catch (Exception e) { errorDesc = "Unexpected exception: " + e; errorDesc += "\nInput message is \"" + message + "\""; TestLibrary.TestFramework.LogError("004" + " TestId-" + c_TEST_ID, errorDesc); retVal = false; } return retVal; }
public bool PosTest1() { bool retVal = true; const string c_TEST_ID = "P001"; string c_TEST_DESC = "PosTest1: initialize an instance of type PlatformNotSupportedException via default constructor"; string errorDesc; TestLibrary.TestFramework.BeginScenario(c_TEST_DESC); try { PlatformNotSupportedException e = new PlatformNotSupportedException(); if (null == e) { errorDesc = "Failed to initialize an instance of type PlatformNotSupportedException via default constructor."; TestLibrary.TestFramework.LogError("001" + " TestId-" + c_TEST_ID, errorDesc); retVal = false; } } catch (Exception e) { errorDesc = "Unexpected exception: " + e; TestLibrary.TestFramework.LogError("002" + " TestId-" + c_TEST_ID, errorDesc); retVal = false; } return retVal; }
public bool PosTest1() { bool retVal = true; const string c_TEST_ID = "P001"; string c_TEST_DESC = "PosTest1: initialize an instance of type PlatformNotSupportedException via default constructor"; string errorDesc; TestLibrary.TestFramework.BeginScenario(c_TEST_DESC); try { PlatformNotSupportedException e = new PlatformNotSupportedException(); if (null == e) { errorDesc = "Failed to initialize an instance of type PlatformNotSupportedException via default constructor."; TestLibrary.TestFramework.LogError("001" + " TestId-" + c_TEST_ID, errorDesc); retVal = false; } } catch (Exception e) { errorDesc = "Unexpected exception: " + e; TestLibrary.TestFramework.LogError("002" + " TestId-" + c_TEST_ID, errorDesc); retVal = false; } return(retVal); }
public bool PosTest2() { bool retVal = true; const string c_TEST_ID = "P002"; string c_TEST_DESC = "PosTest2: initialize an instance of type PlatformNotSupportedException using a string containing special character"; string errorDesc; string message = "Not supported exception occurs here \n\r\0\t\v"; Exception innerException = new Exception(); TestLibrary.TestFramework.BeginScenario(c_TEST_DESC); try { PlatformNotSupportedException e = new PlatformNotSupportedException(message, innerException); if (null == e || e.Message != message || e.InnerException != innerException) { errorDesc = "Failed to initialize an instance of type PlatformNotSupportedException."; errorDesc += "\nInput message is \"" + message + "\""; errorDesc += "\nInner exception is " + innerException; TestLibrary.TestFramework.LogError("003" + " TestId-" + c_TEST_ID, errorDesc); retVal = false; } } catch (Exception e) { errorDesc = "Unexpected exception: " + e; errorDesc += "\nInput message is \"" + message + "\""; errorDesc += "\nInner exception is " + innerException; TestLibrary.TestFramework.LogError("004" + " TestId-" + c_TEST_ID, errorDesc); retVal = false; } return(retVal); }
public static void Ctor_String() { string message = "platform not supported"; var exception = new PlatformNotSupportedException(message); ExceptionHelpers.ValidateExceptionProperties(exception, hResult: COR_E_PLATFORMNOTSUPPORTED, message: message); }
public void DotnetCoreNotCurrentlySupported() { List <string> options = new List <string>(new string[] { "sharedmemoryname", "pipe", "useperformancemonitor", }); if (Platform.IsWindows()) { options.Add("integratedsecurity"); } foreach (string option in options) { PlatformNotSupportedException ex = Assert.Throws <PlatformNotSupportedException>(() => { MySqlConnectionStringBuilder connString = new MySqlConnectionStringBuilder($"server=localhost;user=root;password=;{option}=dummy"); }); } MySqlConnectionStringBuilder csb = new MySqlConnectionStringBuilder(); Assert.Throws <PlatformNotSupportedException>(() => csb.SharedMemoryName = "dummy"); if (Platform.IsWindows()) { Assert.Throws <PlatformNotSupportedException>(() => csb.IntegratedSecurity = true); } Assert.Throws <PlatformNotSupportedException>(() => csb.PipeName = "dummy"); Assert.Throws <PlatformNotSupportedException>(() => csb.UsePerformanceMonitor = true); csb.ConnectionProtocol = MySqlConnectionProtocol.Tcp; Assert.Throws <PlatformNotSupportedException>(() => csb.ConnectionProtocol = MySqlConnectionProtocol.SharedMemory); Assert.Throws <PlatformNotSupportedException>(() => csb.ConnectionProtocol = MySqlConnectionProtocol.NamedPipe); }
public void Create_InvalidECCurveFriendlyName_ThrowsPlatformNotSupportedException() { ECCurve curve = ECCurve.CreateFromFriendlyName("bad potato"); PlatformNotSupportedException pnse = Assert.Throws <PlatformNotSupportedException>(() => ECDiffieHellman.Create(curve)); Assert.Contains("'bad potato'", pnse.Message); }
public bool PosTest3() { bool retVal = true; const string c_TEST_ID = "P003"; string c_TEST_DESC = "PosTest3: initialize an instance of type PlatformNotSupportedException using a null reference"; string errorDesc; string message = null; Exception innerException = new Exception(); TestLibrary.TestFramework.BeginScenario(c_TEST_DESC); try { PlatformNotSupportedException e = new PlatformNotSupportedException(message, innerException); if (null == e) { errorDesc = "Failed to initialize an instance of type PlatformNotSupportedException."; errorDesc += "\nInput message is a null reference."; errorDesc += "\nInner exception is " + innerException; TestLibrary.TestFramework.LogError("005" + " TestId-" + c_TEST_ID, errorDesc); retVal = false; } } catch (Exception e) { errorDesc = "Unexpected exception: " + e; errorDesc += "\nInput message is a null reference."; errorDesc += "\nInner exception is " + innerException; TestLibrary.TestFramework.LogError("006" + " TestId-" + c_TEST_ID, errorDesc); retVal = false; } return(retVal); }
public static void Ctor_String_Exception() { string message = "platform not supported"; var innerException = new Exception("Inner exception"); var exception = new PlatformNotSupportedException(message, innerException); ExceptionUtility.ValidateExceptionProperties(exception, hResult: COR_E_PLATFORMNOTSUPPORTED, innerException: innerException, message: message); }
protected PlatformNotSupportedException GetLoggedWrongPlatformNameException(string actualPlatform) { var message = AqualityServices.Get <ILocalizationManager>() .GetLocalizedMessage("loc.platform.name.wrong", actualPlatform); var exception = new PlatformNotSupportedException(message); AqualityServices.Logger.Fatal(message, exception); return(exception); }
private void InstanceOnPlatformNotSupportedException(object sender, PlatformNotSupportedException e) { Dispatcher.Invoke(() => { var m = MessageBox.Show("No bluetooth adapter found.\nPlease enable bluetooth and try again.", "Galaxy Buds Manager", MessageBoxButton.OK, MessageBoxImage.Error); Environment.Exit(0); }); }
private void InstanceOnPlatformNotSupportedException(object sender, PlatformNotSupportedException e) { Dispatcher.Invoke(() => { var m = MessageBox.Show(Loc.GetString("nobluetoothdev"), "Galaxy Buds Manager", MessageBoxButton.OK, MessageBoxImage.Error); Environment.Exit(0); }); }
private void InstanceOnPlatformNotSupportedException(object sender, PlatformNotSupportedException e) { Dispatcher.Invoke(() => { MessageBox.Show("No bluetooth adapter found.\nPlease enable bluetooth and try again.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); Close(); }); }
public void Test() { string message = "This is a test of serialized event data."; Exception myError = new PlatformNotSupportedException("Error.Message", new InsufficientMemoryException()); LogEventArgs arg1 = null; LogEventHandler eh = new LogEventHandler(delegate(object s, LogEventArgs e) { arg1 = e; }); string[] stack = new string[] { "step 1", "step 2" }; using (Log.Start(stack[0])) using (Log.Start(stack[1])) { Log.LogWrite += eh; Log.Error(myError, message); Log.LogWrite -= eh; } Assert.IsNotNull(arg1); Assert.AreEqual(1, arg1.Count); Assert.AreEqual(1, arg1.ToArray().Length); EventData data = arg1.ToArray()[0]; Assert.IsNotNull(data); BasicLogTest.AssertMessage(GetType(), stack, data, LogLevels.Error, message, myError.GetType()); Assert.AreEqual(String.Join("::", stack), data.ToString("{LogStack}")); BinaryFormatter ser = new BinaryFormatter(); MemoryStream ms = new MemoryStream(); ser.Serialize(ms, arg1); Assert.Greater((int)ms.Position, 0); ms.Position = 0; object restored = ser.Deserialize(ms); Assert.IsNotNull(restored); Assert.AreEqual(typeof(LogEventArgs), restored.GetType()); LogEventArgs arg2 = restored as LogEventArgs; Assert.IsNotNull(arg2); Assert.AreEqual(1, arg2.Count); Assert.AreEqual(1, arg2.ToArray().Length); data = arg2.ToArray()[0]; Assert.IsNotNull(data); Assert.IsNotNull(data.Exception); Assert.AreNotEqual(myError.GetType(), data.Exception.GetType()); Assert.AreEqual(typeof(Log).Assembly, data.Exception.GetType().Assembly); Assert.AreEqual(myError.Message, data.Exception.Message); Assert.AreEqual(myError.StackTrace, data.Exception.StackTrace); Assert.AreEqual(myError.Source, data.Exception.Source); Assert.AreEqual(myError.ToString(), data.Exception.ToString()); BasicLogTest.AssertMessage(GetType(), stack, data, LogLevels.Error, message, data.Exception.GetType()); }
public void CreateClient() { try { cli = new BluetoothClient(); } catch (PlatformNotSupportedException e) { PlatformNotSupportedException?.Invoke(this, e); } }
static void Main(string[] args) { Console.WriteLine("Hallo Welt!"); LoadBooks().items.Select(x => x.volumeInfo) .Where(x => x.title.StartsWith("b")) .ToList() .ForEach(x => Console.WriteLine(x.title)); //foreach (var item in LoadBooks().items) //{ // Console.WriteLine(item.volumeInfo.title); //} object o = new Volumeinfo() { title = "testbuch!" }; o = new PlatformNotSupportedException(); //casting = doof { if (o is Volumeinfo) { Volumeinfo vii = (Volumeinfo)o; Console.WriteLine(vii.title); } } //boxing = alt aber OK Volumeinfo vi = o as Volumeinfo; PlatformNotSupportedException pe = o as PlatformNotSupportedException; if (vi != null) { Console.WriteLine(vi.title); } //pattern match = neu und cool! if (o is Volumeinfo viiii) { Console.WriteLine(viiii); } string text = "Heute ist: " + DateTime.Now.DayOfWeek + " der " + DateTime.Now.Day; string text2 = string.Format("Heute ist {0} der {1:00}", DateTime.Now.DayOfWeek, DateTime.Now.Day); string text3 = $"Heute ist {DateTime.Now.DayOfWeek} der {DateTime.Now.Day:00}"; Console.WriteLine("Ende"); Console.ReadLine(); }
// TODO: add platform deployment attributes to really check this // this should run on a generic CE device public void UnsupportedPlatformTest() { PlatformNotSupportedException expected = null; try { ConnectionManager target = new ConnectionManager(); } catch (PlatformNotSupportedException ex) { expected = ex; } Assert.IsNotNull(expected); }
// TODO: this should be run on an unsupported platform public void UnsupportedPlatformTest() { PlatformNotSupportedException expected = null; try { Timer2 timer = new Timer2(); } catch (PlatformNotSupportedException ex) { expected = ex; } Assert.IsNotNull(expected); }
// TODO: add platform deployment attributes to really check this // this should run on a PPC03 emulator public void TestUnsupportedConnectionDetailItems() { PlatformNotSupportedException expected = null; ConnectionManager manager = new ConnectionManager(); try { manager.GetConnectionDetailItems(); } catch (PlatformNotSupportedException ex) { expected = ex; } Assert.IsNotNull(expected); }
public void DotnetCoreNotCurrentlySupported() { List <string> options = new List <string>(new string[] { "sharedmemoryname", "pipe", "useperformancemonitor", #if NETCOREAPP1_1 "logging", "useusageadvisor", "interactivesession", "replication" #endif }); if (Platform.IsWindows()) { options.Add("integratedsecurity"); } foreach (string option in options) { PlatformNotSupportedException ex = Assert.ThrowsAny <PlatformNotSupportedException>(() => { MySqlConnectionStringBuilder connString = new MySqlConnectionStringBuilder($"server=localhost;user=root;password=;{option}=dummy"); }); } MySqlConnectionStringBuilder csb = new MySqlConnectionStringBuilder(); Assert.ThrowsAny <PlatformNotSupportedException>(() => csb.SharedMemoryName = "dummy"); if (Platform.IsWindows()) { Assert.ThrowsAny <PlatformNotSupportedException>(() => csb.IntegratedSecurity = true); } Assert.ThrowsAny <PlatformNotSupportedException>(() => csb.PipeName = "dummy"); Assert.ThrowsAny <PlatformNotSupportedException>(() => csb.UsePerformanceMonitor = true); #if NETCOREAPP1_1 Assert.ThrowsAny <PlatformNotSupportedException>(() => csb.Logging = true); Assert.ThrowsAny <PlatformNotSupportedException>(() => csb.UseUsageAdvisor = true); Assert.ThrowsAny <PlatformNotSupportedException>(() => csb.Replication = true); #endif csb.ConnectionProtocol = MySqlConnectionProtocol.Tcp; Assert.ThrowsAny <PlatformNotSupportedException>(() => csb.ConnectionProtocol = MySqlConnectionProtocol.SharedMemory); Assert.ThrowsAny <PlatformNotSupportedException>(() => csb.ConnectionProtocol = MySqlConnectionProtocol.NamedPipe); }
public async Task LogExceptionWithCorrelationInfo_SinksToApplicationInsights_ResultsInTelemetryWithCorrelationInfo() { // Arrange string message = BogusGenerator.Lorem.Sentence(); var exception = new PlatformNotSupportedException(message); string operationId = $"operation-{Guid.NewGuid()}"; string transactionId = $"transaction-{Guid.NewGuid()}"; string operationParentId = $"operation-parent-{Guid.NewGuid()}"; var correlationInfoAccessor = new DefaultCorrelationInfoAccessor(); correlationInfoAccessor.SetCorrelationInfo(new CorrelationInfo(operationId, transactionId, operationParentId)); using (ILoggerFactory loggerFactory = CreateLoggerFactory(config => config.Enrich.WithCorrelationInfo(correlationInfoAccessor))) { ILogger logger = loggerFactory.CreateLogger <ApplicationInsightsSinkTests>(); // Act logger.LogCritical(exception, exception.Message); } // Assert using (ApplicationInsightsDataClient client = CreateApplicationInsightsClient()) { await RetryAssertUntilTelemetryShouldBeAvailableAsync(async() => { EventsResults <EventsExceptionResult> results = await client.Events.GetExceptionEventsAsync(ApplicationId, filter: OnlyLastHourFilter); Assert.NotEmpty(results.Value); AssertX.Any(results.Value, result => { Assert.Equal(exception.Message, result.Exception.OuterMessage); Assert.Equal(operationId, result.Operation.Id); Assert.Equal(operationParentId, result.Operation.ParentId); }); }); } }
private bool CreateUnixSocketStream(string socketName) { #if __MonoCS__ && !WINDOWS Socket socket = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.IP); try { UnixEndPoint endPoint = new UnixEndPoint(socketName); socket.Connect(endPoint); stream = new NetworkStream(socket, true); return(true); } catch (Exception ex) { baseException = ex; return(false); } #else baseException = new PlatformNotSupportedException("This is not a Unix"); return(false); #endif }
public void TestVerbose() { Exception e = new PlatformNotSupportedException(); Log.Verbose(e); AssertMessage(LastMessage, LogLevels.Verbose, e.Message, e.GetType()); Log.Verbose(e, "a-->{0}", UniqueData); AssertMessage(LastMessage, LogLevels.Verbose, String.Format("a-->{0}", UniqueData), e.GetType()); Log.Verbose("b-->{0}", UniqueData); AssertMessage(LastMessage, LogLevels.Verbose, String.Format("b-->{0}", UniqueData), null); Log.Config.Level = LogLevels.None; LastMessage.ToString(); Log.Verbose(e); Assert.AreEqual(0, _lastMessages.Count); Log.Verbose(e, "a-->{0}", UniqueData); Assert.AreEqual(0, _lastMessages.Count); Log.Verbose("b-->{0}", UniqueData); Assert.AreEqual(0, _lastMessages.Count); }
/// <summary> /// Attempts to create a process memory dump at the requested location. Any file already existing at that location will be overwritten /// </summary> public static bool TryDumpProcess(Process process, string dumpPath, out Exception dumpCreationException, bool compress = false) { if (OperatingSystemHelper.IsUnixOS) { dumpCreationException = new PlatformNotSupportedException(); return(false); } string processName = "Exited"; try { processName = process.ProcessName; bool dumpResult = TryDumpProcess(process.Handle, process.Id, dumpPath, out dumpCreationException, compress); if (!dumpResult) { Contract.Assume(dumpCreationException != null, "Exception was null on failure."); } return(dumpResult); } catch (Win32Exception ex) { dumpCreationException = new BuildXLException("Failed to get process handle to create a process dump for: " + processName, ex); return(false); } catch (InvalidOperationException ex) { dumpCreationException = new BuildXLException("Failed to get process handle to create a process dump for: " + processName, ex); return(false); } catch (NotSupportedException ex) { dumpCreationException = new BuildXLException("Failed to get process handle to create a process dump for: " + processName, ex); return(false); } }
private static async Task TestService(IProductService client) { //ExceptionSerializationTest(); Console.WriteLine("start test"); var clientInfo = client as IRpcClient; if (clientInfo != null) { Console.WriteLine("formatter is " + clientInfo.Formatter?.GetType()); } var testBatchName = "GetAll"; try { var ps1 = client.GetAll(); Assert.AreNotEqual(ps1, null); Assert.Greater(ps1.Length, 0); Assert.AreEqual(ps1.Length, 10); ps1 = await client.GetAllAsync(); Assert.AreNotEqual(ps1, null); Assert.Greater(ps1.Length, 0); Assert.AreEqual(ps1.Length, 10); Console.WriteLine(testBatchName + " Test Success"); } catch (Exception ex) { Console.BackgroundColor = ConsoleColor.Red; Console.WriteLine(testBatchName + " Test Failed. " + ex); Console.ResetColor(); } testBatchName = "Add, GetById"; try { var id1 = client.Add(new Product { Id = 1001, Name = "1001-name", Tags = new List <string> { "Tag1", "Tag2" } }); Assert.AreEqual(id1, 1001); id1 = await client.AddAsync(new Product { Id = 1002, Name = "1002-name", Tags = new List <string> { "Tag1", "Tag2" } }); Assert.AreEqual(id1, 1002); var product1 = client.GetById(1001); Assert.AreEqual(product1.Id, 1001); Assert.AreEqual(product1.Name, "1001-name"); Assert.AreEqual(product1.Tags.Count, 2); Assert.AreEqual(product1.Tags[0], "Tag1"); Assert.AreEqual(product1.Tags[1], "Tag2"); var product2 = await client.GetByIdAsync(1002); Assert.AreEqual(product2.Id, 1002); Assert.AreEqual(product2.Name, "1002-name"); Assert.AreEqual(product2.Tags.Count, 2); Assert.AreEqual(product2.Tags[0], "Tag1"); Assert.AreEqual(product2.Tags[1], "Tag2"); var id2 = client.Add(null); Console.WriteLine(testBatchName + " Test Success"); } catch (Exception ex) { Console.BackgroundColor = ConsoleColor.Red; Console.WriteLine(testBatchName + " Test Failed. " + ex); Console.ResetColor(); } testBatchName = "SetNumber, GetNumber"; try { client.SetNumber(98); var num = client.GetNumber(); Assert.AreEqual(num, 98); await client.SetNumberAsync(97); var num2 = await client.GetNumberAsync(); Assert.AreEqual(num2, 97); Console.WriteLine(testBatchName + " Test Success"); } catch (Exception ex) { Console.BackgroundColor = ConsoleColor.Red; Console.WriteLine(testBatchName + " Test Failed. " + ex); Console.ResetColor(); } testBatchName = "GetPage"; try { var ps1 = client.GetPage(1, 5); Assert.AreNotEqual(ps1, null); Assert.AreEqual(ps1.Length, 5); var ps2 = await client.GetPageAsync(1, 5); Assert.AreNotEqual(ps2, null); Assert.AreEqual(ps2.Length, 5); Console.WriteLine(testBatchName + " Test Success"); } catch (Exception ex) { Console.BackgroundColor = ConsoleColor.Red; Console.WriteLine(testBatchName + " Test Failed. " + ex); Console.ResetColor(); } testBatchName = "ThrowException"; try { client.ExceptionTest(); } catch (Exception ex) { Console.WriteLine(ex); } testBatchName = "ExceptionTestAsync"; try { client.ExceptionTestAsync().Wait(); } catch (AggregateException ex) { Console.WriteLine(ex.InnerException); } catch (Exception ex) { Console.WriteLine(ex); } var exObj = new PlatformNotSupportedException("win31"); testBatchName = "ThrowException"; try { client.ThrowException(exObj); } catch (Exception ex) { try { if (ex.GetType() != exObj.GetType()) { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine($"Warning: Exception Type not equal: {ex.GetType()} <-> {exObj.GetType()}"); Console.ResetColor(); } else { Console.WriteLine($"Exception Type are equal: {ex.GetType()} <-> {exObj.GetType()}"); } Assert.AreEqual(ex.Message, exObj.Message); Console.WriteLine(testBatchName + " Test Success"); } catch (Exception ex2) { Console.BackgroundColor = ConsoleColor.Red; Console.WriteLine(testBatchName + " Test Failed. " + ex2); Console.ResetColor(); } } Console.WriteLine("Test Finished."); }
/// <summary> /// Generate the type(s) /// </summary> protected override void ProcessRecord() { List <string> pathsToProcess = new(); ProviderInfo provider = null; if (string.Equals(this.ParameterSetName, "ByLiteralPath", StringComparison.OrdinalIgnoreCase)) { foreach (string path in _paths) { string newPath = Context.SessionState.Path.GetUnresolvedProviderPathFromPSPath(path); if (IsValidFileForUnblocking(newPath)) { pathsToProcess.Add(newPath); } } } else { // Resolve paths foreach (string path in _paths) { try { Collection <string> newPaths = Context.SessionState.Path.GetResolvedProviderPathFromPSPath(path, out provider); foreach (string currentFilepath in newPaths) { if (IsValidFileForUnblocking(currentFilepath)) { pathsToProcess.Add(currentFilepath); } } } catch (ItemNotFoundException e) { if (!WildcardPattern.ContainsWildcardCharacters(path)) { ErrorRecord errorRecord = new(e, "FileNotFound", ErrorCategory.ObjectNotFound, path); WriteError(errorRecord); } } } } #if !UNIX // Unblock files foreach (string path in pathsToProcess) { if (ShouldProcess(path)) { try { AlternateDataStreamUtilities.DeleteFileStream(path, "Zone.Identifier"); } catch (Exception e) { WriteError(new ErrorRecord(exception: e, errorId: "RemoveItemUnableToAccessFile", ErrorCategory.ResourceUnavailable, targetObject: path)); } } } #else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { string errorMessage = UnblockFileStrings.LinuxNotSupported; Exception e = new PlatformNotSupportedException(errorMessage); ThrowTerminatingError(new ErrorRecord(exception: e, errorId: "LinuxNotSupported", ErrorCategory.NotImplemented, targetObject: null)); return; } foreach (string path in pathsToProcess) { if (IsBlocked(path)) { UInt32 result = RemoveXattr(path, MacBlockAttribute, RemovexattrFollowSymLink); if (result != 0) { string errorMessage = string.Format(CultureInfo.CurrentUICulture, UnblockFileStrings.UnblockError, path); Exception e = new InvalidOperationException(errorMessage); WriteError(new ErrorRecord(exception: e, errorId: "UnblockError", ErrorCategory.InvalidResult, targetObject: path)); } } } #endif }
internal static PlatformNotSupportedException DbTypeNotSupported(string dbType) { PlatformNotSupportedException e = new PlatformNotSupportedException(System.SRHelper.GetString(SR.SQL_DbTypeNotSupportedOnThisPlatform, dbType)); return(e); }
private static Exception CreateLockNotSupportedException(PlatformNotSupportedException innerEx) { throw new InvalidOperationException("Your platform does not support FileStream.Lock. Please set mode=Exclusive in your connnection string to avoid this error.", innerEx); }
public bool PosTest4() { bool retVal = true; const string c_TEST_ID = "P004"; string c_TEST_DESC = "PosTest4: message is a string containing special character and inner exception is a null reference"; string errorDesc; string message = "Not supported exception occurs here"; Exception innerException = null; TestLibrary.TestFramework.BeginScenario(c_TEST_DESC); try { PlatformNotSupportedException e = new PlatformNotSupportedException(message, innerException); if (null == e || e.Message != message || e.InnerException != innerException) { errorDesc = "Failed to initialize an instance of type PlatformNotSupportedException."; errorDesc += "\nInput message is \"" + message + "\""; errorDesc += "\nInner exception is a null reference."; TestLibrary.TestFramework.LogError("007" + " TestId-" + c_TEST_ID, errorDesc); retVal = false; } } catch (Exception e) { errorDesc = "Unexpected exception: " + e; errorDesc += "\nInput message is \"" + message + "\""; errorDesc += "\nInner exception is a null reference."; TestLibrary.TestFramework.LogError("008" + " TestId-" + c_TEST_ID, errorDesc); retVal = false; } return retVal; }
public bool PosTest3() { bool retVal = true; const string c_TEST_ID = "P003"; string c_TEST_DESC = "PosTest3: initialize an instance of type PlatformNotSupportedException using a null reference"; string errorDesc; string message = null; Exception innerException = new Exception(); TestLibrary.TestFramework.BeginScenario(c_TEST_DESC); try { PlatformNotSupportedException e = new PlatformNotSupportedException(message, innerException); if (null == e) { errorDesc = "Failed to initialize an instance of type PlatformNotSupportedException."; errorDesc += "\nInput message is a null reference."; errorDesc += "\nInner exception is " + innerException; TestLibrary.TestFramework.LogError("005" + " TestId-" + c_TEST_ID, errorDesc); retVal = false; } } catch (Exception e) { errorDesc = "Unexpected exception: " + e; errorDesc += "\nInput message is a null reference."; errorDesc += "\nInner exception is " + innerException; TestLibrary.TestFramework.LogError("006" + " TestId-" + c_TEST_ID, errorDesc); retVal = false; } return retVal; }
static internal PlatformNotSupportedException DbTypeNotSupported(string dbType) { PlatformNotSupportedException e = new PlatformNotSupportedException(Res.GetString(Res.SQL_DbTypeNotSupportedOnThisPlatform, dbType)); return e; }