コード例 #1
0
ファイル: Omitter.cs プロジェクト: nrjohnstone/AutoFixture
        /// <summary>
        /// Initializes a new instance of the <see cref="Omitter" /> class with
        /// the supplied <see cref="IRequestSpecification" />.
        /// </summary>
        /// <param name="specification">
        /// A specification used to control whether or not an
        /// <see cref="OmitSpecimen" /> instance should be issued.
        /// </param>
        /// <exception cref="System.ArgumentNullException">
        /// specification
        /// </exception>
        /// <seealso cref="Specification" />
        public Omitter(IRequestSpecification specification)
        {
            if (specification == null)
                throw new ArgumentNullException("specification");

            this.specification = specification;
        }
コード例 #2
0
ファイル: Postprocessor.cs プロジェクト: wqshabib/AutoFixture
 /// <summary>
 /// Initializes a new instance of the <see cref="Postprocessor" />
 /// class.
 /// </summary>
 /// <param name="builder">
 /// The <see cref="ISpecimenBuilder"/> to decorate.
 /// </param>
 /// <param name="command">
 /// The command to apply to the created specimen.
 /// </param>
 /// A specification which is used to determine whether postprocessing
 /// should be performed
 /// <param name="specification">
 /// </param>
 public Postprocessor(
     ISpecimenBuilder builder,
     ISpecimenCommand command,
     IRequestSpecification specification)
     : base(builder, command, specification)
 {
 }
 public FreezeSpecimenOnMatchCustomization(
     object specimen,
     IRequestSpecification matcher)
 {
     _specimen = specimen;
     _matcher  = matcher ?? throw new ArgumentNullException(nameof(matcher));
 }
コード例 #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FreezeOnMatchCustomization"/> class.
 /// </summary>
 /// <param name="request">The request used to create a specimen to freeze.</param>
 /// <param name="matcher">
 /// The <see cref="IRequestSpecification"/> used to match the requests
 /// that will be satisfied by the frozen specimen.
 /// </param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="request"/> or <paramref name="matcher"/> is null.
 /// </exception>
 public FreezeOnMatchCustomization(
     object request,
     IRequestSpecification matcher)
 {
     this.Request = request ?? throw new ArgumentNullException(nameof(request));
     this.Matcher = matcher ?? throw new ArgumentNullException(nameof(matcher));
 }
コード例 #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FakeItEasyRelay"/> class with a specification
        /// that determines whether a type should be mocked.
        /// </summary>
        /// <param name="fakeableSpecification">
        /// A specification that determines whether a type should be mocked or not.
        /// </param>
        public FakeItEasyRelay(IRequestSpecification fakeableSpecification)
        {
            if (fakeableSpecification == null)
                throw new ArgumentNullException("fakeableSpecification");

            this.fakeableSpecification = fakeableSpecification;
        }
コード例 #6
0
 public Filter Or(IRequestSpecification condition)
 {
     return(new Filter(
                new OrRequestSpecification(
                    criteria,
                    condition)));
 }
コード例 #7
0
            /// <summary>
            /// Initializes a new instance of the <see cref="DecorateWithInputFilterTransformation"/> class.
            /// </summary>
            /// <param name="inputFilter">The input filter.</param>
            public DecorateWithInputFilterTransformation(IRequestSpecification inputFilter)
            {
                if (inputFilter == null)
                {
                    throw new ArgumentNullException("inputFilter");
                }

                this.inputFilter = inputFilter;
            }
コード例 #8
0
ファイル: MockRelay.cs プロジェクト: yreynhout/AutoFixture
        /// <summary>
        /// Initializes a new instance of the <see cref="MockRelay"/> class with a specification
        /// that determines whether a type should be mocked.
        /// </summary>
        /// <param name="mockableSpecification">
        /// A specification that determines whether a type should be mocked or not.
        /// </param>
        public MockRelay(IRequestSpecification mockableSpecification)
        {
            if (mockableSpecification == null)
            {
                throw new ArgumentNullException("mockableSpecification");
            }

            this.mockableSpecification = mockableSpecification;
        }
コード例 #9
0
ファイル: Omitter.cs プロジェクト: ngm/AutoFixture
        /// <summary>
        /// Initializes a new instance of the <see cref="Omitter" /> class with
        /// the supplied <see cref="IRequestSpecification" />.
        /// </summary>
        /// <param name="specification">
        /// A specification used to control whether or not an
        /// <see cref="OmitSpecimen" /> instance should be issued.
        /// </param>
        /// <exception cref="System.ArgumentNullException">
        /// specification
        /// </exception>
        /// <seealso cref="Specification" />
        public Omitter(IRequestSpecification specification)
        {
            if (specification == null)
            {
                throw new ArgumentNullException("specification");
            }

            this.specification = specification;
        }
コード例 #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="InverseRequestSpecification"/> by
        /// decorating the supplied specification.
        /// </summary>
        /// <param name="specification">
        /// The <see cref="IRequestSpecification"/> to decorate.
        /// </param>
        public InverseRequestSpecification(IRequestSpecification specification)
        {
            if (specification == null)
            {
                throw new ArgumentNullException("specification");
            }

            this.spec = specification;
        }
コード例 #11
0
 public SqliteConnectionBuilder(
     string connectionString,
     IRequestSpecification connectionSpecification)
 {
     this.ConnectionString = connectionString
                             ?? throw new ArgumentNullException(nameof(connectionString));
     this.ConnectionSpecification = connectionSpecification
                                    ?? throw new ArgumentNullException(nameof(connectionSpecification));
 }
コード例 #12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="InverseRequestSpecification"/> by
        /// decorating the supplied specification.
        /// </summary>
        /// <param name="specification">
        /// The <see cref="IRequestSpecification"/> to decorate.
        /// </param>
        public InverseRequestSpecification(IRequestSpecification specification)
        {
            if (specification == null)
            {
                throw new ArgumentNullException("specification");
            }

            this.spec = specification;
        }
コード例 #13
0
ファイル: MockRelay.cs プロジェクト: nrjohnstone/AutoFixture
        /// <summary>
        /// Initializes a new instance of the <see cref="MockRelay"/> class with a specification
        /// that determines whether a type should be mocked.
        /// </summary>
        /// <param name="mockableSpecification">
        /// A specification that determines whether a type should be mocked or not.
        /// </param>
        public MockRelay(IRequestSpecification mockableSpecification)
        {
            if (mockableSpecification == null)
            {
                throw new ArgumentNullException("mockableSpecification");
            }

            this.mockableSpecification = mockableSpecification;
        }
コード例 #14
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FakeItEasyRelay"/> class with a specification
        /// that determines whether a type should be mocked.
        /// </summary>
        /// <param name="fakeableSpecification">
        /// A specification that determines whether a type should be mocked or not.
        /// </param>
        public FakeItEasyRelay(IRequestSpecification fakeableSpecification)
        {
            if (fakeableSpecification == null)
            {
                throw new ArgumentNullException("fakeableSpecification");
            }

            this.fakeableSpecification = fakeableSpecification;
        }
コード例 #15
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TracingBuilder"/> class with a decorated
        /// <see cref="ISpecimenBuilder"/>.
        /// </summary>
        /// <param name="builder">The <see cref="ISpecimenBuilder"/> to decorate.</param>
        public TracingBuilder(ISpecimenBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException("builder");
            }

            this.builder = builder;
            this.filter = new TrueRequestSpecification();
        }
コード例 #16
0
        /// <summary>Initializes a new instance of the <see cref="NSubstituteBuilder"/> class with an
        ///     <see cref="ISpecimenBuilder"/> to decorate.</summary>
        /// <param name="builder">The builder which must build mock instances.</param>
        /// <param name="substitutionSpecification">A specification that determines whether a substitute should be created for a given request or not.</param>
        /// <remarks>
        ///     <para><paramref name="builder"/> is subsequently available through the <see cref="Builder"/> property.</para>
        ///     <para><paramref name="substitutionSpecification"/> is subsequently available through the <see cref="SubstitutionSpecification"/> property.</para>
        /// </remarks>
        /// <seealso cref="Builder"/>
        /// <seealso cref="SubstitutionSpecification"/>
        public NSubstituteBuilder(ISpecimenBuilder builder, IRequestSpecification substitutionSpecification)
        {
            if (builder == null)
                throw new ArgumentNullException("builder");
            if (substitutionSpecification == null)
                throw new ArgumentNullException("substitutionSpecification");

            this.builder = builder;
            this.substitutionSpecification = substitutionSpecification;
        }
コード例 #17
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TracingBuilder"/> class with a decorated
        /// <see cref="ISpecimenBuilder"/>.
        /// </summary>
        /// <param name="builder">The <see cref="ISpecimenBuilder"/> to decorate.</param>
        public TracingBuilder(ISpecimenBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            this.Builder = builder;
            this.filter  = new TrueRequestSpecification();
        }
コード例 #18
0
        public void SpecificationMatchesConstructorArgument()
        {
            // Arrange
            var expected = new DelegatingRequestSpecification();
            var sut      = new Omitter(expected);
            // Act
            IRequestSpecification actual = sut.Specification;

            // Assert
            Assert.Equal(expected, actual);
        }
コード例 #19
0
        public void SpecificationIsCorrectWhenInitializedWithModestCtor()
        {
            // Arrange
            var dummyBuilder = new DelegatingSpecimenBuilder();
            var sut          = new NoSpecimenOutputGuard(dummyBuilder);
            // Act
            IRequestSpecification result = sut.Specification;

            // Assert
            Assert.IsAssignableFrom <TrueRequestSpecification>(result);
        }
コード例 #20
0
ファイル: MockRelayTest.cs プロジェクト: zvirja/AutoFixture
        public void SpecificationIsCorrectWhenInitializedWithSpecification()
        {
            // Arrange
            var expected = new Mock <IRequestSpecification>().Object;
            var sut      = new MockRelay(expected);
            // Act
            IRequestSpecification result = sut.MockableSpecification;

            // Assert
            Assert.Equal(expected, result);
        }
        public void ShouldCreateConstructorParametersIfFilterIsSatisfied(
            [Frozen] IRequestSpecification requestSpecification,
            ISpecimenContext specimenContext,
            RecordReplayConstructorSpecimensForTypeBuilder sut)
        {
            requestSpecification.IsSatisfiedBy(Arg.Any <object>()).Returns(true);

            sut.Create(typeof(SimpleType), specimenContext);

            specimenContext.Received(1).Resolve(Arg.Any <object>());
        }
コード例 #22
0
        public void SpecificationIsCorrectly()
        {
            // Arrange
            var expectedSpec = new DelegatingRequestSpecification();
            var sut          = new InverseRequestSpecification(expectedSpec);
            // Act
            IRequestSpecification result = sut.Specification;

            // Assert
            Assert.Equal(expectedSpec, result);
        }
        public void ShouldDelegateToDecoratedBuilderIfFilterIsNotSatisfied(
            [Frozen] IRequestSpecification requestSpecification,
            [Substitute] ISpecimenBuilder builder)
        {
            requestSpecification.IsSatisfiedBy(Arg.Any <object>()).Returns(false);

            var sut = new RecordReplayConstructorSpecimensForTypeBuilder(builder, requestSpecification);

            sut.CreateInstanceOfType(typeof(object));

            builder.Received(1).Create(Arg.Any <object>(), Arg.Any <ISpecimenContext>());
        }
コード例 #24
0
ファイル: OmitterTests.cs プロジェクト: wqshabib/AutoFixture
        public void SpecificationMatchesConstructorArgument()
        {
            // Fixture setup
            var expected = new DelegatingRequestSpecification();
            var sut      = new Omitter(expected);
            // Exercise system
            IRequestSpecification actual = sut.Specification;

            // Verify outcome
            Assert.Equal(expected, actual);
            // Teardown
        }
        public void ShouldUseRecordedConstructorSpecimensInSubsequentCallsForTheSameRequest(
            [Frozen] IRequestSpecification requestSpecification,
            ISpecimenContext context,
            RecordReplayConstructorSpecimensForTypeBuilder sut)
        {
            requestSpecification.IsSatisfiedBy(Arg.Any <object>()).Returns(true);

            sut.Create(typeof(SimpleType), context);
            sut.Create(typeof(SimpleType), context);

            context.Received(1).Resolve(Arg.Any <object>());
        }
コード例 #26
0
        public void SpecificationIsCorrectly()
        {
            // Fixture setup
            var expectedSpec = new DelegatingRequestSpecification();
            var sut          = new InverseRequestSpecification(expectedSpec);
            // Exercise system
            IRequestSpecification result = sut.Specification;

            // Verify outcome
            Assert.Equal(expectedSpec, result);
            // Teardown
        }
コード例 #27
0
        public void SpecificationIsCorrect()
        {
            // Arrange
            var dummyBuilder          = new DelegatingSpecimenBuilder();
            var expectedSpecification = new DelegatingRequestSpecification();
            var sut = new FilteringSpecimenBuilder(dummyBuilder, expectedSpecification);
            // Act
            IRequestSpecification result = sut.Specification;

            // Assert
            Assert.Equal(expectedSpecification, result);
        }
コード例 #28
0
        public void SpecificationIsCorrectWhenInitializedWithModestCtor()
        {
            // Fixture setup
            var dummyBuilder = new DelegatingSpecimenBuilder();
            var sut          = new NoSpecimenOutputGuard(dummyBuilder);
            // Exercise system
            IRequestSpecification result = sut.Specification;

            // Verify outcome
            Assert.IsAssignableFrom <TrueRequestSpecification>(result);
            // Teardown
        }
コード例 #29
0
ファイル: MockRelayTest.cs プロジェクト: wertzui/AutoFixture
        public void SpecificationIsCorrectWhenInitializedWithSpecification()
        {
            // Fixture setup
            var expected = new Mock <IRequestSpecification>().Object;
            var sut      = new MockRelay(expected);
            // Exercise system
            IRequestSpecification result = sut.MockableSpecification;

            // Verify outcome
            Assert.Equal(expected, result);
            // Teardown
        }
コード例 #30
0
        public void FilterIsProperWritableProperty()
        {
            // Arrange
            var sut = new DelegatingTracingBuilder();
            IRequestSpecification expectedFilter = new DelegatingRequestSpecification();

            // Act
            sut.Filter = expectedFilter;
            IRequestSpecification result = sut.Filter;

            // Assert
            Assert.Equal(expectedFilter, result);
        }
コード例 #31
0
        public void SpecificationIsCorrect()
        {
            // Fixture setup
            var dummyBuilder          = new DelegatingSpecimenBuilder();
            var expectedSpecification = new DelegatingRequestSpecification();
            var sut = new FilteringSpecimenBuilder(dummyBuilder, expectedSpecification);
            // Exercise system
            IRequestSpecification result = sut.Specification;

            // Verify outcome
            Assert.Equal(expectedSpecification, result);
            // Teardown
        }
コード例 #32
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TypeRelay"/> class.
        /// </summary>
        /// <param name="from">
        /// The <see cref="Type" /> from which the TypeRelay instance should map.
        /// </param>
        /// <param name="to">
        /// The <see cref="Type" /> to which the TypeRelay instance should map.
        /// </param>
        /// <remarks>
        /// <para>
        /// The <paramref name="from" /> and <paramref name="to" /> parameters are used by the
        /// <see cref="Create" /> method to map a request for the <i>from</i> Type into a request
        /// for the <i>to</i> Type.
        /// </para>
        /// </remarks>
        /// <example>
        /// In this example, BaseType is an abstract base class, and
        /// DerivedType is a concrete class that derives from BaseType. The
        /// Fixture instance is configured to relay all requests for BasetType
        /// to requests for DerivedType, so the actual result return from the
        /// fixture when BasetType is requested is a DerivedType instance.
        /// <code>
        /// var fixture = new Fixture();
        /// fixture.Customizations.Add(
        ///     new TypeRelay(
        ///         typeof(BaseType),
        ///         typeof(DerivedType)));
        ///
        /// var actual = fixture.Create&lt;BaseType&gt;();
        /// </code>
        /// </example>
        public TypeRelay(Type from, Type to)
        {
            this.From = from ?? throw new ArgumentNullException(nameof(from));
            this.To   = to ?? throw new ArgumentNullException(nameof(to));

            if (from.GetTypeInfo().IsGenericTypeDefinition ^ to.GetTypeInfo().IsGenericTypeDefinition)
            {
                throw new ArgumentException("Relaying from open generic type to open generic type " +
                                            "or from closed type to closed type are supported only.");
            }

            this.fromSpecification = new ExactTypeSpecification(from);
        }
コード例 #33
0
        public void FilterIsProperWritableProperty()
        {
            // Fixture setup
            var sut = new DelegatingTracingBuilder();
            IRequestSpecification expectedFilter = new DelegatingRequestSpecification();

            // Exercise system
            sut.Filter = expectedFilter;
            IRequestSpecification result = sut.Filter;

            // Verify outcome
            Assert.Equal(expectedFilter, result);
            // Teardown
        }
コード例 #34
0
        /// <summary>Initializes a new instance of the <see cref="NSubstituteBuilder"/> class with an
        ///     <see cref="ISpecimenBuilder"/> to decorate.</summary>
        /// <param name="builder">The builder which must build mock instances.</param>
        /// <param name="substitutionSpecification">A specification that determines whether a substitute should be created for a given request or not.</param>
        /// <remarks>
        ///     <para><paramref name="builder"/> is subsequently available through the <see cref="Builder"/> property.</para>
        ///     <para><paramref name="substitutionSpecification"/> is subsequently available through the <see cref="SubstitutionSpecification"/> property.</para>
        /// </remarks>
        /// <seealso cref="Builder"/>
        /// <seealso cref="SubstitutionSpecification"/>
        public NSubstituteBuilder(ISpecimenBuilder builder, IRequestSpecification substitutionSpecification)
        {
            if (builder == null)
            {
                throw new ArgumentNullException("builder");
            }
            if (substitutionSpecification == null)
            {
                throw new ArgumentNullException("substitutionSpecification");
            }

            this.builder = builder;
            this.substitutionSpecification = substitutionSpecification;
        }
コード例 #35
0
        public void SpecificationIsCorrect()
        {
            // Arrange
            var dummyBuilder = new DelegatingSpecimenBuilder();
            Action <object, ISpecimenContext> dummyAction = (s, c) => { };
            var expectedSpec = new DelegatingRequestSpecification();

            var sut = new Postprocessor <object>(dummyBuilder, dummyAction, expectedSpec);
            // Act
            IRequestSpecification result = sut.Specification;

            // Assert
            Assert.Equal(expectedSpec, result);
        }
 public RecordReplayConstructorSpecimensForTypeBuilder(ISpecimenBuilder builder, IRequestSpecification requestToRecordSpecification)
 {
     if (builder == null)
     {
         throw new ArgumentNullException("builder");
     }
     if (requestToRecordSpecification == null)
     {
         throw new ArgumentNullException("requestToRecordSpecification");
     }
     this.builder = builder;
     this.requestFilter = requestToRecordSpecification;
     this.recordedSpecimens = new List<object>();
 }
コード例 #37
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FilteringSpecimenBuilder"/> class.
        /// </summary>
        /// <param name="builder">A specimen builder to decorate.</param>
        /// <param name="specification">
        /// A specification that determines whether <paramref name="builder"/> will receive the request.
        /// </param>
        public FilteringSpecimenBuilder(ISpecimenBuilder builder, IRequestSpecification specification)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }        
            if (specification == null)
            {
                throw new ArgumentNullException(nameof(specification));
            }

            this.Builder = builder;
            this.Specification = specification;
        }
コード例 #38
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NoSpecimenOutputGuard"/> class with an
        /// <see cref="ISpecimenBuilder"/> to decorate and an <see cref="IRequestSpecification"/>
        /// that is used to determine whether an exception should be thrown based on the request.
        /// </summary>
        /// <param name="builder">The builder to decorate.</param>
        /// <param name="specification">The specification.</param>
        public NoSpecimenOutputGuard(ISpecimenBuilder builder, IRequestSpecification specification)
        {
            if (builder == null)
            {
                throw new ArgumentNullException("builder");
            }
            if (specification == null)
            {
                throw new ArgumentNullException("specification");
            }

            this.builder = builder;
            this.specification = specification;
        }
コード例 #39
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NoSpecimenOutputGuard"/> class with an
        /// <see cref="ISpecimenBuilder"/> to decorate and an <see cref="IRequestSpecification"/>
        /// that is used to determine whether an exception should be thrown based on the request.
        /// </summary>
        /// <param name="builder">The builder to decorate.</param>
        /// <param name="specification">The specification.</param>
        public NoSpecimenOutputGuard(ISpecimenBuilder builder, IRequestSpecification specification)
        {
            if (builder == null)
            {
                throw new ArgumentNullException("builder");
            }
            if (specification == null)
            {
                throw new ArgumentNullException("specification");
            }

            this.builder       = builder;
            this.specification = specification;
        }
コード例 #40
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FreezeOnMatchCustomization"/> class.
        /// </summary>
        /// <param name="targetType">The <see cref="Type"/> to freeze.</param>
        /// <param name="matcher">
        /// The <see cref="IRequestSpecification"/> used to match the requests
        /// that will be satisfied by the frozen specimen.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="targetType"/> or<paramref name="matcher"/> is null.
        /// </exception>
        public FreezeOnMatchCustomization(
            Type targetType,
            IRequestSpecification matcher)
        {
            if (targetType == null)
            {
                throw new ArgumentNullException("targetType");
            }

            if (matcher == null)
            {
                throw new ArgumentNullException("matcher");
            }

            this.targetType = targetType;
            this.matcher = matcher;
        }
コード例 #41
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TypedBuilderComposer"/> class.
        /// </summary>
        /// <param name="targetType">
        /// The <see cref="Type"/> targeted by the <see cref="ISpecimenBuilder"/> created by
        /// <see cref="Compose"/>.
        /// </param>
        /// <param name="factory">
        /// The factory that creates instances of <see cref="TargetType"/>.
        /// </param>
        public TypedBuilderComposer(Type targetType, ISpecimenBuilder factory)
        {
            if (targetType == null)
            {
                throw new ArgumentNullException("targetType");
            }
            if (factory == null)
            {
                throw new ArgumentNullException("factory");
            }

            this.targetType = targetType;
            this.factory = factory;

            this.inputFilter = new OrRequestSpecification(
                new SeedRequestSpecification(this.TargetType),
                new ExactTypeSpecification(this.TargetType));
        }
コード例 #42
0
            /// <summary>
            /// Initializes a new instance of the <see cref="DecorateWithInputFilterTransformation"/> class.
            /// </summary>
            /// <param name="inputFilter">The input filter.</param>
            public DecorateWithInputFilterTransformation(IRequestSpecification inputFilter)
            {
                if (inputFilter == null)
                {
                    throw new ArgumentNullException("inputFilter");
                }

                this.inputFilter = inputFilter;
            }
コード例 #43
0
        /// <summary>
        /// Creates new instance.
        /// </summary>
        public MutableValueTypeGenerator()
        {
            valueTypeWithoutConstructorsSpecification = new AndRequestSpecification(new ValueTypeSpecification(),
                                                                                    new NoConstructorsSpecification());

        }