예제 #1
0
        public void GetOrderedPropertiesReturnsCachedValueWhenCacheEnabled(CacheLevel cacheLevel)
        {
            var configuration = Substitute.For <IBuildConfiguration>();
            var type          = typeof(SlimModel);

            var sut = new DefaultPropertyResolver(cacheLevel);

            var first  = sut.GetOrderedProperties(configuration, type);
            var second = sut.GetOrderedProperties(configuration, type);

            first.Should().BeSameAs(second);
        }
예제 #2
0
        public void GetOrderedPropertiesReturnsNewInstanceWhenCacheDisabled()
        {
            var configuration = Substitute.For <IBuildConfiguration>();
            var type          = typeof(Person);

            var sut = new DefaultPropertyResolver(CacheLevel.None);

            var first  = sut.GetOrderedProperties(configuration, type).ToList();
            var second = sut.GetOrderedProperties(configuration, type).ToList();

            first.Should().NotBeSameAs(second);
            first.Should().BeEquivalentTo(second);
        }
예제 #3
0
        public void GetOrderedPropertiesThrowsExceptionWithNullTargetType()
        {
            var configuration = Substitute.For <IBuildConfiguration>();

            var sut = new DefaultPropertyResolver(CacheLevel.PerInstance);

            Action action = () => sut.GetOrderedProperties(configuration, null !);

            action.Should().Throw <ArgumentNullException>();
        }
예제 #4
0
        public void GetOrderedPropertiesDoesNotReturnStaticSetterProperty()
        {
            var configuration = Substitute.For <IBuildConfiguration>();
            var type          = typeof(StaticSetter);

            var sut = new DefaultPropertyResolver(CacheLevel.PerInstance);

            var actual = sut.GetOrderedProperties(configuration, type);

            actual.Should().NotContain(x => x.Name == nameof(StaticSetter.Person));
        }
예제 #5
0
        public void GetOrderedPropertiesDoesNotReturnsReadOnlyValueTypeProperty()
        {
            var configuration = Substitute.For <IBuildConfiguration>();
            var type          = typeof(PrivateValue);

            var sut = new DefaultPropertyResolver(CacheLevel.PerInstance);

            var actual = sut.GetOrderedProperties(configuration, type);

            actual.Should().NotContain(x => x.Name == nameof(PrivateValue.Id));
        }
예제 #6
0
        public void GetOrderedPropertiesReturnsReadOnlyReferenceTypeProperty()
        {
            var configuration = Substitute.For <IBuildConfiguration>();
            var type          = typeof(ReadOnlyParent);

            var sut = new DefaultPropertyResolver(CacheLevel.PerInstance);

            var actual = sut.GetOrderedProperties(configuration, type);

            actual.Should().Contain(x => x.Name == nameof(ReadOnlyParent.Company));
        }
예제 #7
0
        public void GetOrderedPropertiesReturnsPublicSetterProperty()
        {
            var configuration = Substitute.For <IBuildConfiguration>();
            var type          = typeof(Address);

            var sut = new DefaultPropertyResolver(CacheLevel.PerInstance);

            var actual = sut.GetOrderedProperties(configuration, type);

            actual.Should().Contain(x => x.Name == nameof(Address.AddressLine1));
        }
예제 #8
0
        public void GetOrderedPropertiesReturnsPropertiesWhenExecuteOrderRulesIsNull()
        {
            var configuration = Substitute.For <IBuildConfiguration>();
            var type          = typeof(EmailParts);

            configuration.ExecuteOrderRules.Returns((ICollection <IExecuteOrderRule>)null !);

            var sut = new DefaultPropertyResolver(CacheLevel.PerInstance);

            var actual = sut.GetOrderedProperties(configuration, type).ToList();

            actual.Should().HaveCount(4);
        }
예제 #9
0
        public void GetOrderedPropertiesReturnsPropertiesInDescendingOrder()
        {
            var configuration = new BuildConfiguration()
                                .AddExecuteOrderRule <EmailParts>(x => x.FirstName, 40)
                                .AddExecuteOrderRule <EmailParts>(x => x.LastName, 30)
                                .AddExecuteOrderRule <EmailParts>(x => x.Domain, 20)
                                .AddExecuteOrderRule <EmailParts>(x => x.Email, 10);
            var type = typeof(EmailParts);

            var sut = new DefaultPropertyResolver(CacheLevel.None);

            var actual = sut.GetOrderedProperties(configuration, type).ToList();

            actual[0].Name.Should().Be(nameof(EmailParts.FirstName));
            actual[1].Name.Should().Be(nameof(EmailParts.LastName));
            actual[2].Name.Should().Be(nameof(EmailParts.Domain));
            actual[3].Name.Should().Be(nameof(EmailParts.Email));
        }