public void ConstructWithBuilderAndNullHandlerAndComparerThrows() { // Fixture setup var dummyBuilder = new DelegatingSpecimenBuilder(); var dummyComparer = new DelegatingEqualityComparer(); // Exercise system and verify outcome Assert.Throws <ArgumentNullException>( () => new RecursionGuard(dummyBuilder, null, dummyComparer)); // Teardown }
public void ConstructWithNullBuilderAndHandlerAndComparerAndRecursionDepthThrows() { // Fixture setup var dummyHandler = new DelegatingRecursionHandler(); var dummyComparer = new DelegatingEqualityComparer(); var dummyRecursionDepth = 2; // Exercise system and verify outcome Assert.Throws <ArgumentNullException>( () => new RecursionGuard(null, dummyHandler, dummyComparer, dummyRecursionDepth)); // 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 ConstructorWithRecusionDepthLowerThanOneThrows(int recursionDepth) { // Fixture setup var dummyBuilder = new DelegatingSpecimenBuilder(); var dummyHandler = new DelegatingRecursionHandler(); var dummyComparer = new DelegatingEqualityComparer(); // Exercise system and verify outcome Assert.Throws <ArgumentOutOfRangeException>(() => new RecursionGuard(dummyBuilder, dummyHandler, dummyComparer, recursionDepth)); // Teardown }
public void ComposeRetainsHandler() { // Fixture setup var dummyBuilder = new DelegatingSpecimenBuilder(); var expected = new DelegatingRecursionHandler(); var dummyComparer = new DelegatingEqualityComparer(); var sut = new RecursionGuard(dummyBuilder, expected, dummyComparer); // Exercise system var actual = sut.Compose(new ISpecimenBuilder[0]); // Verify outcome var rg = Assert.IsAssignableFrom<RecursionGuard>(actual); Assert.Equal(expected, rg.RecursionHandler); // Teardown }
public void ConstructWithBuilderAndHandlerAndComparerHasCorrectComparer() { // Fixture setup var dummyBuilder = new DelegatingSpecimenBuilder(); var dummyHandler = new DelegatingRecursionHandler(); var expected = new DelegatingEqualityComparer(); var sut = new RecursionGuard(dummyBuilder, dummyHandler, expected); // Exercise system var actual = sut.Comparer; // Verify outcome Assert.Equal(expected, actual); // Teardown }
public void ComposeRetainsComparer() { // Fixture setup var dummyBuilder = new DelegatingSpecimenBuilder(); var dummyHandler = new DelegatingRecursionHandler(); var expected = new DelegatingEqualityComparer(); var sut = new RecursionGuard(dummyBuilder, dummyHandler, expected); // Exercise system var actual = sut.Compose(new ISpecimenBuilder[0]); // Verify outcome var rg = Assert.IsAssignableFrom <RecursionGuard>(actual); Assert.Equal(expected, rg.Comparer); // Teardown }
public void ConstructWithBuilderAndHandlerAndComparerHasCorrectBuilder() { // Fixture setup var expected = new DelegatingSpecimenBuilder(); var dummyHandler = new DelegatingRecursionHandler(); var dummyComparer = new DelegatingEqualityComparer(); #pragma warning disable 618 var sut = new RecursionGuard(expected, dummyHandler, dummyComparer); #pragma warning restore 618 // Exercise system var actual = sut.Builder; // Verify outcome Assert.Equal(expected, actual); // Teardown }
public void ComposeSingleItemReturnsCorrectResult() { // Fixture setup var dummyBuilder = new DelegatingSpecimenBuilder(); var dummyHandler = new DelegatingRecursionHandler(); var dummyComparer = new DelegatingEqualityComparer(); int dummyRecursionDepth = 2; var sut = new RecursionGuard(dummyBuilder, dummyHandler, dummyComparer, dummyRecursionDepth); // Exercise system var expected = new DelegatingSpecimenBuilder(); var actual = sut.Compose(new[] { expected }); // Verify outcome var rg = Assert.IsAssignableFrom <RecursionGuard>(actual); Assert.Equal(expected, rg.Builder); // Teardown }
public void ComposeReturnsCorrectResult() { // Fixture setup var dummyBuilder = new DelegatingSpecimenBuilder(); var dummyHandler = new DelegatingRecursionHandler(); var dummyComparer = new DelegatingEqualityComparer(); var sut = new RecursionGuard(dummyBuilder, dummyHandler, dummyComparer); // Exercise system var expectedBuilders = new[] { new DelegatingSpecimenBuilder(), new DelegatingSpecimenBuilder(), new DelegatingSpecimenBuilder() }; var actual = sut.Compose(expectedBuilders); // Verify outcome var rg = Assert.IsAssignableFrom<RecursionGuard>(actual); var composite = Assert.IsAssignableFrom<CompositeSpecimenBuilder>(rg.Builder); Assert.True(expectedBuilders.SequenceEqual(composite)); // Teardown }
public void ComposeReturnsCorrectResult() { // Fixture setup var dummyBuilder = new DelegatingSpecimenBuilder(); var dummyHandler = new DelegatingRecursionHandler(); var dummyComparer = new DelegatingEqualityComparer(); var sut = new RecursionGuard(dummyBuilder, dummyHandler, dummyComparer); // Exercise system var expectedBuilders = new[] { new DelegatingSpecimenBuilder(), new DelegatingSpecimenBuilder(), new DelegatingSpecimenBuilder() }; var actual = sut.Compose(expectedBuilders); // Verify outcome var rg = Assert.IsAssignableFrom <RecursionGuard>(actual); var composite = Assert.IsAssignableFrom <CompositeSpecimenBuilder>(rg.Builder); Assert.True(expectedBuilders.SequenceEqual(composite)); // Teardown }
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 CreateReturnsResultFromInjectedHandlerWhenRequestIsMatched() { // Fixture setup var builder = new DelegatingSpecimenBuilder() { OnCreate = (r, ctx) => ctx.Resolve(r) }; var request = new object(); var expected = new object(); var handlerStub = new DelegatingRecursionHandler { OnHandleRecursiveRequest = (r, rs) => { Assert.Equal(request, r); Assert.NotNull(rs); return(expected); } }; var comparer = new DelegatingEqualityComparer { OnEquals = (x, y) => true }; var sut = new RecursionGuard(builder, handlerStub, comparer, 1); var context = new DelegatingSpecimenContext(); context.OnResolve = r => sut.Create(r, context); // Exercise system var actual = sut.Create(request, context); // Verify outcome Assert.Equal(expected, actual); // Teardown }
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 ConstructorWithRecusionDepthLowerThanOneThrows(int recursionDepth) { // Fixture setup var dummyBuilder = new DelegatingSpecimenBuilder(); var dummyHandler = new DelegatingRecursionHandler(); var dummyComparer = new DelegatingEqualityComparer(); // Exercise system and verify outcome Assert.Throws<ArgumentOutOfRangeException>(() => new RecursionGuard(dummyBuilder, dummyHandler, dummyComparer, recursionDepth)); // Teardown }
public void ConstructWithBuilderAndHandlerAndComparerAndRecursionDepthHasCorrectRecursionDepth() { // Fixture setup var dummyBuilder = new DelegatingSpecimenBuilder(); var dummyHandler = new DelegatingRecursionHandler(); var dummyComparer = new DelegatingEqualityComparer(); var expected = 2; var sut = new RecursionGuard(dummyBuilder, dummyHandler, dummyComparer, expected); // Exercise system var actual = sut.RecursionDepth; // Verify outcome Assert.Equal(expected, actual); // Teardown }
public void ConstructWithBuilderAndNullHandlerAndComparerAndRecursionDepthThrows() { // Fixture setup var dummyBuilder = new DelegatingSpecimenBuilder(); var dummyComparer = new DelegatingEqualityComparer(); var dummyRecursionDepth = 2; // Exercise system and verify outcome Assert.Throws<ArgumentNullException>( () => new RecursionGuard(dummyBuilder, null, dummyComparer, dummyRecursionDepth)); // Teardown }
public void ConstructWithBuilderAndHandlerAndComparerHasCorrectComparer() { // Fixture setup var dummyBuilder = new DelegatingSpecimenBuilder(); var dummyHandler = new DelegatingRecursionHandler(); var expected = new DelegatingEqualityComparer(); #pragma warning disable 618 var sut = new RecursionGuard(dummyBuilder, dummyHandler, expected); #pragma warning restore 618 // Exercise system var actual = sut.Comparer; // Verify outcome Assert.Equal(expected, actual); // Teardown }
public void CreateReturnsResultFromInjectedHandlerWhenRequestIsMatched() { // Fixture setup var builder = new DelegatingSpecimenBuilder() { OnCreate = (r, ctx) => ctx.Resolve(r) }; var request = new object(); var expected = new object(); var handlerStub = new DelegatingRecursionHandler { OnHandleRecursiveRequest = (r, rs) => { Assert.Equal(request, r); Assert.NotNull(rs); return expected; } }; var comparer = new DelegatingEqualityComparer { OnEquals = (x, y) => true }; var sut = new RecursionGuard(builder, handlerStub, comparer, 1); var context = new DelegatingSpecimenContext(); context.OnResolve = r => sut.Create(r, context); // Exercise system var actual = sut.Create(request, context); // Verify outcome Assert.Equal(expected, actual); // Teardown }
public void ComposeSingleItemReturnsCorrectResult() { // Fixture setup var dummyBuilder = new DelegatingSpecimenBuilder(); var dummyHandler = new DelegatingRecursionHandler(); var dummyComparer = new DelegatingEqualityComparer(); int dummyRecursionDepth = 2; var sut = new RecursionGuard(dummyBuilder, dummyHandler, dummyComparer, dummyRecursionDepth); // Exercise system var expected = new DelegatingSpecimenBuilder(); var actual = sut.Compose(new[] { expected }); // Verify outcome var rg = Assert.IsAssignableFrom<RecursionGuard>(actual); Assert.Equal(expected, rg.Builder); // Teardown }
public void ConstructWithNullBuilderAndHandlerAndComparerThrows() { // Fixture setup var dummyHandler = new DelegatingRecursionHandler(); var dummyComparer = new DelegatingEqualityComparer(); // Exercise system and verify outcome Assert.Throws<ArgumentNullException>( () => new RecursionGuard(null, dummyHandler, dummyComparer)); // Teardown }