public void CreateWillNotTriggerHandlingOnSecondarySameRequestWhenDecoratedBuilderThrows() { // Fixture setup var builder = new DelegatingSpecimenBuilder { OnCreate = (r, c) => { throw new PrivateExpectedException("The decorated builder always throws."); } }; var sut = new DelegatingRecursionGuard(builder) { OnHandleRecursiveRequest = o => { throw new PrivatUnexpectedException("Recursive handling should not be triggered."); } }; var dummyContext = new DelegatingSpecimenContext(); var sameRequest = new object(); // Exercise system and verify outcome Assert.Throws <PrivateExpectedException>(() => sut.Create(sameRequest, dummyContext)); Assert.Empty(sut.UnprotectedRecordedRequests); Assert.Throws <PrivateExpectedException>(() => sut.Create(sameRequest, dummyContext)); Assert.Empty(sut.UnprotectedRecordedRequests); }
public void CreateWillNotTriggerHandlingUntilDeeperThanRecursionDepth() { // Fixture setup var requestScenario = new Queue <int>(new[] { 1, 2, 1, 3, 1, 4 }); var builder = new DelegatingSpecimenBuilder(); builder.OnCreate = (r, c) => c.Resolve(requestScenario.Dequeue()); // By setting the depth to two we expect the handle to be triggered at the third "1" occurence. var sut = new DelegatingRecursionGuard(builder, 2); object recursiveRequest = null; sut.OnHandleRecursiveRequest = obj => recursiveRequest = obj; var container = new DelegatingSpecimenContext(); container.OnResolve = r => sut.Create(r, container); // Exercise system sut.Create(5, container); // Verify outcome // Check that recursion was actually detected as expected Assert.Equal(1, recursiveRequest); // Check that we passed the first recursion, but didn't go any further Assert.Equal(4, requestScenario.Dequeue()); }
public void CreateWillTriggerHandlingOnSecondLevelRecursiveRequest() { // Fixture setup object subRequest1 = Guid.NewGuid(); object subRequest2 = Guid.NewGuid(); var requestScenario = new Stack <object>(new [] { subRequest1, subRequest2, subRequest1 }); var builder = new DelegatingSpecimenBuilder(); builder.OnCreate = (r, c) => c.Resolve(requestScenario.Pop()); var sut = new DelegatingRecursionGuard(builder); object recursiveRequest = null; sut.OnHandleRecursiveRequest = obj => recursiveRequest = obj; var container = new DelegatingSpecimenContext(); container.OnResolve = (r) => sut.Create(r, container); // Exercise system sut.Create(Guid.NewGuid(), container); // Verify outcome Assert.Same(subRequest1, recursiveRequest); }
public void SutIsNode() { // Fixture setup var dummyBuilder = new DelegatingSpecimenBuilder(); // Exercise system var sut = new DelegatingRecursionGuard(dummyBuilder); // Verify outcome Assert.IsAssignableFrom<ISpecimenBuilderNode>(sut); // Teardown }
public void SutYieldsInjectedBuilder() { // Fixture setup var expected = new DelegatingSpecimenBuilder(); var sut = new DelegatingRecursionGuard(expected); // Exercise system // Verify outcome Assert.Equal(expected, sut.Single()); Assert.Equal(expected, ((System.Collections.IEnumerable)sut).Cast<object>().Single()); // Teardown }
public void SutIsNode() { // Fixture setup var dummyBuilder = new DelegatingSpecimenBuilder(); // Exercise system var sut = new DelegatingRecursionGuard(dummyBuilder); // Verify outcome Assert.IsAssignableFrom <ISpecimenBuilderNode>(sut); // Teardown }
public void ComparerIsCorrect() { // Fixture setup var dummyBuilder = new DelegatingSpecimenBuilder(); var expected = new DelegatingEqualityComparer(); var sut = new DelegatingRecursionGuard(dummyBuilder, expected); // Exercise system IEqualityComparer actual = sut.Comparer; // Verify outcome Assert.Equal(expected, actual); // Teardown }
public void SutYieldsInjectedBuilder() { // Fixture setup var expected = new DelegatingSpecimenBuilder(); var sut = new DelegatingRecursionGuard(expected); // Exercise system // Verify outcome Assert.Equal(expected, sut.Single()); Assert.Equal(expected, ((System.Collections.IEnumerable)sut).Cast <object>().Single()); // Teardown }
public void CreateWillNotTriggerHandlingOnFirstRequest() { // Fixture setup var sut = new DelegatingRecursionGuard(new DelegatingSpecimenBuilder()); bool handlingTriggered = false; sut.OnHandleRecursiveRequest = obj => handlingTriggered = true; // Exercise system sut.Create(Guid.NewGuid(), new DelegatingSpecimenContext()); // Verify outcome Assert.False(handlingTriggered); }
public void CreateWillTriggerHandlingOnRecursiveRequests() { // Fixture setup var builder = new DelegatingSpecimenBuilder(); builder.OnCreate = (r, c) => c.Resolve(r); var sut = new DelegatingRecursionGuard(builder); bool handlingTriggered = false; sut.OnHandleRecursiveRequest = obj => handlingTriggered = true; var container = new DelegatingSpecimenContext(); container.OnResolve = (r) => sut.Create(r, container); // Exercise system sut.Create(Guid.NewGuid(), container); // Verify outcome Assert.True(handlingTriggered); }
public void CreateWillUseEqualityComparer() { // Fixture setup var builder = new DelegatingSpecimenBuilder(); builder.OnCreate = (r, c) => c.Resolve(r); bool comparerUsed = false; var comparer = new DelegatingEqualityComparer { OnEquals = (x, y) => comparerUsed = true }; var sut = new DelegatingRecursionGuard(builder, comparer); sut.OnHandleRecursiveRequest = (obj) => { return(null); }; var container = new DelegatingSpecimenContext(); container.OnResolve = (r) => sut.Create(r, container); // Exercise system sut.Create(Guid.NewGuid(), container); // Verify outcome Assert.True(comparerUsed); }
public void CreateWillNotTriggerHandlingOnSecondarySameRequestWhenDecoratedBuilderThrows() { // Fixture setup var builder = new DelegatingSpecimenBuilder { OnCreate = (r, c) => { throw new PrivateExpectedException("The decorated builder always throws."); }}; var sut = new DelegatingRecursionGuard(builder) { OnHandleRecursiveRequest = o => { throw new PrivatUnexpectedException("Recursive handling should not be triggered."); }}; var dummyContext = new DelegatingSpecimenContext(); var sameRequest = new object(); // Exercise system and verify outcome Assert.Throws<PrivateExpectedException>(() => sut.Create(sameRequest, dummyContext)); Assert.Empty(sut.UnprotectedRecordedRequests); Assert.Throws<PrivateExpectedException>(() => sut.Create(sameRequest, dummyContext)); Assert.Empty(sut.UnprotectedRecordedRequests); }
public void CreateWillTriggerHandlingOnSecondLevelRecursiveRequest() { // Fixture setup object subRequest1 = Guid.NewGuid(); object subRequest2 = Guid.NewGuid(); var requestScenario = new Stack<object>(new [] { subRequest1, subRequest2, subRequest1 }); var builder = new DelegatingSpecimenBuilder(); builder.OnCreate = (r, c) => c.Resolve(requestScenario.Pop()); var sut = new DelegatingRecursionGuard(builder); object recursiveRequest = null; sut.OnHandleRecursiveRequest = obj => recursiveRequest = obj; var container = new DelegatingSpecimenContext(); container.OnResolve = (r) => sut.Create(r, container); // Exercise system sut.Create(Guid.NewGuid(), container); // Verify outcome Assert.Same(subRequest1, recursiveRequest); }
public void CreateWillNotTriggerHandlingUntilDeeperThanRecursionDepth() { // Fixture setup var requestScenario = new Queue<int>(new[] { 1, 2, 1, 3, 1, 4 }); var builder = new DelegatingSpecimenBuilder(); builder.OnCreate = (r, c) => c.Resolve(requestScenario.Dequeue()); // By setting the depth to two we expect the handle to be triggered at the third "1" occurence. var sut = new DelegatingRecursionGuard(builder, 2); object recursiveRequest = null; sut.OnHandleRecursiveRequest = obj => recursiveRequest = obj; var container = new DelegatingSpecimenContext(); container.OnResolve = r => sut.Create(r, container); // Exercise system sut.Create(5, container); // Verify outcome // Check that recursion was actually detected as expected Assert.Equal(1, recursiveRequest); // Check that we passed the first recursion, but didn't go any further Assert.Equal(4, requestScenario.Dequeue()); }
public void CreateWillUseEqualityComparer() { // Fixture setup var builder = new DelegatingSpecimenBuilder(); builder.OnCreate = (r, c) => c.Resolve(r); bool comparerUsed = false; var comparer = new DelegatingEqualityComparer { OnEquals = (x, y) => comparerUsed = true }; var sut = new DelegatingRecursionGuard(builder, comparer); sut.OnHandleRecursiveRequest = (obj) => { return null; }; var container = new DelegatingSpecimenContext(); container.OnResolve = (r) => sut.Create(r, container); // Exercise system sut.Create(Guid.NewGuid(), container); // Verify outcome Assert.True(comparerUsed); }
public void CreateWillNotTriggerHandlingOnSubsequentSimilarRequests() { // Fixture setup var sut = new DelegatingRecursionGuard(new DelegatingSpecimenBuilder()); bool handlingTriggered = false; object request = Guid.NewGuid(); sut.OnHandleRecursiveRequest = obj => handlingTriggered = true; // Exercise system sut.Create(request, new DelegatingSpecimenContext()); sut.Create(request, new DelegatingSpecimenContext()); // Verify outcome Assert.False(handlingTriggered); }