/// <summary>Executes all actions regardless of failed assertions (a.k.a. <c>AssertFailedException</c> thrown). If any assertions fail, a single /// assertion failure with aggregated assertion message texts is generated.</summary> public static void Aggregate(params Action[] actions) { try { MultiAssertForTException.Aggregate <AssertFailedException>(actions); } // Turn aggregated messages into a proper MS Test assert failed exception - but let other exceptions, including 'inconclusive' fall through: catch (AggregatedMessagesException e) { throw new AssertFailedException(e.Message); } }
public void WithDataPreRegistrationMustThrowArgumentExceptionWhenNoBuilderHasBeenRegistered() { ArgumentException actual = Assert.ThrowsException <ArgumentException>(() => _contextBuilder .WithData <DataWithNoHandler>() .WithData <AlsoDataWithNoHandler>() .Build()); MultiAssertForTException.Aggregate <AssertFailedException>( () => Assert.IsTrue(actual.Message.Contains(nameof(DataWithNoHandler)), $"Expected the exception to mention the type '{nameof(DataWithNoHandler)}' as not registered."), () => Assert.IsTrue(actual.Message.Contains(nameof(AlsoDataWithNoHandler)), $"Expected the exception to mention the type '{nameof(AlsoDataWithNoHandler)}' as not registered.")); }
public void BuildMustPassTheDataToTwoMocksWhenRegistered() { _contextBuilder .WithData(new DataWithTwoMocks { SomeData = "TheData" }) .Build(); DataWithTwoMocks[] allDataInMocks = _dataWithTwoMocksReader.Query().ToArray(); var actions = new List <Action> { () => Assert.AreEqual(2, allDataInMocks.Length, "Expected exactly two mocks."), () => Assert.AreEqual("TheData", allDataInMocks[0].SomeData, "Expected the data to be passed to the first registered mock-for-data."), () => Assert.AreEqual("TheData", allDataInMocks[1].SomeData, "Expected the data to be passed to the second registered mock-for-data.") }; MultiAssertForTException.Aggregate <AssertFailedException>(actions.ToArray()); }
public void WithClearDataStoreMustClearAllDataWhenCalled() { ContextBuilderFactory.ContextBuilder .WithData(new DataWithOneMock { SomeData = "TheData" }); DataWithOneMock firstPre = _contextBuilder.First <DataWithOneMock>(); DataWithOneMock lastPre = _contextBuilder.Last <DataWithOneMock>(); List <DataWithOneMock> allPre = _contextBuilder.All <DataWithOneMock>().ToList(); _contextBuilder.WithClearDataStore(); MultiAssertForTException.Aggregate <AssertFailedException>( () => Assert.IsTrue(allPre.Single() == firstPre, "Expected a single piece of data in the data store initially."), () => Assert.IsTrue(firstPre == lastPre, "Expected the first to be the last in the data store initially."), () => Assert.ThrowsException <KeyNotFoundException>(() => _contextBuilder.All <DataWithOneMock>(), "Expected an empty data store after WithClearDataStore.") ); }
public void BuildMustPassTheDataToBothStateHandlerAndMockForDataWhenRegistered() { _contextBuilder .WithEnumerableData(new List <DataWithOneMockAndOneStateHandler> { new DataWithOneMockAndOneStateHandler { SomeData = "TheData" } }) .Build(); DataWithOneMockAndOneStateHandler[] allDataInStateHandlers = _dataWithOneMockAndStateHandlersReader.Query().ToArray(); var actions = new List <Action> { () => Assert.AreEqual(2, allDataInStateHandlers.Length, "Expected exactly two state handlers."), () => Assert.AreEqual("TheData", allDataInStateHandlers[0].SomeData, "Expected the data to be passed to the first registered state handler."), () => Assert.AreEqual("TheData", allDataInStateHandlers[1].SomeData, "Expected the data to be passed to the second registered state handler.") }; MultiAssertForTException.Aggregate <AssertFailedException>(actions.ToArray()); }