示例#1
0
        public void CompareSetRemoveItemTest()
        {
            var original = new Contact
            {
                Id         = Guid.NewGuid().ToString(),
                Categories = new HashSet <string> {
                    "Person", "Owner", "Blah"
                },
            };

            var current = new Contact
            {
                Id         = original.Id,
                Categories = new HashSet <string> {
                    "Person", "Owner"
                },
            };

            var configuration = new Configuration();
            var comparer      = new EntityComparer(configuration);
            var changes       = comparer.Compare(original, current);

            changes.Should().NotBeNull();
            changes.Count.Should().Be(1);

            changes[0].Path.Should().Be("Categories[2]");
            changes[0].Operation.Should().Be(ChangeOperation.Remove);

            WriteMarkdown(changes);
        }
示例#2
0
        public void CompareDictionaryRemoveTest()
        {
            var original = new Contact
            {
                Id   = Guid.NewGuid().ToString(),
                Data = new Dictionary <string, object>
                {
                    { "Boost", 1 },
                }
            };

            var current = new Contact
            {
                Id = original.Id,
            };

            var configuration = new Configuration();
            var comparer      = new EntityComparer(configuration);
            var changes       = comparer.Compare(original, current);

            changes.Should().NotBeNull();
            changes.Count.Should().Be(1);

            changes[0].Path.Should().Be("Data[Boost]");
            changes[0].Operation.Should().Be(ChangeOperation.Remove);

            WriteMarkdown(changes);
        }
示例#3
0
        public void CompareCollectionRemoveEmptyTest()
        {
            var original = new Order
            {
                Id          = Guid.NewGuid().ToString(),
                OrderNumber = 1000,
                Total       = 10000,
                Items       = new List <OrderLine>()
            };

            var current = new Order
            {
                Id          = Guid.NewGuid().ToString(),
                OrderNumber = 1000,
                Total       = 11000,
            };

            var configuration = new Configuration();
            var comparer      = new EntityComparer(configuration);
            var changes       = comparer.Compare(original, current);

            changes.Should().NotBeNull();
            changes.Count.Should().Be(2);

            changes[0].Path.Should().Be("Id");
            changes[1].Path.Should().Be("Total");

            WriteMarkdown(changes);
        }
示例#4
0
        public void ComparisonTest2()
        {
            var one = new TableA()
            {
                Id = 1, Name = "one", Value = 11
            };
            var two = new TableA()
            {
                Id = 2, Name = "two", Value = 22
            };
            var six = new TableA()
            {
                Id = 6, Name = "six", Value = 66
            };

            var sut = new EntityComparer <TableA>(null);

            Assert.Equal(sut.Compare(one, two), -1);
            Assert.Equal(sut.Compare(two, six), -1);
            Assert.Equal(sut.Compare(two, one), 1);
            Assert.Equal(sut.Compare(six, two), 1);
            Assert.Equal(sut.Compare(one, one), 0);
            Assert.Equal(sut.Compare(two, two), 0);
            Assert.Equal(sut.Compare(six, six), 0);
        }
示例#5
0
        public void Configure()
        {
            Kick.Start(config => config
                       .LogTo(_output.WriteLine)
                       .IncludeAssemblyFor <OrderProfile>()
                       .UseEntityChange()
                       );


            var original = new Order
            {
                Id          = Guid.NewGuid().ToString(),
                OrderNumber = 1000,
                Total       = 10000,
            };

            var current = new Order
            {
                Id          = Guid.NewGuid().ToString(),
                OrderNumber = 1000,
                Total       = 11000,
                Items       = new List <OrderLine>
                {
                    new OrderLine {
                        Sku = "abc-123", Quanity = 1, UnitPrice = 5000
                    },
                }
            };


            var comparer = new EntityComparer();
            var changes  = comparer.Compare(original, current);

            changes.Should().NotBeNull();
            changes.Count.Should().Be(3);

            var total = changes.FirstOrDefault(c => c.Path == "Total");

            total.Should().NotBeNull();
            total.Path.Should().Be("Total");
            total.CurrentFormatted.Should().Be("$11,000.00");

            var items = changes.FirstOrDefault(c => c.Path == "Items[0]");

            items.Should().NotBeNull();
            items.Path.Should().Be("Items[0]");
            items.CurrentFormatted.Should().Be("abc-123");
            items.Operation.Should().Be(ChangeOperation.Add);


            WriteMarkdown(changes);
        }
示例#6
0
        public void CompareCollectionRemoveTest()
        {
            var original = new Order
            {
                Id          = Guid.NewGuid().ToString(),
                OrderNumber = 1000,
                Total       = 10000,
                Items       = new List <OrderLine>
                {
                    new OrderLine {
                        Sku = "abc-123", Quanity = 1, UnitPrice = 5000
                    },
                }
            };

            var current = new Order
            {
                Id          = Guid.NewGuid().ToString(),
                OrderNumber = 1000,
                Total       = 11000,
            };

            var configuration = new Configuration();

            configuration.Configure(config =>
            {
                config.Entity <Order>(e =>
                {
                    e.Property(p => p.Id);
                    e.Collection(p => p.Items).ElementFormatter(v =>
                    {
                        var orderLine = v as OrderLine;
                        return(orderLine?.Sku);
                    });
                });
            });

            var comparer = new EntityComparer(configuration);
            var changes  = comparer.Compare(original, current);

            changes.Should().NotBeNull();
            changes.Count.Should().Be(3);

            changes[0].Path.Should().Be("Id");
            changes[1].Path.Should().Be("Items[0]");
            changes[1].OriginalFormatted.Should().Be("abc-123");
            changes[1].Operation.Should().Be(ChangeOperation.Remove);
            changes[2].Path.Should().Be("Total");

            WriteMarkdown(changes);
        }
示例#7
0
        public async Task <IActionResult> Insert([FromBody] SalesOrderLine payload)
        {
            try
            {
                SalesOrderLine salesOrderLine = new SalesOrderLine {
                    Quantity             = payload.Quantity, Price = payload.Price
                    , SalesOrderId       = payload.SalesOrderId
                    , DiscountAmount     = payload.DiscountAmount
                    , TaxPercentage      = payload.TaxPercentage
                    , SubProductId       = payload.SubProductId
                    , SubProductName     = payload.SubProductName
                    , ProductName        = payload.ProductName
                    , ProductId          = payload.ProductId
                    , Description        = payload.Description
                    , DiscountPercentage = payload.DiscountPercentage
                };
                // salesOrderLine = payload;

                salesOrderLine = this.Recalculate(salesOrderLine);

                List <string> _propiedadesAComparar = new List <string>();
                _propiedadesAComparar.Add("Amount");
                _propiedadesAComparar.Add("DiscountAmount");
                _propiedadesAComparar.Add("SubTotal");
                _propiedadesAComparar.Add("TaxAmount");
                _propiedadesAComparar.Add("Total");

                EntityComparer <SalesOrderLine> comparer = new EntityComparer <SalesOrderLine>(_propiedadesAComparar, "SalesOrderId", 0);
                var res = comparer.Compare(payload, salesOrderLine);

                if (res)
                {
                    _context.SalesOrderLine.Add(salesOrderLine);
                    await _context.SaveChangesAsync();

                    //Falta comparar los totales , haciendo suma de las lineas
                    //this.UpdateSalesOrder(salesOrderLine.SalesOrderId);
                    //return Ok(salesOrderLine);
                    return(await Task.Run(() => Ok(salesOrderLine)));
                }
                else
                {
                    return(BadRequest($"Ocurrio un error, en el envio de los datos!"));
                }
            }
            catch (Exception ex)
            {
                _logger.LogError($"Ocurrio un error: { ex.ToString() }");
                return(BadRequest($"Ocurrio un error:{ex.Message}"));
            }
        }
示例#8
0
        public void CompareCollectionRemoveItemTest()
        {
            var original = new Order
            {
                Id          = Guid.NewGuid().ToString(),
                OrderNumber = 1000,
                Total       = 10000,
                Items       = new List <OrderLine>
                {
                    new OrderLine {
                        Sku = "abc-123", Quanity = 1, UnitPrice = 10000
                    },
                    new OrderLine {
                        Sku = "xyz-123", Quanity = 1, UnitPrice = 5000
                    }
                }
            };

            var current = new Order
            {
                Id          = Guid.NewGuid().ToString(),
                OrderNumber = 1000,
                Total       = 11000,
                Items       = new List <OrderLine>
                {
                    new OrderLine {
                        Sku = "abc-123", Quanity = 1, UnitPrice = 5000
                    }
                }
            };

            var configuration = new Configuration();
            var comparer      = new EntityComparer(configuration);
            var changes       = comparer.Compare(original, current);

            changes.Should().NotBeNull();
            changes.Count.Should().Be(4);

            changes[0].Path.Should().Be("Id");
            changes[1].Path.Should().Be("Items[0].UnitPrice");
            changes[2].Path.Should().Be("Items[1]");
            changes[2].Operation.Should().Be(ChangeOperation.Remove);
            changes[3].Path.Should().Be("Total");

            WriteMarkdown(changes);
        }
示例#9
0
        public void CompareObjectRemovePropertyTest()
        {
            var original = new Order
            {
                Id             = Guid.NewGuid().ToString(),
                OrderNumber    = 1000,
                Total          = 10000,
                BillingAddress = new MailingAddress
                {
                    Address1 = "123 Main St",
                    Address2 = "Suite 101",
                    City     = "New York",
                    State    = "NY",
                    Zip      = "10038"
                }
            };

            var current = new Order
            {
                Id             = Guid.NewGuid().ToString(),
                OrderNumber    = 1000,
                Total          = 11000,
                BillingAddress = new MailingAddress
                {
                    Address1 = "123 Main St",
                    City     = "New York",
                    State    = "NY",
                    Zip      = "10026"
                }
            };

            var configuration = new Configuration();
            var comparer      = new EntityComparer(configuration);
            var changes       = comparer.Compare(original, current);

            changes.Should().NotBeNull();
            changes.Count.Should().Be(4);

            changes[0].Path.Should().Be("Id");
            changes[1].Path.Should().Be("BillingAddress.Address2");
            changes[1].Operation.Should().Be(ChangeOperation.Replace);
            changes[2].Path.Should().Be("BillingAddress.Zip");
            changes[3].Path.Should().Be("Total");

            WriteMarkdown(changes);
        }
示例#10
0
        public void ComparenNestedObjectsPathsTest()
        {
            var node = new TreeNode
            {
                Name  = "Root",
                nodes = new List <TreeNode>
                {
                    new TreeNode
                    {
                        Name  = "Level 1",
                        nodes = new List <TreeNode>
                        {
                            new TreeNode
                            {
                                Name = "Level 2"
                            }
                        }
                    }
                }
            };

            var node2 = new TreeNode
            {
                Name  = "Root",
                nodes = new List <TreeNode>
                {
                    new TreeNode
                    {
                        Name  = "Level 1",
                        nodes = new List <TreeNode>
                        {
                            new TreeNode
                            {
                                Name = "Level 3"
                            }
                        }
                    }
                }
            };

            EntityComparer entityComparer = new EntityComparer();
            var            changes        = entityComparer.Compare(node, node2);

            changes.Should().NotBeEmpty();
            changes.First().Path.Should().Be("nodes[0].nodes[0].Name");
        }
        private void CreateListFromResults(Logic.SystemComparer emds)
        {
            SendMessageToStatusBar?.Invoke(this, new StatusBarMessageEventArgs(0, $"Generating List"));
            comparisonListView.Items.Clear();

            /*OrganizationComparer orgComparer = new OrganizationComparer();
             *      MetadataComparison orgComparison = null;
             *      orgComparison = orgComparer.Compare("Organization", emds._sourceCustomizationRoot.Organizations,
             *          emds._targetCustomizationRoot.Organizations);*/


            if (_configuration.IncludeViews)
            {
                SendMessageToStatusBar?.Invoke(this, new StatusBarMessageEventArgs(0, "Processing Views..."));
                EntityComparer     viewComparer   = new EntityComparer();
                MetadataComparison viewComparison = viewComparer.Compare("Views",
                                                                         emds.SourceCustomizationRoot.Views,
                                                                         emds.TargetCustomizationRoot.Views);
                AddItem(viewComparison, null);
            }

            if (_configuration.IncludeForms)
            {
                SendMessageToStatusBar?.Invoke(this, new StatusBarMessageEventArgs(33, "Processing Forms..."));
                EntityComparer     formComparer   = new EntityComparer();
                MetadataComparison formComparison = formComparer.Compare("Forms",
                                                                         emds.SourceCustomizationRoot.Forms,
                                                                         emds.TargetCustomizationRoot.Forms);
                AddItem(formComparison, null);
            }

            SendMessageToStatusBar?.Invoke(this, new StatusBarMessageEventArgs(66, "Processing Forms..."));
            MetadataComparer   comparer   = new MetadataComparer(_configuration);
            MetadataComparison comparison = comparer.Compare("Entities",
                                                             emds.SourceCustomizationRoot.EntitiesRaw,
                                                             emds.TargetCustomizationRoot.EntitiesRaw);

            AddItem(comparison, null);

            SendMessageToStatusBar?.Invoke(this, new StatusBarMessageEventArgs("List generated!"));
        }
示例#12
0
        public void CompareDictionaryRemoveEmptyTest()
        {
            var original = new Contact
            {
                Id   = Guid.NewGuid().ToString(),
                Data = new Dictionary <string, object>()
            };

            var current = new Contact
            {
                Id = original.Id,
            };

            var configuration = new Configuration();
            var comparer      = new EntityComparer(configuration);
            var changes       = comparer.Compare(original, current);

            changes.Should().NotBeNull();
            changes.Count.Should().Be(0);

            WriteMarkdown(changes);
        }
示例#13
0
        public void CompareObjectValueFormatter()
        {
            var original = new Order
            {
                Id          = Guid.NewGuid().ToString(),
                OrderNumber = 1000,
                Total       = 10000,
            };

            var current = new Order
            {
                Id          = original.Id,
                OrderNumber = 1000,
                Total       = 11000,
            };

            var configuration = new Configuration();

            configuration.Configure(config =>
            {
                config.Entity <Order>(e =>
                {
                    e.Property(p => p.Total).Formatter(StringFormatter.Currency);
                });
            });

            var comparer = new EntityComparer(configuration);
            var changes  = comparer.Compare(original, current);

            changes.Should().NotBeNull();
            changes.Count.Should().Be(1);

            changes[0].Path.Should().Be("Total");
            changes[0].CurrentFormatted.Should().Be("$11,000.00");

            WriteMarkdown(changes);
        }
示例#14
0
        public void CompareComplexCompareTest()
        {
            var original = new Contact
            {
                Id         = Guid.NewGuid().ToString(),
                Created    = DateTime.Now,
                Updated    = DateTime.Now,
                FirstName  = "Jim",
                LastName   = "Bob",
                JobTitle   = "CEO",
                Status     = Status.New,
                Roles      = new[] { "Administrator", "User" },
                Categories = new HashSet <string> {
                    "Person", "Owner"
                },
                Data = new Dictionary <string, object>
                {
                    { "Boost", 1 },
                    { "Path", "./home" }
                },
                EmailAddresses = new List <EmailAddress>
                {
                    new EmailAddress {
                        Address = "*****@*****.**", Type = ContactType.Business
                    },
                    new EmailAddress {
                        Address = "*****@*****.**", Type = ContactType.Personal
                    },
                },
                MailingAddresses = new List <MailingAddress>
                {
                    new MailingAddress
                    {
                        Address1 = "123 Main St",
                        City     = "New York",
                        State    = "NY",
                        Zip      = "10026"
                    }
                },
                PhoneNumbers = new List <PhoneNumber>
                {
                    new PhoneNumber {
                        Number = "888-555-1212", Type = ContactType.Business
                    }
                }
            };

            var current = new Contact
            {
                Id         = original.Id,
                Created    = original.Created,
                Updated    = original.Updated.AddSeconds(1),
                FirstName  = "Jim",
                LastName   = "Bob",
                JobTitle   = "CEO",
                Status     = Status.Verified,
                Roles      = new[] { "User" },
                Categories = new HashSet <string> {
                    "Person", "Owner", "Blah"
                },
                Data = new Dictionary <string, object>
                {
                    { "Boost", 2 },
                    { "Path", "./path" }
                },
                EmailAddresses = new List <EmailAddress>
                {
                    new EmailAddress {
                        Address = "*****@*****.**", Type = ContactType.Business
                    },
                    new EmailAddress {
                        Address = "*****@*****.**", Type = ContactType.Personal
                    },
                    new EmailAddress {
                        Address = "*****@*****.**", Type = ContactType.Home
                    },
                },
                MailingAddresses = new List <MailingAddress>
                {
                    new MailingAddress
                    {
                        Address1 = "123 Main St",
                        City     = "New York",
                        State    = "NY",
                        Zip      = "10027"
                    }
                },
                PhoneNumbers = new List <PhoneNumber>
                {
                    new PhoneNumber {
                        Number = "800-555-1212", Type = ContactType.Business
                    }
                }
            };

            var configuration = new Configuration();

            configuration.Configure(config => config
                                    .Entity <Contact>(e =>
            {
                e.Property(p => p.FirstName).Display("First Name");
                e.Collection(p => p.Roles)
                .CollectionComparison(CollectionComparison.ObjectEquality)
                .ElementEquality(StringEquality.OrdinalIgnoreCase);
                e.Collection(p => p.EmailAddresses).ElementFormatter(v =>
                {
                    var address = v as EmailAddress;
                    return(address?.Address);
                });
            })
                                    .Entity <EmailAddress>(e =>
            {
                e.Property(p => p.Address).Display("Email Address");
            })
                                    );

            var comparer = new EntityComparer(configuration);
            var changes  = comparer.Compare(original, current);

            changes.Should().NotBeNull();
            changes.Count.Should().Be(10);

            WriteMarkdown(changes);
        }
示例#15
0
        public void CompareCollectionObjectEqualityTest()
        {
            var original = new Order
            {
                Id    = Guid.NewGuid().ToString(),
                Items = new List <OrderLine>
                {
                    new OrderLine {
                        Sku = "XYZ-123", Quanity = 1, UnitPrice = 10000
                    },
                    new OrderLine {
                        Sku = "abc-123", Quanity = 1, UnitPrice = 10000
                    }
                }
            };

            var current = new Order
            {
                Id    = original.Id,
                Items = new List <OrderLine>
                {
                    new OrderLine {
                        Sku = "abc-123", Quanity = 2, UnitPrice = 5000
                    },
                    new OrderLine {
                        Sku = "xyz-123", Quanity = 2, UnitPrice = 5000
                    }
                }
            };

            var configuration = new Configuration();

            configuration.Configure(config => config
                                    .Entity <Order>(e =>
            {
                e.Collection(p => p.Items)
                .CollectionComparison(CollectionComparison.ObjectEquality)
                .ElementEquality((o, c) =>
                {
                    var l = o as OrderLine;
                    var r = c as OrderLine;

                    return(string.Equals(l?.Sku, r?.Sku, StringComparison.OrdinalIgnoreCase));
                });
            })
                                    .Entity <OrderLine>(e =>
            {
                e.Property(p => p.Sku).Equality(StringEquality.OrdinalIgnoreCase);
            })
                                    );
            var comparer = new EntityComparer(configuration);

            var changes = comparer.Compare(original, current);

            changes.Should().NotBeNull();
            changes.Count.Should().Be(4);

            changes[0].Path.Should().Be("Items[0].Quanity");
            changes[1].Path.Should().Be("Items[0].UnitPrice");
            changes[2].Path.Should().Be("Items[1].Quanity");
            changes[3].Path.Should().Be("Items[1].UnitPrice");

            WriteMarkdown(changes);
        }
示例#16
0
        private void LoadEntities()
        {
            _systemComparer = new Logic.SystemComparer(_sourceConnection, _targetConnection);

            WorkAsync(new WorkAsyncInfo
            {
                Message = "Getting Metadata",
                Work    = (worker, args) =>
                {
                    LogInfo("Start retrieving metadata on Source");
                    _systemComparer.RetrieveMetadata(ConnectionType.Source, _configuration.IncludeAttributeMetadata, worker.ReportProgress);
                    //_systemComparer.RetrieveOrganization(ConnectionType.Source, worker.ReportProgress);
                    _systemComparer.RetrieveForms(ConnectionType.Source, _configuration.IncludeForms, worker.ReportProgress);
                    _systemComparer.RetrieveViews(ConnectionType.Source, _configuration.IncludeViews, worker.ReportProgress);
                    LogInfo("Start retrieving metadata on Target");
                    _systemComparer.RetrieveMetadata(ConnectionType.Target, _configuration.IncludeAttributeMetadata, worker.ReportProgress);
                    //_systemComparer.RetrieveOrganization(ConnectionType.Target, worker.ReportProgress);
                    _systemComparer.RetrieveForms(ConnectionType.Target, _configuration.IncludeForms, worker.ReportProgress);
                    _systemComparer.RetrieveViews(ConnectionType.Target, _configuration.IncludeViews, worker.ReportProgress);

                    args.Result = _systemComparer;
                },
                PostWorkCallBack = (args) =>
                {
                    LogInfo("Postprocessing Metadata");
                    if (args.Error != null)
                    {
                        LogError(args.Error.ToString(), args);
                        MessageBox.Show(args.Error.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    var emds = (Logic.SystemComparer)args.Result;

                    comparisonListView.Items.Clear();

                    /*OrganizationComparer orgComparer = new OrganizationComparer();
                     * MetadataComparison orgComparison = null;
                     * orgComparison = orgComparer.Compare("Organization", emds._sourceCustomizationRoot.Organizations,
                     *  emds._targetCustomizationRoot.Organizations);*/



                    if (_configuration.IncludeViews)
                    {
                        EntityComparer viewComparer       = new EntityComparer();
                        MetadataComparison viewComparison = viewComparer.Compare("Views",
                                                                                 emds._sourceCustomizationRoot.Views,
                                                                                 emds._targetCustomizationRoot.Views);
                        AddItem(viewComparison, null);
                    }

                    if (_configuration.IncludeForms)
                    {
                        EntityComparer formComparer       = new EntityComparer();
                        MetadataComparison formComparison = formComparer.Compare("Forms",
                                                                                 emds._sourceCustomizationRoot.Forms,
                                                                                 emds._targetCustomizationRoot.Forms);
                        AddItem(formComparison, null);
                    }

                    MetadataComparer comparer     = new MetadataComparer();
                    MetadataComparison comparison = comparer.Compare("Entities",
                                                                     emds._sourceCustomizationRoot.EntitiesRaw,
                                                                     emds._targetCustomizationRoot.EntitiesRaw);
                    AddItem(comparison, null);
                },
                ProgressChanged = e => { SetWorkingMessage(e.UserState.ToString()); }
            });
        }