public object Create(object request, ISpecimenContext context) { var speciment = _enumGenerator.Create(request, context); if (speciment.ToString() == "Unknown" || speciment.ToString() == "Uninitialized") { speciment = _enumGenerator.Create(request, context); } return(speciment); }
public void SutCanCorrectlyInterleaveDifferentEnumTypes(Type enumType, object expectedResult) { // Arrange var sut = new EnumGenerator(); var dummyContext = new DelegatingSpecimenContext(); sut.Create(typeof(TriState), dummyContext); sut.Create(typeof(TriState), dummyContext); sut.Create(typeof(DayOfWeek), dummyContext); // Act var result = sut.Create(enumType, dummyContext); // Assert Assert.Equal(expectedResult, result); }
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 }
public object Create(object request, ISpecimenContext context) { var enumType = request as Type; if (enumType == null || !enumType.IsEnum) { return(new NoSpecimen()); } var namesEnumerator = Enum.GetNames(enumType).GetEnumerator(); while (namesEnumerator.MoveNext()) { var specimen = _enumGenerator.Create(request, context); if (specimen.ToString() != "Unknown" && specimen.ToString() != "Uninitialized") { return(specimen); } } throw new ObjectCreationException( "AutoFixture was unable to create a value for " + enumType.FullName + " since it is an enum containing either no values or " + "ignored values only ('Unknown' and 'Uninitialized'). " + "Please add at least one valid value to the enum."); }
public void Enum_WhenCreatingEnumWithAttribute_ShouldGenerateCorrectCode() { Assert.AreEqual("[Test]enumMyEnum{MyValue,MyOtherValue}", EnumGenerator.Create("MyEnum", new List <EnumMember> { new EnumMember("MyValue"), new EnumMember("MyOtherValue") }, attributes: new List <Attribute> { new Attribute("Test") }).ToString()); }
public void Enum_WhenCreatingEnumWithModifiers_ShouldGenerateCorrectCode() { Assert.AreEqual("publicenumMyEnum{MyValue,MyOtherValue}", EnumGenerator.Create("MyEnum", new List <EnumMember> { new EnumMember("MyValue"), new EnumMember("MyOtherValue") }, modifiers: new List <Modifiers>() { Modifiers.Public }).ToString()); }
public void RequestForEnumWithNoValuesThrowsObjectCreationException() { // Arrange var sut = new EnumGenerator(); // Act & assert var dummyContext = new DelegatingSpecimenContext(); Assert.Throws <ObjectCreationException>(() => sut.Create(typeof(EmptyEnum), dummyContext)); }
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 }
public void RequestForFlagEnumTypeReturnsCorrectResult(Type enumType, int requestCount, object expectedResult) { // Arrange var sut = new EnumGenerator(); // Act var dummyContext = new DelegatingSpecimenContext(); var result = Enumerable.Repeat <Func <object> >(() => sut.Create(enumType, dummyContext), requestCount).Select(f => f()).ToArray().Last(); // Assert Assert.Equal(expectedResult, result); }
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) { // Arrange var sut = new EnumGenerator(); // Act var dummyContext = new DelegatingSpecimenContext(); var result = sut.Create(request, dummyContext); // Assert var expectedResult = new NoSpecimen(); Assert.Equal(expectedResult, result); }
public void Enum_WhenCreatingEnumWithValueOnMember_ShouldGenerateCorrectCode() { Assert.AreEqual("[Test]publicenumMyEnum{MyValue=2,MyOtherValue}", EnumGenerator.Create("MyEnum", new List <EnumMember> { new EnumMember("MyValue", 2), new EnumMember("MyOtherValue") }, new List <Modifiers>() { Modifiers.Public }, new List <Attribute> { new Attribute("Test") }).ToString()); }
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 }
public void Enum_WhenCreatingEnum_ShouldGenerateCorrectCode() { Assert.AreEqual("enumMyEnum{MyValue,MyOtherValue}", EnumGenerator.Create("MyEnum", new List <EnumMember> { new EnumMember("MyValue"), new EnumMember("MyOtherValue") }).ToString()); }
public SyntaxList <MemberDeclarationSyntax> AddMember(SyntaxList <MemberDeclarationSyntax> members) { return(members.Add(EnumGenerator.Create(_name, _members, _modifiers, _attributes))); }