public void GetCar_EntryIsAbsent_Exception() { var fakeIndex = 4; providerMock.Setup(c => c.Load()).Returns(_fakeCarslist); Assert.Throws <Exception>(() => carsRepositoryController.GetCar(fakeIndex)); }
public void QueryUpdate(string caseName) { InitCase(caseName); var caseInfo = GetCaseInfo <CaseInfo>(caseName); if (caseInfo.ItemGroup.Any(item => item.Type == StoreType.DBStore)) { _StoreCenter.Update(item => item.ID >= 3 && item.ID <= 7, item => new Student { Name = "李四" }); var group = _StoreCenter.GetAll().Where(item => item.Name == "李四").ToList(); Assert.Equal(5, group.Count); Assert.Equal(3, group.Min(item => item.ID)); Assert.Equal(7, group.Max(item => item.ID)); LogHelper.WriteLine(group.Count().ToString()); } else { Assert.Throws <NotSupportedException>( () => _StoreCenter.Update(item => item.ID >= 3 && item.ID <= 7, item => new Student { Name = "李四" })); } }
public void ExchangeService_CanInitiate() { //import for service discovery to be able to initiate without constructor _ = new ExchangeService(); Assert.Throws <ArgumentException>(() => { _ = GetExternalService(new ExternalServiceData() { Type = "invalid" }); }); var data = new ExchangeExternalServiceData() { PublicKey = "test", PairedDate = DateTime.Now }; var externalServiceData = new ExternalServiceData() { Type = ExchangeService.ExchangeServiceType, Name = "something" }; externalServiceData.Set(data); var exchangeService = new ExchangeService(externalServiceData); Assert.Equal(exchangeService.GetData().PublicKey, data.PublicKey); Assert.Equal(exchangeService.GetData().PairedDate, data.PairedDate); }
public void Create_Employee_Fails_With_Bad_Inputs(string guidAsString, string firstName, string lastName, string occupation) { EmployeeProcessor employeeProcessor = new EmployeeProcessor(null); Assert.Throws <ArgumentException>(() => employeeProcessor.CreateEmployee(Guid.Parse(guidAsString), firstName, lastName, occupation)); }
public void RandInt_ThrowsIfEqualArguments() { Assert.Throws <ArgumentException>(() => { Rand.Int(9, 9); }); }
public void PriorityQueuePeekEmptyQueueThrowsException() { var q = new PriorityQueue <int>(); Assert.Equal(0, q.Count); Assert.Throws <InvalidOperationException>(() => q.Peek()); }
public void CountRangeTest() { int[] a = new int[] { 1, 2, 3, 5, 7, 8, 10 }; SAssert.Count(a, 2, 4, x => x > 3); XAssert.Throws <ArgumentException>(() => SAssert.Count(a, 3, 5, x => x > 7)); XAssert.Throws <ArgumentException>(() => SAssert.Count(a, 3, 5, x => x > 1)); }
public void AddressRepositoryConstructorTest() { Assert.Throws <ArgumentNullException>(() => { IAddressRepository newAddressRepository = new AddressRepository(null); }); }
public void Verify_Camera_Exception_Cases() { var cameraStatus = new NestCameraStatus(); Assert.Throws <NestCameraOfflineException>(() => cameraStatus.ThrowExceptionIfCameraIsntOnlineAndStreaming(new NestCameraJson())); Assert.Throws <NestCameraOfflineException>(() => cameraStatus.ThrowExceptionIfCameraIsntOnlineAndStreaming(new NestCameraJson { IsOnline = true })); Assert.Throws <NestCameraOfflineException>(() => cameraStatus.ThrowExceptionIfCameraIsntOnlineAndStreaming(new NestCameraJson { IsStreaming = true // Probably isn't posible to be streaming and offline...This is a test case I can remove when I gain experience and comfort with this problem area. For now however, I'm validating the API's themselves and making no assumptions. })); var fullyOnlineCamera = new NestCameraJson { IsOnline = true, IsStreaming = true }; cameraStatus.ThrowExceptionIfCameraIsntOnlineAndStreaming(fullyOnlineCamera); Assert.False(cameraStatus.IsOffline(fullyOnlineCamera)); }
public static int Main(string [] args) { try { string assemblyLocation = typeof(InvalidHostingTest).Assembly.Location; string testBasePath = Path.GetDirectoryName(assemblyLocation); string componentDirectory = Path.Combine(testBasePath, $"InvalidHostingComponent_{Guid.NewGuid().ToString().Substring(0, 8)}"); Directory.CreateDirectory(componentDirectory); string componentAssemblyPath = Path.Combine(componentDirectory, "InvalidHostingComponent.dll"); File.WriteAllText(componentAssemblyPath, "Mock assembly"); object innerException = Assert.Throws <InvalidOperationException>(() => { AssemblyDependencyResolver resolver = new AssemblyDependencyResolver( Path.Combine(testBasePath, componentAssemblyPath)); }).InnerException; Assert.IsType <DllNotFoundException>(innerException); } catch (Exception ex) { Console.WriteLine(ex); return(101); } return(100); }
public void FromTypeTest() { EntityInfo entity = new EntityInfo(); Type type = null; Assert.Throws <ArgumentNullException>(() => entity.FromType(type)); entity = new EntityInfo(); type = typeof(TestEntityA); entity.FromType(type); entity.Name.ShouldBe("测试实体A"); entity.TypeName.ShouldBe(typeof(TestEntityA).FullName + ",OSharp.Tests"); entity.Properties.Length.ShouldBe(6); entity.Properties.ShouldContain(m => m.Name == "Id"); entity.Properties.ShouldContain(m => m.Name == "Name"); entity.Properties.ShouldContain(m => m.Name == "IsLocked"); entity.Properties.ShouldContain(m => m.Name == "CreatedTime"); entity.Properties.ShouldNotContain(m => m.Name == "DeletedTime"); entity.Properties.First(m => m.Name == "Id").TypeName.ShouldBe(typeof(int).FullName); entity.Properties.First(m => m.Name == "Enum").ValueRange.Count.ShouldBe(4); entity.Properties.First(m => m.Name == "OtherId").IsUserFlag.ShouldBeTrue(); }
public void TestComponentLoadFailureWithPreviousErrorWriter() { IntPtr previousWriter = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate( (HostPolicyMock.ErrorWriterDelegate)((string _) => { Assert.True(false, "Should never get here"); })); using (HostPolicyMock.MockValues_corehost_set_error_writer errorWriterMock = HostPolicyMock.Mock_corehost_set_error_writer(previousWriter)) { using (HostPolicyMock.MockValues_corehost_resolve_component_dependencies resolverMock = HostPolicyMock.Mock_corehost_resolve_component_dependencies( 134, "", "", "")) { Assert.Throws <InvalidOperationException>(() => { AssemblyDependencyResolver resolver = new AssemblyDependencyResolver( Path.Combine(TestBasePath, _componentAssemblyPath)); }); // After everything is done, the error writer should be reset to the original value. Assert.Equal(previousWriter, errorWriterMock.LastSetErrorWriterPtr); } } }
public void GetPortionTest() { var input = new string[] { "There once was a jolly young tester", "Who couldn't leave software to fester -", "He'd prod and he'd poke", "Until something bad broke,", "And then he'd find someone to pester." }; var text = new Text(input); // A single-line range (to test the special case). Assert.Equal("jolly" + NL, text.GetPortion(0, 17, 0, 22)); // A two-line range. Assert.Equal("prod and he'd poke" + NL + "Until" + NL, text.GetPortion(2, 5, 3, 5)); // A three-line range (to test that the middle line is included in full). Assert.Equal("poke" + NL + "Until something bad broke," + NL + "And then" + NL, text.GetPortion(2, 19, 4, 8)); // An invalid but recoverable range (to test that a best effort is made rather than crashing). Assert.Equal(NL + "Who couldn't leave software to fester -" + NL, text.GetPortion(0, int.MaxValue, 1, int.MaxValue)); // Some quite definitely dodgy ranges (to test that exceptions are thrown). Assert.Throws <Exception>(() => text.GetPortion(-1, 0, 0, 0)); Assert.Throws <Exception>(() => text.GetPortion(0, -1, 0, 0)); Assert.Throws <Exception>(() => text.GetPortion(0, 0, -1, 0)); Assert.Throws <Exception>(() => text.GetPortion(0, 0, 0, -1)); Assert.Throws <Exception>(() => text.GetPortion(3, 5, 2, 5)); Assert.Throws <Exception>(() => text.GetPortion(2, 5, int.MaxValue, 5)); }
public void Assertions() { var condition = false; var text = "something"; var obj = new Auto(); var tokens = new List <string> { "public", "void", "return" }; var zero = 8 - 8; var someEnumerable = new List <string>(); Assert.False(condition); Assert.Equal("something", text); Assert.NotEqual("something else", text); Assert.Contains("tech", "technology"); // also DoesNotContain Assert.Matches(".*thing$", "something"); Assert.Throws <DivideByZeroException>(() => 4 / zero); Assert.Empty(someEnumerable); // also NotEmpty Assert.IsType <Auto>(obj); Assert.Collection(new List <int> { 2, 4 }, n => Assert.Equal(2, n), n => Assert.Equal(4, n) ); Assert.All(new List <string> { "a", "ab", "abc" }, s => s.StartsWith("a")); }
public void RejectMessagePattern() { Action fnFailAORException = () => OAssert.Throws <MyArgumentException>(ThrowException, NotMatchingPattern); Action fnFailArgException = () => OAssert.Throws <ArgumentException>(ThrowException, NotMatchingPattern); XAssert.Throws <ArgumentException>(fnFailAORException); XAssert.Throws <ArgumentException>(fnFailArgException); string expectedMessage = string.Format("Exception message '{0}' did not match expected pattern '{1}'", ExceptionMessage, NotMatchingPattern); try { fnFailAORException(); throw new Exception("Action did not throw an exception!"); } catch (Exception ex) { XAssert.Equal(expectedMessage, ex.Message); } try { fnFailArgException(); throw new Exception("Action did not throw an exception!"); } catch (Exception ex) { XAssert.Equal(expectedMessage, ex.Message); } }
public void LengthTest() { string actual = "afds"; SAssert.Length(actual, 4); XAssert.Throws <ArgumentException>(() => SAssert.Length(actual, 6)); XAssert.Throws <ArgumentException>(() => SAssert.Length(actual, 2)); }
public void NotNullTest() { string actual = "afds"; SAssert.NotNull(actual); XAssert.Throws <ArgumentException>(() => SAssert.NotNull(null)); }
public void ParameterFill_NoUniqueBeanDefinition_ExceptionThrown() { var ex = Assert.Throws <BeanCreationException>(() => Sp.GetRequiredService <CtorService>()); Assert.Equal($"Parameter 0 of Constructor in {typeof(CtorService).FullName} required a single bean, but 2 were found:\r\n" + $"- {typeof(B1).Name}: defined in namespace [{typeof(B1).Namespace}]\r\n" + $"- {typeof(B2).Name}: defined in namespace [{typeof(B2).Namespace}]", ex.Message); }
public void ThrowError_Throw_ApplicationException2() { const string expected_exception_message = "Hello World2!"; var exception = Assert.Throws <ApplicationException>(() => _controller.ThrowError(expected_exception_message)); Assert.Equal(expected_exception_message, exception.Message); }
public void RertryThrowException() { Assert.Throws <StackOverflowException>(() => { ExceptionHandler.Retry <StackOverflowException>(3, () => { throw new StackOverflowException(); }); }); }
public static void Throws <T>(Action action) where T : Exception { #if XUNIT XUnitAssert.Throws <T>(action); #else NUnitAssert.Throws <T>(action.Invoke); #endif }
public void DictionaryTest() { Dictionary <string, string> a = new Dictionary <string, string>(); a.Add("foo", "bar"); SAssert.ContainsKey(a, "foo"); XAssert.Throws <ArgumentException>(() => SAssert.ContainsKey(a, "loo")); }
public void DisposeTest() { var p = new PipeLine(CancellationToken.None); var x = p.Init(Enumerable.Range(0, 10), 10, 10, i => i); p.Dispose(); Assert.Throws <ObjectDisposedException>(() => x.Out.ToArray()); }
public void RangeFailsIfYearsAreInvalid() { Assert.Throws <ArgumentOutOfRangeException>(() => TimePeriodUtil.Range(new TimePeriodQuery(12345, CalendarYear, 2019, CalendarYear))); Assert.Throws <ArgumentOutOfRangeException>(() => TimePeriodUtil.Range(new TimePeriodQuery(2019, CalendarYear, 12345, CalendarYear))); }
public void DefaultStructTest() { Foo f = new Foo(32); Foo f2 = default(Foo); SAssert.NotDefault(f); XAssert.Throws <ArgumentException>(() => SAssert.NotDefault(f2)); }
public void Throws_exception_on_invalid() { //Arrange const string orgnr = "1234567"; //Act Assert.Throws <KonfigurasjonsException>(() => new Organisasjonsnummer(orgnr)); }
public void NotEmptyTest() { string actual = "afds"; SAssert.NotEmpty(actual); SAssert.NotEmpty(null); XAssert.Throws <ArgumentException>(() => SAssert.NotEmpty(string.Empty)); }
public void NonEqualityTest() { string actual = "afds"; string compared = "foo"; string compared2 = "afds"; SAssert.NotEquals(actual, compared); XAssert.Throws <ArgumentException>(() => SAssert.NotEquals(actual, compared2)); }
public void WildcardTest() { string actual = "foo123.txt"; string pattern = "foo*.txt"; string pattern2 = "bar*.txt"; SAssert.IsLike(actual, pattern); XAssert.Throws <ArgumentException>(() => SAssert.IsLike(actual, pattern2)); }
public void CancelTest() { using (var cts = new CancellationTokenSource()) using (var p = new PipeLine(cts.Token)) { p.Init(Enumerable.Range(0, 10), 1, 1, i => i); cts.Cancel(); Assert.Throws <OperationCanceledException>(() => p.Start(null)); } }