Example #1
0
        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
        }
Example #2
0
        /// <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());
        }