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); }
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); }
public void GetOrderedPropertiesThrowsExceptionWithNullTargetType() { var configuration = Substitute.For <IBuildConfiguration>(); var sut = new DefaultPropertyResolver(CacheLevel.PerInstance); Action action = () => sut.GetOrderedProperties(configuration, null !); action.Should().Throw <ArgumentNullException>(); }
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)); }
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)); }
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)); }
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)); }
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); }
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)); }