public void SutIsSpecimenBuilder() { // Fixture setup // Exercise system var sut = new EnumGenerator(); // Verify outcome Assert.IsAssignableFrom<ISpecimenBuilder>(sut); // Teardown }
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 }
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 }
/// <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)); } }
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 }
/// <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)); } }
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 }