public void SafeGet_UsingNestedEntityPropertyWithNull_Succeeds() { // Arrange. TestEntity subject = new TestEntity(); // Act. var result = EntityExtensions.NullSafeGet(subject, n => n.Property1.Property3.Length); // Assert. Assert.AreEqual(default(int), result); }
public void SafeGet_PassingNullAsExpression_ThrowsException() { // Arrange. TestEntity subject = new TestEntity() { Property1 = new TestEntityPropertyType() }; // Act. var result = NullSafeExpressionHandler.SafeGet<Entity, object>(subject, null); // Assert. }
public void SafeGet_UsingDirectValueTypeProperty_ReturnsPropertyValue() { // Arrange. TestEntity subject = new TestEntity() { Property2 = 123 }; // Act. var result = NullSafeExpressionHandler.SafeGet(subject, n => n.Property2); // Assert. Assert.IsNotNull(result); Assert.AreEqual(subject.Property2, result); }
public void SafeGet_UsingNestedNonNullEntityProperty_Succeeds() { // Arrange. TestEntity subject = new TestEntity() { Property1 = new TestEntityPropertyType() { Property3 = "abc" } }; // Act. var result = EntityExtensions.NullSafeGet(subject, n => n.Property1.Property3.Length); // Assert. Assert.AreEqual(subject.Property1.Property3.Length, result); }
public void SafeGet_UsingNestedProperty_ReturnsPropertyResult() { // Arrange. string stringValue = "Hello"; TestEntity subject = new TestEntity() { Property1 = new TestEntityPropertyType() { Property3 = stringValue } }; // Act. object result = NullSafeExpressionHandler.SafeGet(subject, n => n.Property1.Property3.Length); // Assert. Assert.IsNotNull(result); Assert.IsTrue(result is int); Assert.AreEqual(stringValue.Length, (int)result); }
public void SafeMapFrom_MapUsingSafeMapFrom_Succeeds() { // Arrange. TestEntity subject = new TestEntity() { Property1 = new TestEntityPropertyType() { Property3 = "abc" } }; TestEntity subject2 = new TestEntity(); Mapper.Reset(); // Act. Mapper.Initialize(n => n.AddProfile<TestAutoMapperProfile>()); Mapper.AssertConfigurationIsValid(); var result = Mapper.Map<TestEntity, TestEntity>(subject, subject2); // Assert. Assert.AreEqual(subject.Property1.Property3.Length, subject2.Property2); }
public void SafeGet_UsingNestedReferenceTypePropertyWithNullInChain_ReturnsNull() { // Arrange. TestEntity subject = new TestEntity(); // Act. object result = NullSafeExpressionHandler.SafeGet(subject, n => n.Property1.Property3); // Assert. Assert.AreEqual(result, null); }
public void SafeGet_UsingTwoDifferentObjectsAccessingEquallyNamedProperty_ReturnsCorrectPropertyValue() { // Arrange. TestEntity subject1 = new TestEntity() { Property1 = new TestEntityPropertyType() }; TestEntity2 subject2 = new TestEntity2() { Property1 = new TestEntityPropertyType() }; // Act. var result = NullSafeExpressionHandler.SafeGet(subject1, n => n.Property1); result = NullSafeExpressionHandler.SafeGet(subject2, n => n.Property1); // Assert. Assert.IsNotNull(result); Assert.AreEqual(subject2.Property1, result); }
public void SafeGet_UsingNestedValueTypePropertyWithNullInChain_ReturnsDefault() { // Arrange. TestEntity subject = new TestEntity(); // Act. object result = NullSafeExpressionHandler.SafeGet(subject, n => n.Property1.Property3.Length); // Assert. Assert.IsNotNull(result); Assert.AreEqual(result.GetType(), typeof(int)); Assert.AreEqual(result, default(int)); }