public void CanCorrectlyInterleaveDifferentEnumTypes(Type enumType, string expectedResult)
        {
            // Arrange
            var enumDataTypeAttribute = new EnumDataTypeAttribute(enumType);
            var providedAttribute     = new ProvidedAttribute(enumDataTypeAttribute, true);
            var request      = new FakeMemberInfo(providedAttribute);
            var dummyContext = new DelegatingSpecimenContext();

            var sut = new EnumDataTypeAttributeRelay
            {
                RequestMemberTypeResolver = new DelegatingRequestMemberTypeResolver
                {
                    OnTryGetMemberType = _ => typeof(string)
                }
            };

            var triStateEnumDataTypeAttribute  = new EnumDataTypeAttribute(typeof(TriState));
            var triStateProvidedAttribute      = new ProvidedAttribute(triStateEnumDataTypeAttribute, true);
            var dayOfWeekEnumDataTypeAttribute = new EnumDataTypeAttribute(typeof(DayOfWeek));
            var dayOfWeekProvidedAttribute     = new ProvidedAttribute(dayOfWeekEnumDataTypeAttribute, true);

            sut.Create(new FakeMemberInfo(triStateProvidedAttribute), dummyContext);
            sut.Create(new FakeMemberInfo(triStateProvidedAttribute), dummyContext);
            sut.Create(new FakeMemberInfo(dayOfWeekProvidedAttribute), dummyContext);

            // Act
            var result = sut.Create(request, dummyContext);

            // Assert
            Assert.Equal(expectedResult, result);
        }
        public void RequestForEnumTypeReturnsResultAsString(
            Type enumType, int requestCount, string expectedResult)
        {
            // Arrange
            var enumDataTypeAttribute = new EnumDataTypeAttribute(enumType);
            var providedAttribute     = new ProvidedAttribute(enumDataTypeAttribute, true);
            var request      = new FakeMemberInfo(providedAttribute);
            var dummyContext = new DelegatingSpecimenContext();

            var sut = new EnumDataTypeAttributeRelay
            {
                RequestMemberTypeResolver = new DelegatingRequestMemberTypeResolver
                {
                    OnTryGetMemberType = _ => typeof(string)
                }
            };

            // Act
            var result = Enumerable
                         .Repeat <Func <object> >(() => sut.Create(request, dummyContext), requestCount)
                         .Select(f => f()).ToArray().Last();

            // Assert
            Assert.Equal(expectedResult, result);
        }
        public void SutIsSpecimenBuilder()
        {
            // Arrange
            var sut = new EnumDataTypeAttributeRelay();

            // Act & assert
            Assert.IsAssignableFrom <ISpecimenBuilder>(sut);
        }
        public void CreateWithUnsupportedRequestReturnsNoSpecimen(object request)
        {
            // Arrange
            var sut          = new EnumDataTypeAttributeRelay();
            var dummyContext = new DelegatingSpecimenContext();

            // Act
            var result = sut.Create(request, dummyContext);

            // Assert
            Assert.IsType <NoSpecimen>(result);
        }
        public void CreateWithAnonymousRequestReturnsNoSpecimen()
        {
            // Arrange
            var sut            = new EnumDataTypeAttributeRelay();
            var dummyRequest   = new object();
            var dummyContainer = new DelegatingSpecimenContext();

            // Act
            var result = sut.Create(dummyRequest, dummyContainer);

            // Assert
            Assert.IsType <NoSpecimen>(result);
        }
        public void ReturnsNoSpecimenWhenEnumGeneratorReturnsNoSpecimen(Type enumType)
        {
            // Arrange
            var enumDataTypeAttribute = new EnumDataTypeAttribute(enumType);
            var providedAttribute     = new ProvidedAttribute(enumDataTypeAttribute, true);
            var request       = new FakeMemberInfo(providedAttribute);
            var enumGenerator = new DelegatingSpecimenBuilder
            {
                OnCreate = (_, _) => new NoSpecimen()
            };
            var sut = new EnumDataTypeAttributeRelay(enumGenerator);

            // Act
            var actual = sut.Create(request, null);

            // Assert
            Assert.IsType <NoSpecimen>(actual);
        }
        public void RequestForEnumWithNoValuesThrows()
        {
            // Arrange
            var enumDataTypeAttribute = new EnumDataTypeAttribute(typeof(EmptyEnum));
            var providedAttribute     = new ProvidedAttribute(enumDataTypeAttribute, true);
            var request      = new FakeMemberInfo(providedAttribute);
            var dummyContext = new DelegatingSpecimenContext();

            var sut = new EnumDataTypeAttributeRelay
            {
                RequestMemberTypeResolver = new DelegatingRequestMemberTypeResolver
                {
                    OnTryGetMemberType = _ => typeof(string)
                }
            };

            // Act & assert
            Assert.Throws <ObjectCreationException>(() => sut.Create(request, dummyContext));
        }
        public void ReturnsNoSpecimenWhenResolverReturnsNoSpecimen(Type enumType)
        {
            // Arrange
            var enumDataTypeAttribute = new EnumDataTypeAttribute(enumType);
            var providedAttribute     = new ProvidedAttribute(enumDataTypeAttribute, true);
            var request = new FakeMemberInfo(providedAttribute);
            var sut     = new EnumDataTypeAttributeRelay
            {
                RequestMemberTypeResolver = new DelegatingRequestMemberTypeResolver
                {
                    OnTryGetMemberType = _ => null
                }
            };

            // Act
            var actual = sut.Create(request, null);

            // Assert
            Assert.IsType <NoSpecimen>(actual);
        }
        public void ReturnsNoSpecimenResultForCustomClassMemberType(Type enumType, Type memberType)
        {
            // Arrange
            var enumDataTypeAttribute = new EnumDataTypeAttribute(enumType);
            var providedAttribute     = new ProvidedAttribute(enumDataTypeAttribute, true);
            var request      = new FakeMemberInfo(providedAttribute);
            var dummyContext = new DelegatingSpecimenContext();

            var sut = new EnumDataTypeAttributeRelay
            {
                RequestMemberTypeResolver = new DelegatingRequestMemberTypeResolver
                {
                    OnTryGetMemberType = _ => memberType
                }
            };

            // Act
            var actual = sut.Create(request, dummyContext);

            // Assert
            Assert.IsType <NoSpecimen>(actual);
        }
        public void RequestReturnsExpectedResultForEnumMemberType(Type enumType, Type memberType, object expectedResult)
        {
            // Arrange
            var enumDataTypeAttribute = new EnumDataTypeAttribute(enumType);
            var providedAttribute     = new ProvidedAttribute(enumDataTypeAttribute, true);
            var request      = new FakeMemberInfo(providedAttribute);
            var dummyContext = new DelegatingSpecimenContext();

            var sut = new EnumDataTypeAttributeRelay
            {
                RequestMemberTypeResolver = new DelegatingRequestMemberTypeResolver
                {
                    OnTryGetMemberType = _ => memberType
                }
            };

            // Act
            var actual = sut.Create(request, dummyContext);

            // Assert
            Assert.Equal(expectedResult, actual);
        }
        public void RequestReturnsCorrectTypeForDifferentMemberTypes(
            Type enumType, Type memberType)
        {
            // Arrange
            var enumDataTypeAttribute = new EnumDataTypeAttribute(enumType);
            var providedAttribute     = new ProvidedAttribute(enumDataTypeAttribute, true);
            var request      = new FakeMemberInfo(providedAttribute);
            var dummyContext = new DelegatingSpecimenContext();

            var sut = new EnumDataTypeAttributeRelay
            {
                RequestMemberTypeResolver = new DelegatingRequestMemberTypeResolver
                {
                    OnTryGetMemberType = _ => memberType
                }
            };

            // Act
            var result = sut.Create(request, dummyContext);

            // Assert
            Assert.IsType(memberType, result);
        }