/// <summary>
        /// Creates an anonymous object, potentially using the supplied seed as additional
        /// information when creating the object.
        /// </summary>
        /// <typeparam name="T">The type of object to create.</typeparam>
        /// <param name="seed">
        /// Any data that adds additional information when creating the anonymous object.
        /// </param>
        /// <param name="composer">The composer used to resolve the type request.</param>
        /// <returns>An anonymous object.</returns>
        public static T CreateAnonymous <T>(this ISpecimenBuilderComposer composer, T seed)
        {
            if (composer == null)
            {
                throw new ArgumentNullException("composer");
            }

            return(composer.Compose().CreateContext().CreateAnonymous(seed));
        }
        /// <summary>
        /// Creates many anonymous objects.
        /// </summary>
        /// <typeparam name="T">The type of objects to create.</typeparam>
        /// <param name="composer">The composer used to resolve the type request.</param>
        /// <param name="seed">
        /// An initial value that may or may not be used as input for the algorithm creating the
        /// return value.
        /// </param>
        /// <param name="count">The number of objects to create.</param>
        /// <returns>A sequence of anonymous objects of type <typeparamref name="T"/>.</returns>
        /// <remarks>
        /// <para>
        /// The CreateMany implementation always returns a new instance of
        /// <see cref="IEnumerable{T}" />. Even if IEnumerable&lt;T&gt; is
        /// Frozen by the <see cref="FixtureFreezer.Freeze(IFixture)" /> method
        /// or explicitly assigned with the
        /// <see cref="FixtureRegistrar.Inject{T}(IFixture, T)" /> method, the
        /// CreateMany method returns a new, independent instance of
        /// IEnumerable&lt;T&gt;.
        /// </para>
        /// </remarks>
        public static IEnumerable <T> CreateMany <T>(this ISpecimenBuilderComposer composer, T seed, int count)
        {
            if (composer == null)
            {
                throw new ArgumentNullException("composer");
            }

            return(composer.Compose().CreateContext().CreateMany(seed, count));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="WritablePropertyAssertion"/> class.
        /// </summary>
        /// <param name="composer">
        /// A composer which can create instances required to implement the idiomatic unit test,
        /// such as the owner of the property, as well as the value to be assigned and read from
        /// the property.
        /// </param>
        /// <remarks>
        /// <para>
        /// <paramref name="composer" /> will typically be a <see cref="Fixture" /> instance.
        /// </para>
        /// </remarks>
        public WritablePropertyAssertion(ISpecimenBuilderComposer composer)
        {
            if (composer == null)
            {
                throw new ArgumentNullException("composer");
            }

            this.composer = composer;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="WritablePropertyAssertion"/> class.
        /// </summary>
        /// <param name="composer">
        /// A composer which can create instances required to implement the idiomatic unit test,
        /// such as the owner of the property, as well as the value to be assigned and read from
        /// the property.
        /// </param>
        /// <remarks>
        /// <para>
        /// <paramref name="composer" /> will typically be a <see cref="Fixture" /> instance.
        /// </para>
        /// </remarks>
        public WritablePropertyAssertion(ISpecimenBuilderComposer composer)
        {
            if (composer == null)
            {
                throw new ArgumentNullException("composer");
            }

            this.composer = composer;
        }
        public void ComposerIsCorrect()
        {
            // Fixture setup
            var expectedComposer = new Fixture();
            var sut = new WritablePropertyAssertion(expectedComposer);
            // Exercise system
            ISpecimenBuilderComposer result = sut.Composer;

            // Verify outcome
            Assert.Equal(expectedComposer, result);
            // Teardown
        }
示例#6
0
        public void ComposerIsCorrectFromGreedyConstructor()
        {
            // Fixture setup
            ISpecimenBuilderComposer expectedComposer = new Fixture();
            var dummyExpectation = new DelegatingBehaviorExpectation();
            var sut = new GuardClauseAssertion(expectedComposer, dummyExpectation);
            // Exercise system
            ISpecimenBuilderComposer result = sut.Composer;

            // Verify outcome
            Assert.Equal(expectedComposer, result);
            // Teardown
        }
        /// <summary>
        /// Invokes the supplied action with an anonymous parameter value.
        /// </summary>
        /// <typeparam name="T">The type of the anonymous parameter.</typeparam>
        /// <param name="composer">The composer.</param>
        /// <param name="action">The action to invoke.</param>
        public static void Do <T>(this ISpecimenBuilderComposer composer, Action <T> action)
        {
            if (composer == null)
            {
                throw new ArgumentNullException("composer");
            }
            if (action == null)
            {
                throw new ArgumentNullException("action");
            }

            T x = composer.CreateAnonymous <T>();

            action(x);
        }
        /// <summary>
        /// Invokes the supplied function with an anonymous parameter value and returns the result.
        /// </summary>
        /// <typeparam name="T">The type of the anonymous parameter.</typeparam>
        /// <typeparam name="TResult">The return type.</typeparam>
        /// <param name="composer">The composer.</param>
        /// <param name="function">The function to invoke.</param>
        /// <returns>The return value of <paramref name="function"/>.</returns>
        public static TResult Get <T, TResult>(this ISpecimenBuilderComposer composer, Func <T, TResult> function)
        {
            if (composer == null)
            {
                throw new ArgumentNullException("composer");
            }
            if (function == null)
            {
                throw new ArgumentNullException("function");
            }

            T x = composer.CreateAnonymous <T>();

            return(function(x));
        }
        public static void Do <T1, T2, T3>(this ISpecimenBuilderComposer composer, Action <T1, T2, T3> action)
        {
            if (composer == null)
            {
                throw new ArgumentNullException("composer");
            }
            if (action == null)
            {
                throw new ArgumentNullException("action");
            }

            T1 x1 = composer.CreateAnonymous <T1>();
            T2 x2 = composer.CreateAnonymous <T2>();
            T3 x3 = composer.CreateAnonymous <T3>();

            action(x1, x2, x3);
        }
        public static TResult Get <T1, T2, T3, TResult>(this ISpecimenBuilderComposer composer, Func <T1, T2, T3, TResult> function)
        {
            if (composer == null)
            {
                throw new ArgumentNullException("composer");
            }
            if (function == null)
            {
                throw new ArgumentNullException("function");
            }

            T1 x1 = composer.CreateAnonymous <T1>();
            T2 x2 = composer.CreateAnonymous <T2>();
            T3 x3 = composer.CreateAnonymous <T3>();

            return(function(x1, x2, x3));
        }
示例#11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Generator&lt;T&gt;"/> class.
 /// </summary>
 /// <param name="composer">A composer which is used to generate items.</param>
 public Generator(ISpecimenBuilderComposer composer)
 {
     this.composer = composer;
 }
 internal static object CreateAnonymous(this ISpecimenBuilderComposer composer, Type type)
 {
     return(composer.Compose().CreateContext().Resolve(type));
 }
 internal static object CreateAnonymous(this ISpecimenBuilderComposer composer, object request)
 {
     return(new SpecimenContext(composer.Compose()).Resolve(request));
 }
示例#14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GuardClauseAssertion"/> class.
 /// </summary>
 /// <param name="composer">
 /// A composer which can create instances required to implement the idiomatic unit test.
 /// </param>
 /// <param name="behaviorExpectation">
 /// A behavior expectation to override the default expectation.
 /// </param>
 /// <remarks>
 /// <para>
 /// <paramref name="composer" /> will typically be a <see cref="Fixture" /> instance.
 /// </para>
 /// </remarks>
 public GuardClauseAssertion(ISpecimenBuilderComposer composer, IBehaviorExpectation behaviorExpectation)
 {
     this.composer            = composer;
     this.behaviorExpectation = behaviorExpectation;
 }
示例#15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GuardClauseAssertion"/> class.
 /// </summary>
 /// <param name="composer">
 /// A composer which can create instances required to implement the idiomatic unit test.
 /// </param>
 /// <remarks>
 /// <para>
 /// <paramref name="composer" /> will typically be a <see cref="Fixture" /> instance.
 /// </para>
 /// </remarks>
 public GuardClauseAssertion(ISpecimenBuilderComposer composer)
     : this(composer, new CompositeBehaviorExpectation(
                new NullReferenceBehaviorExpectation(),
                new EmptyGuidBehaviorExpectation()))
 {
 }