public void ChangeAssessorTests_SubListPropertyValuesRemoved_SubListPropertySetAsRemoved() { var destination = MockDataHelper.BuildMultiLevelA("1"); destination.Cs = new System.Collections.Generic.List <MultiLevelC>() { MockDataHelper.BuildMultiLevelC("00"), MockDataHelper.BuildMultiLevelC("11"), MockDataHelper.BuildMultiLevelC("22") }; var source = Mapper.Map <MultiLevelA>(destination); //Note only one exists therefore 2 should be added source.Cs = new List <MultiLevelC>() { Mapper.Map <MultiLevelC>(source.Cs[1]) }; ChangeAssessor <string> changeAssessor = new ChangeAssessor <string>(); var assessment = changeAssessor.SetChangeStatus(source, destination); var expectedIndices = new[] { 0, 2 }; Assert.AreEqual(expectedIndices.Length, assessment.Relationships.Count, string.Format("Invalid change count, received {0}", assessment.OwnedEntities.Count)); foreach (var expectedIndex in expectedIndices) { var relationship = assessment.Relationships.FirstOrDefault(r => r.Value == destination.Cs[expectedIndex]); Assert.IsNotNull(relationship, string.Format("Record {0} should be in the list of changed relationships", expectedIndex)); Assert.AreEqual(relationship.Parent, source, "Proper parent should be assigned in the relationship " + expectedIndex); Assert.AreEqual(relationship.ChangeType, ChangeType.Deleted, "Change Type is set to Deleted " + expectedIndex); Assert.AreEqual(destination.Cs[expectedIndex].ChangeType, ChangeType.None, "Actual Entity type not changed due to lack of ownership " + expectedIndex); } }
public void ChangeAssessorTests_SubListPropertyValuesChanged_SubListPropertySetAsNoChange() { var source = MockDataHelper.BuildMultiLevelA("1"); source.Cs = new System.Collections.Generic.List <MultiLevelC>() { MockDataHelper.BuildMultiLevelC("11"), MockDataHelper.BuildMultiLevelC("22") }; var destination = Mapper.Map <MultiLevelA>(source); destination.Cs = source.Cs.Select(c => Mapper.Map <MultiLevelC>(c)).ToList(); ChangeAssessor <string> changeAssessor = new ChangeAssessor <string>(); var assessment = changeAssessor.SetChangeStatus(source, destination); Assert.AreEqual(assessment.OwnedEntities.Count, 0, string.Format("No changes expected, received {0}", assessment.OwnedEntities.Count)); Assert.AreEqual(source.Cs[0].ChangeType, ChangeType.None, "Change Type is set to None for C 0"); Assert.AreEqual(source.Cs[1].ChangeType, ChangeType.None, "Change Type is set to None for C 1"); }
public void ChangeAssessorTests_List_SubPropertyValuesAddDeletedAndUpdatedAndRootUpdated_SubPropertySetAsMixedStatuses() { var source = MockDataHelper.BuildMultiLevelA("123"); var destination = Mapper.Map <MultiLevelA>(source); source.Cs = new List <MultiLevelC>() { MockDataHelper.BuildMultiLevelC("-2124"), MockDataHelper.BuildMultiLevelC("1"), MockDataHelper.BuildMultiLevelC("5212") }; destination.Cs = new List <MultiLevelC>() { //Existing, unchanged Mapper.Map <MultiLevelC>(source.Cs[0]), //To Be updated MockDataHelper.BuildMultiLevelC("1"), //Note index 2 is not here and therefore added //Does not exist in source and therefore will be deleted MockDataHelper.BuildMultiLevelC("14wdwedqweqe") }; //The root is changed as well destination.StringField = Guid.NewGuid().ToString(); //Note out of order to ensure test covers other scenarios ChangeAssessor <string> changeAssessor = new ChangeAssessor <string>(); var assessment = changeAssessor.SetChangeStatus(source, destination); Assert.AreEqual(1, assessment.OwnedEntities.Count, string.Format("Invalid change count, received {0}", assessment.OwnedEntities.Count)); Assert.AreEqual(2, assessment.Relationships.Count, string.Format("Invalid change count, received {0}", assessment.OwnedEntities.Count)); Assert.IsTrue(assessment.OwnedEntities.Contains(source), "Root record should be in the list of changes"); Assert.AreEqual(ChangeType.Updated, source.ChangeType, string.Format("Record {0} should have the update change type", 2)); Assert.AreEqual(ChangeType.None, source.Cs[0].ChangeType, string.Format("Record {0} should have the none change type", 0)); Assert.AreEqual(ChangeType.None, source.Cs[1].ChangeType, string.Format("Record {0} should have the none change type as it is not owned", 1)); var relationshipS2 = assessment.Relationships.FirstOrDefault(r => r.Value == source.Cs[2]); Assert.IsNotNull(relationshipS2, "Record 2 should be in the list of changed relationships S2"); Assert.AreEqual(relationshipS2.Parent, source, "Proper parent should be assigned in the relationship S2"); Assert.AreEqual(relationshipS2.ChangeType, ChangeType.Added, "Change Type is set to Added S2"); Assert.AreEqual(source.Cs[2].ChangeType, ChangeType.None, "Actual Entity type not changed due to lack of ownership S2"); var relationshipD2 = assessment.Relationships.FirstOrDefault(r => r.Value == destination.Cs[2]); Assert.IsNotNull(relationshipD2, "Record 2 should be in the list of changed relationships D2"); Assert.AreEqual(relationshipD2.Parent, source, "Proper parent should be assigned in the relationship D2"); Assert.AreEqual(relationshipD2.ChangeType, ChangeType.Deleted, "Change Type is set to Deleted D2"); Assert.AreEqual(destination.Cs[2].ChangeType, ChangeType.None, "Actual Entity type not changed due to lack of ownership D2"); }
public void ChangeAssessorTests_List_SubPropertyValuesAddDeletedAndUpdatedAndRootUpdated_IsOwner_SubPropertySetAsMixedStatuses() { var source = MockDataHelper.BuildMultiLevelA("123"); var destination = Mapper.Map <MultiLevelA>(source); source.Cs = new List <MultiLevelC>() { MockDataHelper.BuildMultiLevelC("-2124"), MockDataHelper.BuildMultiLevelC("1"), MockDataHelper.BuildMultiLevelC("5212") }; destination.Cs = new List <MultiLevelC>() { //Existing, unchanged Mapper.Map <MultiLevelC>(source.Cs[0]), //To Be updated MockDataHelper.BuildMultiLevelC("1"), //Note index 2 is not here and therefore added //Does not exist in source and therefore will be deleted MockDataHelper.BuildMultiLevelC("14wdwedqweqe") }; //The root is changed as well destination.StringField = Guid.NewGuid().ToString(); //Note out of order to ensure test covers other scenarios ChangeAssessor <string> changeAssessor = new ChangeAssessor <string>() //Adding Ownershio .AddOwnerMapping <MultiLevelA>(c => c.Cs); var assessment = changeAssessor.SetChangeStatus(source, destination); Assert.AreEqual(4, assessment.OwnedEntities.Count, string.Format("Invalid change count, received {0}", assessment.OwnedEntities.Count)); Assert.IsTrue(assessment.OwnedEntities.Contains(source), "Root record should be in the list of changes"); Assert.AreEqual(ChangeType.Updated, source.ChangeType, string.Format("Record {0} should have the update change type", 2)); Assert.AreEqual(ChangeType.None, source.Cs[0].ChangeType, string.Format("Record {0} should have the none change type", 0)); Assert.IsTrue(assessment.OwnedEntities.Contains(source.Cs[1]), string.Format("Record {0} should be in the list of changes", 1)); Assert.AreEqual(ChangeType.Updated, source.Cs[1].ChangeType, string.Format("Record {0} should have the updated change type", 1)); Assert.IsTrue(assessment.OwnedEntities.Contains(source.Cs[2]), string.Format("Record {0} should be in the list of changes", 2)); Assert.AreEqual(ChangeType.Added, source.Cs[2].ChangeType, string.Format("Record {0} should have the added change type", 2)); Assert.IsTrue(assessment.OwnedEntities.Contains(destination.Cs[2]), string.Format("Record {0} should be in the list of changes", 2)); Assert.AreEqual(ChangeType.Deleted, destination.Cs[2].ChangeType, string.Format("Record {0} should have the removed change type", 2)); }