public void ChangeAssessorTests_IgnoreFieldNameSet_ChangesAreNotDetectedForFieldsSet()
        {
            //Note I am using sub properties to ensure the name is ignored in both levels of different types
            var source = MockDataHelper.BuildMultiLevelA("1");

            source.B = MockDataHelper.BuildMultiLevelB("23145");
            var destination = Mapper.Map <MultiLevelA>(source);

            destination.B = Mapper.Map <MultiLevelB>(source.B);


            //Change  StringField, and Int32
            source.StringField   = Guid.NewGuid().ToString();
            source.Int32Field   += 2000;
            source.B.StringField = Guid.NewGuid().ToString();
            source.B.Int32Field += 1000;

            ChangeAssessor <string> changeAssessor = new ChangeAssessor <string>()
                                                     //Ignoring both fields
                                                     .IgnoreFields("StringField", "Int32Field");

            var assessment = changeAssessor.SetChangeStatus(source, destination);

            Assert.AreEqual(assessment.OwnedEntities.Count, 0, "No changes should be found as the changed fields should be ignored");
        }
示例#2
0
        public void ChangeAssessorTests_SubPropertyAdded_IsOwner_SubPropertySetAsAdded()
        {
            var source      = MockDataHelper.BuildMultiLevelA("1");
            var destination = Mapper.Map <MultiLevelA>(source);

            //Note source will now have a sub single property
            //This is new and not in the destiation
            source.B = MockDataHelper.BuildMultiLevelB("23145");


            ChangeAssessor <string> changeAssessor = new ChangeAssessor <string>()
                                                     //Note owner addition
                                                     .AddOwnerMapping <MultiLevelA>(a => a.B)
            ;

            var assessment = changeAssessor.SetChangeStatus(source, destination);


            Assert.AreEqual(assessment.OwnedEntities.Count, 1, string.Format("One and only one change is expected, received {0}", assessment.OwnedEntities.Count));
            Assert.AreEqual(source.B, assessment.OwnedEntities[0], "Source record returned as Added");
            Assert.AreEqual(source.B.ChangeType, ChangeType.Added, "Change Type is set to Added");

            //relationships
            Assert.AreEqual(assessment.Relationships.Count, 1, string.Format("One and only one change is expected, received {0}", assessment.OwnedEntities.Count));
            Assert.AreEqual(source.B, assessment.Relationships[0].Value, "Source record returned as in relationship changes");
            Assert.AreEqual(assessment.Relationships[0].Parent, source, "Proper parent should be assigned in the relationship");
            Assert.AreEqual(assessment.Relationships[0].ChangeType, ChangeType.Added, "Change Type is set to Added");
        }
示例#3
0
        public void ChangeAssessorTests_SubPropertyValuesIdDifferent_SubPropertySetWithAnAddAndARemove()
        {
            var source      = MockDataHelper.BuildMultiLevelA("123");
            var destination = Mapper.Map <MultiLevelA>(source);

            //Different ids
            source.B         = MockDataHelper.BuildMultiLevelB("1");
            destination.B    = Mapper.Map <MultiLevelB>(source.B);
            destination.B.Id = "SOmething different";

            ChangeAssessor <string> changeAssessor = new ChangeAssessor <string>();

            var assessment = changeAssessor.SetChangeStatus(source, destination);

            Assert.AreEqual(0, 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));

            var relationshipDeleted = assessment.Relationships.FirstOrDefault(f => f.Value == destination.B);

            Assert.IsNotNull(relationshipDeleted, "Destination should be in the list of changed relationships");
            Assert.AreEqual(relationshipDeleted.Parent, source, "Proper parent should be assigned in the relationship ");
            Assert.AreEqual(relationshipDeleted.ChangeType, ChangeType.Deleted, "Change Type is set to Added ");


            var relationshipAdded = assessment.Relationships.FirstOrDefault(f => f.Value == source.B);

            Assert.IsNotNull(relationshipAdded, "Destination should be in the list of changed relationships");
            Assert.AreEqual(relationshipAdded.Parent, source, "Proper parent should be assigned in the relationship ");
            Assert.AreEqual(relationshipAdded.ChangeType, ChangeType.Added, "Change Type is set to Added ");
        }
        public void ChangeAssessorTests_ChangeTypeChanged_NoChangesShouldBePresentedAsThisFieldIsIgnored()
        {
            //Note I am using sub properties to ensure the name is ignored in both levels of different types
            var source = MockDataHelper.BuildMultiLevelA("1");

            source.B = MockDataHelper.BuildMultiLevelB("23145");
            var destination = Mapper.Map <MultiLevelA>(source);

            destination.B = Mapper.Map <MultiLevelB>(source.B);


            //Ensure statuses are different
            source.ChangeType      = ChangeType.Updated;
            destination.ChangeType = ChangeType.Added;

            source.B.ChangeType      = ChangeType.None;
            destination.B.ChangeType = ChangeType.Deleted;


            ChangeAssessor <string> changeAssessor = new ChangeAssessor <string>();

            var assessment = changeAssessor.SetChangeStatus(source, destination);

            Assert.AreEqual(assessment.OwnedEntities.Count, 0, "No changes should be found as the changed fields should be ignored");
        }
示例#5
0
        public void ChangeAssessorTests_SubListPropertyValuesAddDeletedAndUpdated_IsOwner_SubListPropertySetAsMixedStatuses()
        {
            var source      = MockDataHelper.BuildMultiLevelA("123");
            var destination = Mapper.Map <MultiLevelA>(source);

            source.B      = MockDataHelper.BuildMultiLevelB("5523");
            destination.B = MockDataHelper.BuildMultiLevelB("5523");
            //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>()
                                                     //Note ownership
                                                     .AddOwnerMapping <MultiLevelA>(a => a.B);

            var assessment = changeAssessor.SetChangeStatus(source, destination);


            Assert.AreEqual(2, 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.IsTrue(assessment.OwnedEntities.Contains(source.B), "Sub record should be in the list of changes");
            Assert.AreEqual(ChangeType.Updated, source.B.ChangeType, string.Format("Record {0} should have the update change type", 2));
        }
        public void ChangeAssessorTests_SubPropertyRemoved_IsOwner_SubPropertySetAsRemoved()
        {
            var source      = MockDataHelper.BuildMultiLevelA("1");
            var destination = Mapper.Map <MultiLevelA>(source);

            //Note source will now have a sub single property
            //This is removed and not in the source
            destination.B = MockDataHelper.BuildMultiLevelB("23145");

            ChangeAssessor <string> changeAssessor = new ChangeAssessor <string>()
                                                     //Note ownership assignment
                                                     .AddOwnerMapping <MultiLevelA>(a => a.B);

            var assessment = changeAssessor.SetChangeStatus(source, destination);

            Assert.AreEqual(assessment.OwnedEntities.Count, 1, string.Format("One and only one change is expected, received {0}", assessment.OwnedEntities.Count));
            Assert.AreEqual(destination.B, assessment.OwnedEntities[0], "Destination record returned as Deleted");
            Assert.AreEqual(ChangeType.Deleted, destination.B.ChangeType, "Change Type is set to Deleted");

            //Relationships
            Assert.AreEqual(assessment.Relationships.Count, 1, string.Format("One and only one change is expected, received {0}", assessment.OwnedEntities.Count));

            var relationship = assessment.Relationships.FirstOrDefault(r => r.Value == destination.B);

            Assert.IsNotNull(relationship, "Record {0} should be in the list of changed relationships");
            Assert.AreEqual(relationship.Parent, source, "Proper parent should be assigned in the relationship");
            Assert.AreEqual(relationship.ChangeType, ChangeType.Deleted, "Change Type is set to Deleted");
        }
示例#7
0
        public void ChangeAssessorTests_SubPropertyValuesChanged_SubPropertySetAsNoChange()
        {
            var source = MockDataHelper.BuildMultiLevelA("1");

            source.B = MockDataHelper.BuildMultiLevelB("2");
            var destination = Mapper.Map <MultiLevelA>(source);

            destination.B = Mapper.Map <MultiLevelB>(source.B);


            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.B.ChangeType, ChangeType.None, "Change Type is set to None");
        }
示例#8
0
        public void ChangeAssessorTests_SubPropertyValuesChanged_IsOwner_SubPropertySetAsUpdated()
        {
            var source = MockDataHelper.BuildMultiLevelA("1");

            source.B = MockDataHelper.BuildMultiLevelB("2");
            var destination = Mapper.Map <MultiLevelA>(source);

            destination.B = Mapper.Map <MultiLevelB>(source.B);

            source.B.StringField = "I am changed";

            ChangeAssessor <string> changeAssessor = new ChangeAssessor <string>()
                                                     //Note Ownership
                                                     .AddOwnerMapping <MultiLevelA>(a => a.B);

            var assessment = changeAssessor.SetChangeStatus(source, destination);


            Assert.AreEqual(assessment.OwnedEntities.Count, 1, string.Format("One and only one change is expected, received {0}", assessment.OwnedEntities.Count));
            Assert.AreEqual(source.B, assessment.OwnedEntities[0], "Source record returned as changed");
            Assert.AreEqual(source.B.ChangeType, ChangeType.Updated, "Change Type is set to updated");
        }
示例#9
0
        public void ChangeAssessorTests_CirclerReferenceSubProperty_NoStackOverflow()
        {
            var source = MockDataHelper.BuildMultiLevelA("5213123");

            source.B   = MockDataHelper.BuildMultiLevelB("1");
            source.B.A = source;
            var destination = Mapper.Map <MultiLevelA>(source);

            destination.B   = MockDataHelper.BuildMultiLevelB("1");
            destination.B.A = destination;

            //Note change results dont matter for this test, just ensure the results return. Amount checked just for
            //Some kind of assertion

            ChangeAssessor <string> changeAssessor = new ChangeAssessor <string>()
                                                     //Circular ownership
                                                     .AddOwnerMapping <MultiLevelA>(c => c.B)
                                                     .AddOwnerMapping <MultiLevelB>(c => c.A);

            var assessment = changeAssessor.SetChangeStatus(source, destination);

            //1 updates
            Assert.AreEqual(1, assessment.OwnedEntities.Count, string.Format("Invalid change count, received {0}", assessment.OwnedEntities.Count));
        }