예제 #1
0
 public void SutIsSpecimenBuilder()
 {
     // Fixture setup
     // Exercise system
     var sut = new EnumGenerator();
     // Verify outcome
     Assert.IsAssignableFrom<ISpecimenBuilder>(sut);
     // Teardown
 }
예제 #2
0
 public void RequestForEnumTypeReturnsCorrectResult(Type enumType, int requestCount, object expectedResult)
 {
     // Fixture setup
     var sut = new EnumGenerator();
     // Exercise system
     var dummyContext = new DelegatingSpecimenContext();
     var result = Enumerable.Repeat<Func<object>>(() => sut.Create(enumType, dummyContext), requestCount).Select(f => f()).Last();
     // Verify outcome
     Assert.Equal(expectedResult, result);
     // Teardown
 }
예제 #3
0
 public void RequestNonEnumReturnsCorrectResult(object request)
 {
     // Fixture setup
     var sut = new EnumGenerator();
     // Exercise system
     var dummyContext = new DelegatingSpecimenContext();
     var result = sut.Create(request, dummyContext);
     // Verify outcome
     var expectedResult = new NoSpecimen(request);
     Assert.Equal(expectedResult, result);
     // Teardown
 }
예제 #4
0
        /// <summary>
        /// Creates a new enum value based on a request.
        /// </summary>
        /// <param name="request">The request that describes what to create.</param>
        /// <param name="context">
        /// A context that can be used to create other specimens. Not used.
        /// </param>
        /// <returns>
        /// An enum value if appropriate; otherwise a <see cref="NoSpecimen"/> instance.
        /// </returns>
        /// <remarks>
        /// <para>
        /// If <paramref name="request"/> is a <see cref="Type"/> that represents an enum, an
        /// instance of that enum is returned. Differing values are returned, starting with the
        /// first value. When all values of the enum type have been served, the sequence starts
        /// over again.
        /// </para>
        /// </remarks>
        public object Create(object request, ISpecimenContext context)
        {
            var t = request as Type;

            if (!EnumGenerator.IsEnumType(t))
            {
                return(new NoSpecimen(request));
            }

            lock (this.syncRoot)
            {
                return(this.CreateValue(t));
            }
        }
예제 #5
0
        public void SutCanCorrectlyInterleaveDifferentEnumTypes(Type enumType, object expectedResult)
        {
            // Fixture setup
            var sut = new EnumGenerator();
            var dummyContext = new DelegatingSpecimenContext();

            sut.Create(typeof(TriState), dummyContext);
            sut.Create(typeof(TriState), dummyContext);
            sut.Create(typeof(DayOfWeek), dummyContext);
            // Exercise system
            var result = sut.Create(enumType, dummyContext);
            // Verify outcome
            Assert.Equal(expectedResult, result);
            // Teardown
        }
예제 #6
0
        /// <summary>
        /// Creates a new enum value based on a request.
        /// </summary>
        /// <param name="request">The request that describes what to create.</param>
        /// <param name="context">
        /// A context that can be used to create other specimens. Not used.
        /// </param>
        /// <returns>
        /// An enum value if appropriate; otherwise a <see cref="NoSpecimen"/> instance.
        /// </returns>
        /// <remarks>
        /// <para>
        /// If <paramref name="request"/> is a <see cref="Type"/> that represents an enum, an
        /// instance of that enum is returned. Differing values are returned, starting with the
        /// first value. When all values of the enum type have been served, the sequence starts
        /// over again.
        /// </para>
        /// </remarks>
        public object Create(object request, ISpecimenContext context)
        {
            var t = request as Type;

            if (!EnumGenerator.IsEnumType(t))
            {
#pragma warning disable 618
                return(new NoSpecimen(request));

#pragma warning restore 618
            }

            lock (this.syncRoot)
            {
                return(this.CreateValue(t));
            }
        }
예제 #7
0
 public void RequestForEnumWithNoValuesThrowsObjectCreationException()
 {
     // Fixture setup
     var sut = new EnumGenerator();
     // Exercise system and Verify outcome
     var dummyContext = new DelegatingSpecimenContext();
     Assert.Throws<ObjectCreationException>(() => sut.Create(typeof (EmptyEnum), dummyContext));
     // Teardown
 }