public void CreateOnMultipleThreadsConcurrentlyWorks() { // Fixture setup var dummyBuilder = new DelegatingSpecimenBuilder { OnCreate = (r, ctx) => ctx.Resolve(r) }; var dummyHandler = new DelegatingRecursionHandler(); var sut = new RecursionGuard(dummyBuilder, dummyHandler); var dummyContext = new DelegatingSpecimenContext() { OnResolve = (r) => 99 }; // Exercise system int[] specimens = Enumerable.Range(0, 1000) .AsParallel() .WithDegreeOfParallelism(8) .WithExecutionMode(ParallelExecutionMode.ForceParallelism) .Select(x => (int)sut.Create(typeof(int), dummyContext)) .ToArray(); // Verify outcome Assert.Equal(1000, specimens.Length); Assert.True(specimens.All(s => s == 99)); // Teardown }
public void ConstructWithNullBuilderAndRecursionHandlerThrows() { // Fixture setup var dummyHandler = new DelegatingRecursionHandler(); // Exercise system and verify outcome Assert.Throws <ArgumentNullException>( () => new RecursionGuard(null, dummyHandler)); // Teardown }
public void ConstructWithBuilderAndHandlerSetsRecursionDepthCorrectly() { // Fixture setup var dummyBuilder = new DelegatingSpecimenBuilder(); var dummyHandler = new DelegatingRecursionHandler(); // Exercise system var sut = new RecursionGuard(dummyBuilder, dummyHandler); // Verify outcome Assert.Equal(1, sut.RecursionDepth); }
public void ConstructWithBuilderAndHandlerAndNullComparerThrows() { // Fixture setup var dummyBuilder = new DelegatingSpecimenBuilder(); var dummyHandler = new DelegatingRecursionHandler(); // Exercise system and verify outcome Assert.Throws <ArgumentNullException>( () => new RecursionGuard(dummyBuilder, dummyHandler, null)); // 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 ConstructWithBuilderAndRecursionHandlerHasCorrectComparer() { // Fixture setup var dummyBuilder = new DelegatingSpecimenBuilder(); var dummyHandler = new DelegatingRecursionHandler(); var sut = new RecursionGuard(dummyBuilder, dummyHandler); // Exercise system var actual = sut.Comparer; // Verify outcome Assert.Equal(EqualityComparer <object> .Default, actual); // Teardown }
public void ConstructWithBuilderAndRecursionHandlerHasCorrectBuilder() { // Fixture setup var expected = new DelegatingSpecimenBuilder(); var dummyHandler = new DelegatingRecursionHandler(); var sut = new RecursionGuard(expected, dummyHandler); // Exercise system var actual = sut.Builder; // Verify outcome Assert.Equal(expected, actual); // 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 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 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 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 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 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 ConstructWithNullBuilderAndRecursionHandlerThrows() { // Fixture setup var dummyHandler = new DelegatingRecursionHandler(); // Exercise system and verify outcome Assert.Throws<ArgumentNullException>( () => new RecursionGuard(null, dummyHandler)); // 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 ConstructWithBuilderAndHandlerAndNullComparerAndRecursionDepthThrows() { // Fixture setup var dummyBuilder = new DelegatingSpecimenBuilder(); var dummyHandler = new DelegatingRecursionHandler(); var dummyRecursionDepth = 2; // Exercise system and verify outcome Assert.Throws<ArgumentNullException>( () => new RecursionGuard(dummyBuilder, dummyHandler, null, dummyRecursionDepth)); // Teardown }
public void ConstructWithBuilderSetsRecursionDepthCorrectly() { // Fixture setup var dummyBuilder = new DelegatingSpecimenBuilder(); var dummyHandler = new DelegatingRecursionHandler(); // Exercise system #pragma warning disable 618 var sut = new RecursionGuard(dummyBuilder); #pragma warning restore 618 // Verify outcome Assert.Equal(1, sut.RecursionDepth); }
public void ConstructWithBuilderAndHandlerAndRecursionDepthSetsRecursionDepthCorrectly() { // Fixture setup var dummyBuilder = new DelegatingSpecimenBuilder(); var dummyHandler = new DelegatingRecursionHandler(); const int explicitRecursionDepth = 2; // Exercise system var sut = new RecursionGuard(dummyBuilder, dummyHandler, explicitRecursionDepth); // Verify outcome Assert.Equal(explicitRecursionDepth, sut.RecursionDepth); }
public void ConstructWithBuilderAndRecursionHandlerHasCorrectComparer() { // Fixture setup var dummyBuilder = new DelegatingSpecimenBuilder(); var dummyHandler = new DelegatingRecursionHandler(); var sut = new RecursionGuard(dummyBuilder, dummyHandler); // Exercise system var actual = sut.Comparer; // Verify outcome Assert.Equal(EqualityComparer<object>.Default, 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 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 }