Ejemplo n.º 1
0
        public void ChangeAssessorTests_List_RootValuesAdded_RootSetAsAdded()
        {
            var source = new List <OneLevel>()
            {
                MockDataHelper.BuildOneLevel("-2124"), MockDataHelper.BuildOneLevel("1"), MockDataHelper.BuildOneLevel("5212"), MockDataHelper.BuildOneLevel("561223")
            };
            //Note out of order to ensure test covers other scenarios
            var destination = new List <OneLevel>()
            {
                source[2]
            };
            ChangeAssessor <string> changeAssessor = new ChangeAssessor <string>();

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


            var expectedIndices = new[] { 0, 1, 3 };


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

            foreach (var expectedIndex in expectedIndices)
            {
                Assert.IsTrue(assessment.OwnedEntities.Contains(source[expectedIndex]), string.Format("Record {0} should be in the list of changes", expectedIndex));
                Assert.AreEqual(ChangeType.Added, source[expectedIndex].ChangeType, string.Format("Record {0} should have the added change type", expectedIndex));
            }
        }
Ejemplo n.º 2
0
        public void ChangeAssessorTests_ListDestinationNull_RootValuesAdded_RootSetAsAdded()
        {
            var source = new List <OneLevel>()
            {
                MockDataHelper.BuildOneLevel("-2124"), MockDataHelper.BuildOneLevel("1"), MockDataHelper.BuildOneLevel("5212"), MockDataHelper.BuildOneLevel("561223")
            };

            //note null
            List <OneLevel>         destination    = null;
            ChangeAssessor <string> changeAssessor = new ChangeAssessor <string>();

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


            var expectedIndices = Enumerable.Range(0, source.Count);


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

            foreach (var expectedIndex in expectedIndices)
            {
                Assert.IsTrue(assessment.OwnedEntities.Contains(source[expectedIndex]), string.Format("Record {0} should be in the list of changes", expectedIndex));
                Assert.AreEqual(ChangeType.Added, source[expectedIndex].ChangeType, string.Format("Record {0} should have the added change type", expectedIndex));
            }
        }
Ejemplo n.º 3
0
        public void ChangeAssessorTests_List_RootValuesNoChangeAndOutOfOrder_RootSetAsAdded()
        {
            var source = new List <OneLevel>()
            {
                MockDataHelper.BuildOneLevel("-2124"), MockDataHelper.BuildOneLevel("1"), MockDataHelper.BuildOneLevel("5212"), MockDataHelper.BuildOneLevel("561223")
            };
            //Note out of order to ensure test covers other scenarios
            var destination = new List <OneLevel>()
            {
                Mapper.Map <OneLevel>(source[2]),
                Mapper.Map <OneLevel>(source[1]),
                Mapper.Map <OneLevel>(source[0]),
                Mapper.Map <OneLevel>(source[3])
            };


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

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



            Assert.AreEqual(0, assessment.OwnedEntities.Count, string.Format("No changes expected, received {0}", assessment.OwnedEntities.Count));

            foreach (var sourceItem in source)
            {
                Assert.AreEqual(ChangeType.None, sourceItem.ChangeType, string.Format("Record {0} should have the none change type", sourceItem.Id));
            }
        }
Ejemplo n.º 4
0
        public void ChangeAssessorTests_RootValuesChanged_RootSetAsNoChange()
        {
            //Note both should be randomly generated but have the same ID
            var source      = MockDataHelper.BuildOneLevel("1");
            var destination = Mapper.Map <OneLevel>(source);
            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.ChangeType, ChangeType.None, "Change Type is set to NoChange");
        }
Ejemplo n.º 5
0
        public void ChangeAssessorTests_RootValuesChanged_RootSetAsUpdated()
        {
            //Note both should be randomly generated but have the same ID
            var source      = MockDataHelper.BuildOneLevel("1");
            var destination = MockDataHelper.BuildOneLevel("1");
            ChangeAssessor <string> changeAssessor = new ChangeAssessor <string>();

            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));
            Assert.AreEqual(source, assessment.OwnedEntities[0], "Source record returned as changed");
            Assert.AreEqual(source.ChangeType, ChangeType.Updated, "Change Type is set to updated");
        }
        public void ChangeAssessorTests_IgnoreInterfaceSet_ChangesAreNotDetectedForInterfaceFields()
        {
            var source      = MockDataHelper.BuildOneLevel("1");
            var destination = Mapper.Map <OneLevel>(source);
            ChangeAssessor <string> changeAssessor = new ChangeAssessor <string>()
                                                     //Note ignoring the whole interface
                                                     .IgnoreFields <InterfaceToIgnore>();

            //Only change fields from interface cast for test safety
            var sourceCastToInterface = (InterfaceToIgnore)source;

            sourceCastToInterface.BooleanField = !sourceCastToInterface.BooleanField;
            sourceCastToInterface.Int32Field  += 100;


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

            Assert.AreEqual(assessment.OwnedEntities.Count, 0, "No changes should be found as the changed fields should be ignored");
        }
Ejemplo n.º 7
0
        public void ChangeAssessorTests_List_RootValuesAddDeletedAndUpdated_RootSetAsMixedStatuses()
        {
            var source = new List <OneLevel>()
            {
                MockDataHelper.BuildOneLevel("-2124"), MockDataHelper.BuildOneLevel("1"), MockDataHelper.BuildOneLevel("5212")
            };
            //Note out of order to ensure test covers other scenarios
            var destination = new List <OneLevel>()
            {
                //Existing, unchanged
                Mapper.Map <OneLevel>(source[0]),
                //To Be updated
                MockDataHelper.BuildOneLevel("1"),

                //Note index 2 is not here and therefore added

                //Does not exist in source and therefore will be deleted
                MockDataHelper.BuildOneLevel("14wdwedqweqe")
            };
            ChangeAssessor <string> changeAssessor = new ChangeAssessor <string>();

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


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


            Assert.AreEqual(ChangeType.None, source[0].ChangeType, string.Format("Record {0} should have the none change type", 0));

            Assert.IsTrue(assessment.OwnedEntities.Contains(source[1]), string.Format("Record {0} should be in the list of changes", 1));
            Assert.AreEqual(ChangeType.Updated, source[1].ChangeType, string.Format("Record {0} should have the updated change type", 1));

            Assert.IsTrue(assessment.OwnedEntities.Contains(source[2]), string.Format("Record {0} should be in the list of changes", 2));
            Assert.AreEqual(ChangeType.Added, source[2].ChangeType, string.Format("Record {0} should have the added change type", 2));

            Assert.IsTrue(assessment.OwnedEntities.Contains(destination[2]), string.Format("Record {0} should be in the list of changes", 2));
            Assert.AreEqual(ChangeType.Deleted, destination[2].ChangeType, string.Format("Record {0} should have the removed change type", 2));
        }