public void Graph_AddDual_ValidatesBeforeAdding_ForwardOrder() { var graph = new Graph <int, int>(x => x); Action validation = () => { Assert.AreEqual(2, graph.GetNodes().Count); Assert.AreEqual(1, graph.GetOutlinks(0).Count); Assert.AreEqual(0, graph.GetInLinks(0).Count); Assert.AreEqual(0, graph.GetOutlinks(1).Count); Assert.AreEqual(1, graph.GetInLinks(1).Count); }; // Create one directed link that'll conflict with the bidi links in the next steps. graph.AddLink(0, 1, 1); validation(); // Verify that we get an exception during add Assert2.Throws <InvalidOperationException>(() => graph.AddDual(0, 1, 1)); // Verify that the graph is completely unchanged. validation(); }
public void Change_ViaTimeSpan_DoesNotAllow_Negative_Timeout() { SimpleTimerHarness harness = new SimpleTimerHarness(); VersionedTimer <int> timer = new VersionedTimer <int>(123, harness.Callback); using ( timer ) { // Smallest negative possible. Assert2.Throws <ArgumentException>(() => { timer.Change(TimeSpan.FromTicks(-1), Timeout.InfiniteTimeSpan, 0); }); // Edge case near -1 ms (a special value), low side. Assert2.Throws <ArgumentException>(() => { timer.Change(nearOneMsPlus, Timeout.InfiniteTimeSpan, 0); }); // Edge case near -1 ms (a special value), high side. Assert2.Throws <ArgumentException>(() => { timer.Change(nearOneMsMinus, Timeout.InfiniteTimeSpan, 0); }); // More negative. Assert2.Throws <ArgumentException>(() => { timer.Change(MSecs(-2), Timeout.InfiniteTimeSpan, 0); }); } }
public void DisposeNotify_Requires_WaitHandle() { SimpleTimerHarness harness = new SimpleTimerHarness(); VersionedTimer <int> timer = new VersionedTimer <int>(123, harness.Callback); Assert2.Throws <ArgumentNullException>(() => timer.Dispose(null)); }
public void Graph_GetLink_Rejects_LoopbackDoesntExist() { var graph = new Graph <int, int>(x => x); graph.AddLink(0, 1, 10); Assert2.Throws <InvalidOperationException>(() => graph.GetLinkData(0, 0)); }
public void Api_version_mismatch_test() { var mock = new Mock <StacManClient>(null, "2.0"); var client = mock.Object; Assert2.Throws <InvalidOperationException>(() => client.Users.GetTopAnswerTags("stackoverflow.com", new int[] { 1, 3 }, pagesize: 3)); }
public void CreateInstance_WithAbstractTypeAndPublicConstructor_ThrowsCorrectException() { // Act & Assert var ex = Assert2.Throws <InvalidOperationException>(() => ActivatorUtilities.CreateInstance(default(IServiceProvider), typeof(AbstractFoo))); //var msg = "A suitable constructor for type 'Microsoft.Extensions.DependencyInjection.Specification.DependencyInjectionSpecificationTests+AbstractFoo' could not be located. Ensure the type is concrete and services are registered for all parameters of a public constructor."; Assert2.NotNull(ex.Message); }
public void CreateInstance_CapturesInnerException_OfTargetInvocationException() { // Act & Assert var ex = Assert2.Throws <InvalidOperationException>(() => ActivatorUtilities.CreateInstance(default(IServiceProvider), typeof(Bar))); var msg = "some error"; Assert2.Equal(msg, ex.Message); }
public void Graph_AddNodes_Rejects_DuplicateNodes() { var graph = new Graph <int, int>(x => x); graph.AddNode(0); Assert2.Throws <InvalidOperationException>(() => graph.AddNode(0)); }
public void Graph_AddLink_Rejects_DuplicateLoopback() { var graph = new Graph <int, int>(x => x); graph.AddLink(0, 0, 10); Assert2.Throws <InvalidOperationException>(() => graph.AddLink(0, 0, 20)); }
public void Graph_GetNeighbors_Rejects_UnknownNode() { var graph = new Graph <int, int>(x => x); graph.AddLink(1, 2, 10); Assert2.Throws <InvalidOperationException>(() => graph.GetNeighbors(0)); }
public void Graph_Remove_Rejects_AlreadyRemoved() { var graph = new Graph <int, int>(x => x); graph.AddNode(0); graph.Remove(0); Assert2.Throws <InvalidOperationException>(() => graph.Remove(0)); }
public void Graph_GetShortestPath_Rejects_UnknownNodes() { var graph = new Graph <int, int>(x => x); List <int> path; int cost; Assert2.Throws <InvalidOperationException>(() => graph.GetShortestPath(0, 1, out path, out cost)); }
public void GetDefaultValueForParameters_ReturnsSuppliedValues() { var suppliedDefaultValues = new object[] { 123, "test value" }; var executor = GetExecutorForMethod(nameof(TestObject.MethodWithMultipleParameters), suppliedDefaultValues); Assert2.Equal(suppliedDefaultValues[0], executor.GetDefaultValueForParameter(0)); Assert2.Equal(suppliedDefaultValues[1], executor.GetDefaultValueForParameter(1)); Assert2.Throws <ArgumentOutOfRangeException>(() => executor.GetDefaultValueForParameter(2)); }
public void LastDayOfWeekInMonthFilterInvalidState() { var values = Enum.GetValues(typeof(CrontabFieldKind)).Cast <CrontabFieldKind>().Where(x => x != CrontabFieldKind.DayOfWeek); foreach (var type in values) { Assert2.Throws <CrontabException>(() => new LastDayOfWeekInMonthFilter(0, type), "Ensure LastDayOfWeekInMonthFilter can't be instantiated with <{0}>", Enum.GetName(typeof(CrontabFieldKind), type)); } }
public void Graph_SetLink_Rejects_UnknownNodes_Filled() { var graph = new Graph <int, int>(x => x); graph.AddDual(0, 1, 10); graph.AddDual(0, 2, 10); graph.AddLink(2, 1, 10); Assert2.Throws <InvalidOperationException>(() => graph.SetLink(1, 2, 10)); }
public void Graph_RemoveLink_Rejects_UnknownNode() { var graph = new Graph <int, int>(x => x); graph.AddLink(1, 2, 10); Assert2.Throws <InvalidOperationException>(() => graph.RemoveLink(0, 1)); Assert2.Throws <InvalidOperationException>(() => graph.RemoveLink(1, 0)); Assert2.Throws <InvalidOperationException>(() => graph.RemoveLink(0, 3)); }
public void Graph_Remove_Rejects_UnknownNode_Populated() { var graph = new Graph <int, int>(x => x); for (int i = 1; i <= 10; i++) { graph.AddNode(i); } Assert2.Throws <InvalidOperationException>(() => graph.Remove(0)); }
public void ExecuteValueMethodWithReturnTypeThrowsException() { var executor = GetExecutorForMethod(nameof(TestObject.ValueMethodWithReturnTypeThrowsException)); var parameter = new TestObject(); Assert2.False(executor.IsMethodAsync); Assert2.Throws <NotImplementedException>( () => executor.Execute( _targetObject, new object[] { parameter })); }
public void Graph_TryGetLink_Rejects_UnknownNode() { var graph = new Graph <int, int>(x => x); int data; graph.AddLink(0, 1, 10); Assert2.Throws <InvalidOperationException>(() => graph.TryGetLinkData(0, 2, out data)); Assert2.Throws <InvalidOperationException>(() => graph.TryGetLinkData(2, 0, out data)); Assert2.Throws <InvalidOperationException>(() => graph.TryGetLinkData(2, 3, out data)); }
public void Graph_AddLink_Rejects_DuplicateLinks_SameCost() { var graph = new Graph <int, int>(x => x); graph.AddLink(0, 1, 1); Assert2.Throws <InvalidOperationException>(() => graph.AddLink(0, 1, 1)); Assert2.Throws <InvalidOperationException>(() => graph.AddLink(0, 1, 2)); Assert.AreEqual(1, graph.GetLinkData(0, 1)); }
public void RangeFilterInvalidState() { Assert2.Throws <CrontabException>(() => new RangeFilter(-1, 1, null, CrontabFieldKind.Day)); Assert2.Throws <CrontabException>(() => new RangeFilter(1, -1, null, CrontabFieldKind.Day)); Assert2.Throws <CrontabException>(() => new RangeFilter(1, 1, -1, CrontabFieldKind.Day)); Assert2.Throws <CrontabException>(() => new RangeFilter(1, 1, 0, CrontabFieldKind.Day)); Assert2.Throws <CrontabException>(() => new RangeFilter(32, 1, null, CrontabFieldKind.Day)); Assert2.Throws <CrontabException>(() => new RangeFilter(1, 32, null, CrontabFieldKind.Day)); Assert2.Throws <CrontabException>(() => new RangeFilter(1, 1, 32, CrontabFieldKind.Day)); }
public void NearestWeekdayFilterInvalidState() { var values = Enum.GetValues(typeof(CrontabFieldKind)).Cast <CrontabFieldKind>().Where(x => x != CrontabFieldKind.Day); foreach (var type in values) { Assert2.Throws <CrontabException>(() => new NearestWeekdayFilter(1, type), "Ensure NearestWeekdayFilter can't be instantiated with <{0}>", Enum.GetName(typeof(CrontabFieldKind), type)); } Assert2.Throws <CrontabException>(() => new NearestWeekdayFilter(-1, CrontabFieldKind.Day)); Assert2.Throws <CrontabException>(() => new NearestWeekdayFilter(32, CrontabFieldKind.Day)); }
public void MakeFastPropertyGetter_ValueType_ForNullObject_Throws() { // Arrange var property = PropertyHelper .GetPropertyAccessors(typeof(MyProperties)) .Single(p => p.Name == nameof(MyProperties.StringProp)); var accessor = PropertyHelper.MakeFastPropertyGetter(property.Property); // Act & Assert Assert2.Throws <NullReferenceException>(() => accessor(null)); }
//[Theory] //[MemberData(nameof(TypesWithNonPublicConstructorData))] public void TypeActivatorRequiresPublicConstructor_Theory(CreateInstanceFunc createFunc, Type type) { // Arrange var expectedMessage = $"A suitable constructor for type '{type}' could not be located. " + "Ensure the type is concrete and services are registered for all parameters of a public constructor."; // Act and Assert var ex = Assert2.Throws <InvalidOperationException>(() => createFunc(provider: null, type: type, args: new object[0])); Assert2.Equal(expectedMessage, ex.Message); }
public void SpecificDayOfWeekInMonthFilterInvalidState() { var values = Enum.GetValues(typeof(CrontabFieldKind)).Cast <CrontabFieldKind>().Where(x => x != CrontabFieldKind.DayOfWeek); foreach (var type in values) { Assert2.Throws <CrontabException>(() => new SpecificDayOfWeekInMonthFilter(0, 1, type), "Ensure SpecificDayOfWeekInMonthFilter can't be instantiated with <{0}>", Enum.GetName(typeof(CrontabFieldKind), type)); } Assert2.Throws <CrontabException>(() => new SpecificDayOfWeekInMonthFilter(0, -1, CrontabFieldKind.DayOfWeek), "Make sure instance of -1 throws exception"); Assert2.Throws <CrontabException>(() => new SpecificDayOfWeekInMonthFilter(0, 0, CrontabFieldKind.DayOfWeek), "Make sure instance of 0 throws exception"); Assert2.Throws <CrontabException>(() => new SpecificDayOfWeekInMonthFilter(0, 6, CrontabFieldKind.DayOfWeek), "Makes sure instance of 6 throws exception"); }
public void SingleFirstLastError() { var artists = Database.Query <ArtistEntity>(); Assert2.Throws <InvalidOperationException>("Y", () => artists.Where(a => a.Dead && !a.Dead).SingleEx(() => "Y")); Assert2.Throws <InvalidOperationException>("Y", () => artists.Where(a => a.Sex == Sex.Male).SingleEx(() => "X", () => "Y")); Assert2.Throws <InvalidOperationException>("Y", () => artists.Where(a => a.Sex == Sex.Male).SingleOrDefaultEx(() => "Y")); Assert2.Throws <InvalidOperationException>("X", () => artists.Where(a => a.Dead && !a.Dead).FirstEx(() => "X")); Assert2.Throws <InvalidOperationException>(typeof(ArtistEntity).Name, () => artists.SingleEx(a => a.Dead && !a.Dead)); Assert2.Throws <InvalidOperationException>(typeof(ArtistEntity).Name, () => artists.SingleEx(a => a.Sex == Sex.Male)); Assert2.Throws <InvalidOperationException>(typeof(ArtistEntity).Name, () => artists.SingleOrDefaultEx(a => a.Sex == Sex.Male)); Assert2.Throws <InvalidOperationException>(typeof(ArtistEntity).Name, () => artists.FirstEx(a => a.Dead && !a.Dead)); Assert2.Throws <InvalidOperationException>("X", () => artists.Where(a => a.Dead && !a.Dead).SingleOrManyEx(() => "X")); }
public void Graph_GetLink_Rejects_WrongNodes() { var graph = new Graph <int, int>(x => x); graph.AddLink(0, 1, 42); // Wrong end node. Assert2.Throws <InvalidOperationException>(() => graph.GetLinkData(0, 2)); // Wrong start node. Assert2.Throws <InvalidOperationException>(() => graph.GetLinkData(2, 1)); // Wrong both nodes. Assert2.Throws <InvalidOperationException>(() => graph.GetLinkData(1, 2)); // Right nodes, reversed. Assert2.Throws <InvalidOperationException>(() => graph.GetLinkData(1, 0)); }
public void BlankDayOfMonthOrWeekFilterInvalidState() { var values = new CrontabFieldKind[] { CrontabFieldKind.Hour, CrontabFieldKind.Minute, CrontabFieldKind.Month, CrontabFieldKind.Second, CrontabFieldKind.Year }; foreach (var val in values) { Assert2.Throws <CrontabException>(() => new BlankDayOfMonthOrWeekFilter(val), "Ensure BlankDayOfMonthOrWeekFilter can't be instantiated with <{0}>", Enum.GetName(typeof(CrontabFieldKind), val)); } Assert.IsTrue(new BlankDayOfMonthOrWeekFilter(CrontabFieldKind.Day).IsMatch(DateTime.Now)); Assert.IsTrue(new BlankDayOfMonthOrWeekFilter(CrontabFieldKind.DayOfWeek).IsMatch(DateTime.UtcNow)); }
public void Throws() { void Test(object obj) { if (obj == null) { throw new ArgumentNullException(nameof(obj)); } } Console.WriteLine(Assert.ThrowsException <AssertFailedException>(() => Assert.ThrowsException <ArgumentNullException>(() => Test(0))).Message); Console.WriteLine(Assert.ThrowsException <AssertFailedException>(() => Assert.ThrowsException <ArgumentOutOfRangeException>(() => Test(null))).Message); Console.WriteLine(Assert.ThrowsException <AssertFailedException>(() => Assert.ThrowsException <ArgumentException>(() => Test(null))).Message); Console.WriteLine(Assert.ThrowsException <ArgumentNullException>(() => Test(null)).Message); Console.WriteLine(); Console.WriteLine(Assert.ThrowsException <AssertFailedException>(() => Assert2.Throws <ArgumentNullException>(() => Test(0))).Message); Console.WriteLine(Assert.ThrowsException <AssertFailedException>(() => Assert2.Throws <ArgumentOutOfRangeException>(() => Test(null))).Message); Console.WriteLine(Assert2.Throws <ArgumentException>(() => Test(null)).Message); Console.WriteLine(Assert2.Throws <ArgumentNullException>(() => Test(null)).Message); }
public void Graph_AddDual_Rejects_DuplicateLinks() { var graph = new Graph <int, int>(x => x); graph.AddDual(0, 1, 1); // Verify that we can't add the duplicate unidirectional or bidirectional links, // specifying start and end in any order. Assert2.Throws <InvalidOperationException>(() => graph.AddLink(0, 1, 1)); Assert2.Throws <InvalidOperationException>(() => graph.AddLink(0, 1, 2)); Assert2.Throws <InvalidOperationException>(() => graph.AddLink(1, 0, 1)); Assert2.Throws <InvalidOperationException>(() => graph.AddLink(1, 0, 2)); Assert2.Throws <InvalidOperationException>(() => graph.AddDual(0, 1, 1)); Assert2.Throws <InvalidOperationException>(() => graph.AddDual(0, 1, 2)); Assert2.Throws <InvalidOperationException>(() => graph.AddDual(1, 0, 1)); Assert2.Throws <InvalidOperationException>(() => graph.AddDual(1, 0, 2)); }