コード例 #1
0
        public void ObjectsComparerValueMismatchTest()
        {
            var customerIdentifier = 4;
            var ops      = new NorthWindDatabaseOperations();
            var customer = ops.GetCompanyByCustomerIdentifier(customerIdentifier);
            //Assert.IsTrue(customer.Equals(AroundTheHorn));
            var customer1 = AroundTheHorn;

            customer1.FirstName = "Frank";

            var comparer = new ObjectsComparer.Comparer <Company>();

            var positiveCompare = comparer.Compare(customer, customer1, out var differences);

            Assert.IsFalse(positiveCompare);

            var diff = differences.FirstOrDefault();

            Assert.IsTrue(diff != null && diff.DifferenceType == DifferenceTypes.ValueMismatch,
                          "expected ValueMismatch");
            Assert.IsTrue(diff.MemberPath == "FirstName",
                          "expected first name");

            Assert.IsTrue(diff.Value1 == "Thomas",
                          "expected Thomas");

            Assert.IsTrue(diff.Value2 == "Frank",
                          "expected Frank");
        }
コード例 #2
0
        static void Main(string[] args)
        {
            var compr = new ObjectsComparer.Comparer <Employee>();

            Employee e1 = new Employee()
            {
                EmployeeID = 1,
                FirstName  = "Andrew",
                LastName   = "Sheley",
                UpdatedBy  = "Jones",
            };
            Employee e2 = new Employee()
            {
                EmployeeID = 1,
                FirstName  = "Andy",
                LastName   = "Sheley",
                UpdatedBy  = "Elvis",
            };


            //Compare objects
            IEnumerable <Difference> differences;
            var isEqual = compr.Compare(e1, e2, out differences);


            Console.WriteLine("Hello World!");
        }
コード例 #3
0
        private static IEnumerable <Difference> CompareEntityWithoutList <T>(string oldData, string newData)
        {
            var comparer = new ObjectsComparer.Comparer <T>();

            comparer.Compare(InitializeEntity <T>(oldData), InitializeEntity <T>(newData), out IEnumerable <Difference> differences);

            return(differences);
        }
コード例 #4
0
        public ActionResult Edit(EmployeeViewModel employee)
        {
            employee.Name         = employee.Name.Trim();
            employee.Email        = employee.Email.Trim();
            employee.Address      = employee.Address.Trim();
            employee.MobileNumber = Convert.ToDouble(employee.MobileNumber.ToString().Trim());

            EmployeeViewModel originalEmployee = (EmployeeViewModel)Session["EmployeeOriginal"];
            var comparer = new ObjectsComparer.Comparer <EmployeeViewModel>();

            if (ModelState.IsValid)
            {
                bool isEqual = comparer.Compare(employee, originalEmployee);
                ViewData["Designations"]   = GetDesignations();
                ViewData["Qualifications"] = GetQualifications();
                ViewData["Managers"]       = GetManagers();
                ViewData["Roles"]          = GetRoles();
                if (!isEqual)
                {
                    int status = _services.EditEmployeeById(employee.EmployeeViewModeltoDTO());
                    //If mobile number already exists
                    if (status == 1)
                    {
                        ModelState.AddModelError("MobileNumber", "Mobile number already exists");
                    }
                    //If email already exists
                    else if (status == 2)
                    {
                        ModelState.AddModelError("Email", "Email already exists");
                    }
                    else
                    {
                        if (status == -1)
                        {
                            TempData["error"] = "Error in modifying Employee record";
                        }
                        if (status == 0)
                        {
                            TempData["message"] = "Modified Employee record";
                        }

                        if (status == 3)
                        {
                            TempData["error"] = "Role for this employee cannot be changed";
                        }
                        return(RedirectToAction("Index"));
                    }
                }
                else
                {
                    TempData["error"] = "No modification applied";
                    return(RedirectToAction("Index"));
                }
            }
            return(View(employee));
        }
コード例 #5
0
        public bool compareServerConfig(Server toCompare)
        {
            JsonService = new JsonFileServices();
            foreach (var s in JsonService.GetServer(HttpContext.Session.GetString("Customer"), "CurrentConfig", toCompare.ServerName))
            {
                originalServer = s;
            }
            var comparer = new ObjectsComparer.Comparer <Server>();
            var isEqual  = comparer.Compare(originalServer, toCompare, out differences);

            setDifferencesToSession(differences);
            return(isEqual);
        }
コード例 #6
0
        protected override JsonContract CreateContract(Type objectType)
        {
            Logger.Info($"{nameof(CreateContract)}: {objectType}");
            var                baseR       = base.CreateContract(objectType);
            JsonContract       result      = null;
            JsonObjectContract objContract = null;

            if (objectType == typeof(LogLevel))
            {
                result = objContract = new JsonObjectContract(objectType)
                {
                    MemberSerialization = MemberSerialization.OptIn
                };
            }
            else if (objectType == typeof(LogEventInfo))
            {
                result = objContract = new JsonObjectContract(objectType)
                {
                    MemberSerialization = MemberSerialization.OptOut,
                };
            }

            if (result != null)
            {
                Logger.Debug($"Constructed custom contract for {objectType}");
            }
            if (objContract != null)
            {
                var ro = baseR as JsonObjectContract;
                if (ro != null)
                {
                    Logger.Debug("performing compare");
                    var x = new ObjectsComparer.Comparer <JsonObjectContract>();
                    var d = x.CalculateDifferences(ro, objContract);
                    foreach (var diff in d)
                    {
                        Logger.Debug($"{diff}");
                    }
                }
                Logger.Debug($"ObjectContract has MemberSerialization of {objContract.MemberSerialization}");
            }

            if (result == null)
            {
                Logger.Debug($"calling base method {nameof(CreateContract)}");
            }

            return(result);
        }
コード例 #7
0
        public void GetAllSourceEqualObject()
        {
            SourceFormarteDonnees testItemOne = new SourceFormarteDonnees
            {
                ColId = 1,
                SourceFormarteUtilNom                 = "deiva",
                SourceFormarteUtilPrenom              = "Rajaram",
                SourceFormarteSectNom                 = "COLOMIERS",
                SourceFormarteCatalPrincipal          = "DP",
                SourceFormarteCatalAutrePrincipal     = "Par défaut",
                SourceFormarteVersNom                 = "5.3.0.0",
                SourceFormarteComPremierDateId        = 1,
                SourceFormarteComPremierDate          = Convert.ToDateTime("2018-06-27 10:23:10.000"),
                SourceFormarteComDernierDateId        = 2,
                SourceFormarteComDerniereDate         = Convert.ToDateTime("2018-06-28 10:23:10.000"),
                SourceFormarteComPremierFactureDateId = 1,
                SourceFormarteComPremierFactureDate   = Convert.ToDateTime("2018-06-25 10:23:10.000"),
                SourceFormarteComDernierFactureDateId = 2,
                SourceFormarteComDerniereFactureDate  = Convert.ToDateTime("2018-06-26 10:23:10.000"),
                SourceFormarteVisDate                 = Convert.ToDateTime("2018-06-25 10:25:01.000"),
                SourceFormarteTabNom           = new[] { "table1", "table2", "table3", "table4" },
                SourceFormarteTabLigneComptage = new[] { "1", "5", "6", "9" },
                SourceFormarteTabNomIndex      = new List <IndexDetails> {
                    new IndexDetails {
                        TableNom = "table1", Indexes = new[] { "index1", "index2" }
                    },
                    new IndexDetails {
                        TableNom = "table2", Indexes = new[] { "indexz", "indexw" }
                    }
                }
            };

            // create mock
            Mock <ILogger <DonneeSourceController> > mockloger2 = new Mock <ILogger <DonneeSourceController> >();
            // create mock dal object
            Mock <SourceDataAccessLayer> mockDalSource2 = new Mock <SourceDataAccessLayer>();

            var    testUnitaire2 = new DonneeSourceController(mockloger2.Object, mockDalSource2.Object);
            string testDate2     = DateTime.MinValue.ToShortDateString();
            SourceFormarteDonnees testItemTwo = testUnitaire2.SelectionDonneesSource(testDate2, testDate2, testDate2, testDate2, null, null, null).FirstOrDefault();

            //Initialize objects and comparer
            var comparer = new ObjectsComparer.Comparer <SourceFormarteDonnees>();

            //Compare objects
            var isEqual = comparer.Compare(testItemOne, testItemTwo, out IEnumerable <Difference> differences);

            Assert.True(isEqual);
        }
コード例 #8
0
ファイル: ObjectComparer.cs プロジェクト: sanjukz/FIL
        public override ObjectsComparer.IComparer <T> GetObjectsComparer <T>(ComparisonSettings settings = null, BaseComparer parentComparer = null)
        {
            var comparer = new ObjectsComparer.Comparer <T>(settings, parentComparer, this);

            //Do not compare Fields of Type Guid
            comparer.AddComparerOverride <Guid>(DoNotCompareValueComparer.Instance);

            //Do not compare fields of type dateTime
            comparer.AddComparerOverride <DateTime>(DoNotCompareValueComparer.Instance);

            //Do not compare field Id
            comparer.AddComparerOverride("Id", DoNotCompareValueComparer.Instance);

            return(comparer);
        }
コード例 #9
0
        public void GetCompanyWithCountryByIdentifier()
        {
            var customerIdentifier = 4;
            var ops      = new NorthWindDatabaseOperations();
            var customer = ops.GetCompanyWithCountryByIdentifier(customerIdentifier);

            var customer1 = AroundTheHorn;

            customer1.ContactIdentifier = 4;
            customer1.CountryId         = 19;
            customer1.Country           = "UK";

            var comparer = new ObjectsComparer.Comparer <Company>();

            var isEqual = comparer.Compare(customer1, customer, out var differences);

            Assert.IsTrue(isEqual,
                          "expected customer country test to be the same");
        }
コード例 #10
0
        public void CompareEntityObjectToLocalInstanceTest()
        {
            var customerIdentifier = 4;
            var ops = new NorthWindDatabaseOperations();

            /*
             * Return specific properties
             */
            var customer = ops.GetCompanyByCustomerIdentifier(customerIdentifier);

            var comparer = new ObjectsComparer.Comparer <Company>();

            var isEqual = comparer.Compare(customer, AroundTheHorn, out var differences);

            Assert.IsTrue(isEqual);

            /*
             * Demonstrate returning all navigation properties
             */
            ops.GetCompanyByCustomerIdentifierTemp(customerIdentifier);
        }
コード例 #11
0
    public static void InsertInOrderIfMissing <T>(this IList <T> collection, params T[] set)
        where T : IEquatable <T>, IComparable <T>
    {
        var comparer = new ObjectsComparer.Comparer <T>(new ComparisonSettings {
        });

        //var dif2f = Netsoft.Diff.Differences.Between(set, collection.ToArray());
        foreach (var item in set)
        {
            if (collection.Contains(item))
            {
                var single = collection.Single(a => a.Equals(item));
                // var diff = comparer.CalculateDifferences(item, single);
                var equal = TextJsonHelper.Compare(single, item);
                if (equal)
                {
                    continue;
                }
                collection.Remove(item);
            }

            collection.InsertInOrder(item);
        }
    }
コード例 #12
0
ファイル: Settings.cs プロジェクト: LeslieVBH/api-contest
    public bool AddConfigFile(string config)
    {
        string name     = "";
        bool   failed   = false;
        bool   backedUp = false;

        // try
        // {
        string[] configSplit = config.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);
        if (HelperFunctions.DetermineType(config) == ConfigTypes.Fortigate)
        {
            Console.WriteLine("This config is a Fortigate config file");
            Fortigate newFortigate = new Fortigate(configSplit, config);

            bool found = false;
            name = newFortigate.hostname;

            for (int i = fortigates.Count - 1; i >= 0; i--)
            {
                //TODO: improve this selection to include updated fortigates

                Fortigate currentFG = fortigates[i];
                if (fortigates[i].hostname == newFortigate.hostname)
                {
                    Console.WriteLine("Getting differences");
                    var comparer = new ObjectsComparer.Comparer <Fortigate>();
                    IEnumerable <Difference> differences;
                    var isEqual = comparer.Compare(newFortigate, currentFG, out differences);
                    //Print results
                    Console.WriteLine(isEqual ? "Objects are equal" : string.Join(Environment.NewLine, differences));
                    if (isEqual)
                    {
                        Console.WriteLine("Found exact match, skipping");
                        found = true;
                    }
                    else
                    {
                        Console.WriteLine("Found updated Fortigate, removing old");
                        fortigates.RemoveAt(i);
                    }
                }
            }
            if (!found)
            {
                newFortigate.updated = true;

                Console.WriteLine("Adding fortigate");
                fortigates.Add(newFortigate);
            }
        }
        else if ((HelperFunctions.DetermineType(config) == ConfigTypes.Switch29xx) || (HelperFunctions.DetermineType(config) == ConfigTypes.Switch19xx) || (HelperFunctions.DetermineType(config) == ConfigTypes.Switch1920S) || (HelperFunctions.DetermineType(config) == ConfigTypes.CiscoSG200))
        {
            Console.WriteLine("This config is a Switch config file");
            Switch newSwitch = new Switch(configSplit, config, HelperFunctions.DetermineType(config));

            bool found = false;
            name = newSwitch.HostName;
            //MemoryStream streamNew = HelperFunctions.GetStreamFromFortigate(newSwitch);

            for (int i = switches.Count - 1; i >= 0; i--)
            {
                //TODO: improve this selection to include updated fortigates


                if (switches[i].HostName == newSwitch.HostName)
                {
                    Console.WriteLine("Getting differences");
                    var comparer = new ObjectsComparer.Comparer <Switch>();
                    IEnumerable <Difference> differences;
                    var isEqual = comparer.Compare(newSwitch, switches[i], out differences);
                    //Print results
                    Console.WriteLine(isEqual ? "Objects are equal" : string.Join(Environment.NewLine, differences));

                    if (isEqual)
                    {
                        Console.WriteLine("Found exact match, skipping");

                        found = true;
                    }
                    else
                    {
                        Console.WriteLine("Found updated switch, removing old");
                        switches.RemoveAt(i);
                    }
                }
            }
            if (!found)
            {
                Console.WriteLine("Adding switch");
                newSwitch.updated = true;

                switches.Add(newSwitch);
            }
        }

        else if (HelperFunctions.DetermineType(config) == ConfigTypes.unknown)

        {
            failed = true;
        }



        return(!failed);
    }