public void ComposeReturnsCorrectResult() { // Fixture setup var targetType = typeof(string); var factory = new DelegatingSpecimenBuilder(); var sut = new TypedBuilderComposer(targetType, factory); // Exercise system var result = sut.Compose(); // Verify outcome var filter = Assert.IsAssignableFrom<FilteringSpecimenBuilder>(result); var orSpec = Assert.IsAssignableFrom<OrRequestSpecification>(filter.Specification); Assert.Equal(targetType, orSpec.Specifications.OfType<SeedRequestSpecification>().Single().TargetType); Assert.Equal(targetType, orSpec.Specifications.OfType<ExactTypeSpecification>().Single().TargetType); var composite = Assert.IsAssignableFrom<CompositeSpecimenBuilder>(filter.Builder); var outputGuard = Assert.IsAssignableFrom<NoSpecimenOutputGuard>(composite.Builders.First()); Assert.IsAssignableFrom<SeedIgnoringRelay>(composite.Builders.Last()); Assert.Equal(factory, outputGuard.Builder); var inverseSpec = Assert.IsAssignableFrom<InverseRequestSpecification>(outputGuard.Specification); var seedSpec = Assert.IsAssignableFrom<SeedRequestSpecification>(inverseSpec.Specification); Assert.Equal(targetType, seedSpec.TargetType); // Teardown }
public void SutIsSpecimenBuilderComposer() { // Fixture setup var dummyType = typeof(object); var dummyBuilder = new DelegatingSpecimenBuilder(); // Exercise system var sut = new TypedBuilderComposer(dummyType, dummyBuilder); // Verify outcome Assert.IsAssignableFrom<ISpecimenBuilderComposer>(sut); // Teardown }
public void FactoryIsCorrect() { // Fixture setup var dummyType = typeof(string); var expectedBuilder = new DelegatingSpecimenBuilder(); var sut = new TypedBuilderComposer(dummyType, expectedBuilder); // Exercise system ISpecimenBuilder result = sut.Factory; // Verify outcome Assert.Equal(expectedBuilder, result); // Teardown }
public void TargetTypeIsCorrect() { // Fixture setup var expectedType = typeof(decimal); var dummyBuilder = new DelegatingSpecimenBuilder(); var sut = new TypedBuilderComposer(expectedType, dummyBuilder); // Exercise system Type result = sut.TargetType; // Verify outcome Assert.Equal(expectedType, result); // Teardown }
/// <summary> /// Customizes the specified fixture by modifying <see cref="TargetType"/> to use /// <see cref="Query"/> as the strategy for creating new specimens. /// </summary> /// <param name="fixture">The fixture to customize.</param> public void Customize(IFixture fixture) { if (fixture == null) { throw new ArgumentNullException("fixture"); } var factory = new MethodInvoker(this.Query); var composer = new TypedBuilderComposer(this.TargetType, factory); fixture.Customizations.Insert(0, composer.Compose()); }