Exemplo n.º 1
0
        public void UsingIgnorePropertyThrowsWithMethod()
        {
            var config = new ComparisonConfig();

            Assert.Throws <ArgumentException>(() =>
                                              config.IgnoreProperty <Person>(x => x.GetAge()));
        }
Exemplo n.º 2
0
        public void IgnoreDerivedClassPropertyUsingIgnoreProperty()
        {
            var config = new ComparisonConfig();

            config.IgnoreProperty <DeriveFromOfficer>(x => x.ID);

            var deriveFromOfficer1 = new DeriveFromOfficer {
                HomeAddress = "Address", ID = 1, Name = "John", Type = Deck.Engineering
            };
            var deriveFromOfficer2 = new DeriveFromOfficer {
                HomeAddress = "Address", ID = 2, Name = "John", Type = Deck.Engineering
            };

            var derive2FromOfficer1 = new Derive2FromOfficer {
                Email = "*****@*****.**", ID = 3, Name = "John", Type = Deck.Engineering
            };
            var derive2FromOfficer2 = new Derive2FromOfficer {
                Email = "*****@*****.**", ID = 4, Name = "John", Type = Deck.Engineering
            };

            var compare = new CompareLogic(config);

            var result = compare.Compare((Officer)deriveFromOfficer1, (Officer)deriveFromOfficer2);

            Assert.IsTrue(result.AreEqual);

            result = compare.Compare(derive2FromOfficer1, derive2FromOfficer2);
            Assert.IsFalse(result.AreEqual);
        }
Exemplo n.º 3
0
        public void UsingIgnorePropertyThrowsWithField()
        {
            var config = new ComparisonConfig();

            Assert.Throws <ArgumentException>(() =>
                                              config.IgnoreProperty <Person>(x => x.DateCreated));
        }
Exemplo n.º 4
0
        public StudentViewServiceTests()
        {
            this.studentServiceMock = new Mock <IStudentService>();
            this.userServiceMock    = new Mock <IUserService>();
            this.dateTimeBrokerMock = new Mock <IDateTimeBroker>();
            this.loggingBrokerMock  = new Mock <ILoggingBroker>();
            var compareConfig = new ComparisonConfig();

            compareConfig.IgnoreProperty <Student>(student => student.Id);
            compareConfig.IgnoreProperty <Student>(student => student.UserId);
            this.compareLogic = new CompareLogic(compareConfig);

            this.studentViewService = new StudentViewService(
                studentService: this.studentServiceMock.Object,
                userService: this.userServiceMock.Object,
                dateTimeBroker: this.dateTimeBrokerMock.Object,
                loggingBroker: this.loggingBrokerMock.Object);
        }
Exemplo n.º 5
0
        public BookViewServiceTests()
        {
            this._bookServiceMock    = new Mock <IBookService>();
            this._userServiceMock    = new Mock <IUserService>();
            this._dateTimeBrokerMock = new Mock <IDateTimeBroker>();
            this._loggingBrokerMock  = new Mock <ILoggingBroker>();
            var compareConfig = new ComparisonConfig();

            compareConfig.IgnoreProperty <Book>(book => book.Id);
            //  compareConfig.IgnoreProperty<Book>(book => book.BookId);
            this._compareLogic = new CompareLogic(compareConfig);

            //this.bookViewService = new BookViewService(
            //   bookService: _bookServiceMock.Object,
            //   userService: _userServiceMock.Object,
            //   dateTimeBroker: _dateTimeBrokerMock.Object,
            //   loggingBroker: _loggingBrokerMock.Object);
        }
Exemplo n.º 6
0
        public void IgnoreUnaryTypeMemberUsingIgnoreProperty()
        {
            var config = new ComparisonConfig();

            config.IgnoreProperty <Person>(x => x.DateModified);

            var person1 = new Person {
                DateModified = new DateTime(2019, 5, 23)
            };
            var person2 = new Person {
                DateModified = new DateTime(2015, 1, 2)
            };

            var compare = new CompareLogic(config);

            var result = compare.Compare(person1, person2);

            Assert.IsTrue(result.AreEqual);
        }
Exemplo n.º 7
0
        public void IgnoreTypeMemberUsingIgnoreProperty()
        {
            var config = new ComparisonConfig();

            config.IgnoreProperty <Person>(x => x.Name);

            var person1 = new Person {
                Name = "Darth Vader"
            };
            var person2 = new Person {
                Name = "Anakin Skywalker"
            };

            var compare = new CompareLogic(config);

            var result = compare.Compare(person1, person2);

            Assert.IsTrue(result.AreEqual);
        }
Exemplo n.º 8
0
        private static CompareLogic InitComparitor(bool isObo)
        {
            ComparisonConfig config = new ComparisonConfig
            {
                IgnoreObjectTypes     = true, // To match Enrollee to EnrolleeViewModel
                CompareFields         = false,
                MaxDifferences        = 100,
                IgnoreCollectionOrder = true
            };

            // Fields considered "minor" changes
            config.IgnoreProperty <Enrollee>(x => x.Email);
            config.IgnoreProperty <Enrollee>(x => x.SmsPhone);
            config.IgnoreProperty <Enrollee>(x => x.Phone);
            config.IgnoreProperty <Enrollee>(x => x.PhoneExtension);
            if (isObo)
            {
                config.IgnoreProperty <Enrollee>(x => x.Jobs);
            }

            // Ignored fields on models due to the frontend not sending all keys/navigation properties
            config.IgnoreProperty <BaseAuditable>(x => x.CreatedUserId);
            config.IgnoreProperty <BaseAuditable>(x => x.CreatedTimeStamp);
            config.IgnoreProperty <BaseAuditable>(x => x.UpdatedUserId);
            config.IgnoreProperty <BaseAuditable>(x => x.UpdatedTimeStamp);

            config.IgnoreProperty <Certification>(x => x.Id);
            config.IgnoreProperty <Certification>(x => x.Enrollee);
            config.IgnoreProperty <Certification>(x => x.EnrolleeId);
            config.IgnoreProperty <Certification>(x => x.College);
            config.IgnoreProperty <Certification>(x => x.License);
            config.IgnoreProperty <Certification>(x => x.Practice);

            config.IgnoreProperty <Job>(x => x.Id);
            config.IgnoreProperty <Job>(x => x.Enrollee);
            config.IgnoreProperty <Job>(x => x.EnrolleeId);

            config.IgnoreProperty <MailingAddress>(x => x.Id);
            config.IgnoreProperty <MailingAddress>(x => x.Country);
            config.IgnoreProperty <MailingAddress>(x => x.Province);

            config.IgnoreProperty <EnrolleeCareSetting>(x => x.Id);
            config.IgnoreProperty <EnrolleeCareSetting>(x => x.Enrollee);
            config.IgnoreProperty <EnrolleeCareSetting>(x => x.EnrolleeId);
            config.IgnoreProperty <EnrolleeCareSetting>(x => x.CareSetting);

            config.IgnoreProperty <EnrolleeRemoteUser>(x => x.Id);
            config.IgnoreProperty <EnrolleeRemoteUser>(x => x.Enrollee);
            config.IgnoreProperty <EnrolleeRemoteUser>(x => x.RemoteUser);

            config.IgnoreProperty <RemoteAccessSite>(x => x.Id);
            config.IgnoreProperty <RemoteAccessSite>(x => x.Enrollee);
            config.IgnoreProperty <RemoteAccessSite>(x => x.Site);

            config.IgnoreProperty <RemoteAccessLocation>(x => x.Id);
            config.IgnoreProperty <RemoteAccessLocation>(x => x.Enrollee);
            config.IgnoreProperty <RemoteAccessLocation>(x => x.EnrolleeId);

            config.IgnoreProperty <SelfDeclaration>(x => x.Id);
            config.IgnoreProperty <SelfDeclaration>(x => x.EnrolleeId);
            config.IgnoreProperty <SelfDeclaration>(x => x.Enrollee);
            config.IgnoreProperty <SelfDeclaration>(x => x.SelfDeclarationType);
            config.IgnoreProperty <SelfDeclaration>(x => x.DocumentGuids);

            return(new CompareLogic(config));
        }
Exemplo n.º 9
0
        public async Task BackupRestore()
        {
            #region   Components

            var container             = ComponentTestFactory.BuildContainer();
            var customerComponet      = container.GetInstance <CustomerComponent>();
            var customerQueryComponet = container.GetInstance <CustomerQueryComponent>();
            var productComponent      = container.GetInstance <ProductComponent>();
            var productQueryComponent = container.GetInstance <ProductQueryComponent>();
            var squadQueryComponent   = container.GetInstance <SquadQueryComponent>();
            var sourceComponent       = container.GetInstance <SourceComponent>();
            var migrationComponent    = container.GetInstance <MigrationComponent>();
            var journeyComponent      = container.GetInstance <JourneyQueryComponent>();
            var featureComponent      = container.GetInstance <FeatureQueryComponent>();
            var sourceItemComponent   = container.GetInstance <SourceItemComponent>();
            var securityComponent     = container.GetInstance <SecurityRiskComponent>();
            var reliabilityComponent  = container.GetInstance <ReliabilityRiskComponent>();

            #endregion
            var result = await customerComponet.CreateCustomer(new Models.CustomerPostRp()
            {
                Name    = "test",
                Default = true
            });

            var product = await productComponent.CreateProduct(new Models.ProductPostRp()
            {
                Name = "test", CustomerId = result.Id
            });

            var source = await sourceComponent.Create(new Models.SourcePostRp()
            {
                Name      = "test",
                ProductId = product.Id
            });

            var securityThreats = await securityComponent.CreateDefault();

            var SecurityRisk = await securityComponent.Create(new Models.SecurityRiskPost()
            {
                SourceId = source.Id,
                Name     = "test risk"
            });

            var reliabiltyThreats = await reliabilityComponent.CreateDefault();

            var reliabilityRisk = await reliabilityComponent.Create(new Models.ReliabilityRiskPostRp()
            {
                Name     = "reliability risk",
                SourceId = source.Id
            });

            var stream = await migrationComponent.Backup(true);

            await migrationComponent.ClearData();

            Assert.Empty(await customerQueryComponet.GetCustomers());
            Assert.Empty(await securityComponent.GetThreats());
            Assert.Empty(await reliabilityComponent.GetThreats());

            await migrationComponent.Restore(stream);

            var customer_target = await customerQueryComponet.GetCustomerByName("test");

            Assert.NotNull(customer_target);

            var products = await productQueryComponent.GetProducts(customer_target.Id);

            Assert.NotEmpty(products);

            foreach (var item in products)
            {
                var sources = await sourceComponent.GetByProductId(item.Id);

                Assert.NotEmpty(sources);

                var anchors = await productQueryComponent.GetAnchors(item.Id);

                Assert.NotEmpty(anchors);
            }

            var sourceItems = await sourceItemComponent.GetAll();

            Assert.NotEmpty(sourceItems);

            var squads = await squadQueryComponent.GetSquads(customer_target.Id);

            Assert.NotEmpty(squads);

            var journeys = await journeyComponent.GetListByProductId(customer_target.Id);

            Assert.NotEmpty(journeys);

            foreach (var item in journeys)
            {
                var journey_detail = await journeyComponent.GetJourneyById(item.Id);

                Assert.NotEmpty(journey_detail.Features);
            }

            var features = await featureComponent.GetFeatures(customer_target.Id);

            Assert.NotEmpty(features);

            var securityRisks = await securityComponent.GetRisks(null);

            Assert.NotEmpty(securityRisks);

            var reliabilityThreats = await reliabilityComponent.GetThreats();

            Assert.NotEmpty(reliabilityThreats);


            var reliabilityRisks = await reliabilityComponent.GetRisks(null);

            Assert.NotEmpty(reliabilityRisks);



            ComparisonConfig config = new ComparisonConfig();
            config.IgnoreProperty((SecurityThreatGetRp c) => c.Id);
            config.IgnoreProperty((ReliabilityThreatGetRp c) => c.Id);
            config.MaxDifferences = 5;
            var ThreatsCompare = new CompareLogic(config);

            var targets = await securityComponent.GetThreats();

            foreach (var item in securityThreats)
            {
                var target = targets.Where(e => e.Name == item.Name).Single();
                var temp   = ThreatsCompare.Compare(item, target);
                if (!temp.AreEqual)
                {
                    throw new ApplicationException(target.Name + " " + temp.DifferencesString);
                }
            }

            var reliabilityThreatsRestored = await reliabilityComponent.GetThreats();

            foreach (var item in reliabiltyThreats)
            {
                var target = reliabilityThreatsRestored.Where(e => e.Name == item.Name).Single();
                var temp   = ThreatsCompare.Compare(item, target);
                if (!temp.AreEqual)
                {
                    throw new ApplicationException(target.Name + " " + temp.DifferencesString);
                }
            }
        }
Exemplo n.º 10
0
        private static CompareLogic InitComparitor(bool isObo)
        {
            ComparisonConfig config = new ComparisonConfig();

            config.IgnoreObjectTypes     = true; // To match Enrollee to EnrolleeViewModel
            config.CompareFields         = false;
            config.MaxDifferences        = 100;
            config.IgnoreCollectionOrder = true;

            // Fields considered "minor" changes
            config.IgnoreProperty <Enrollee>(x => x.ContactEmail);
            config.IgnoreProperty <Enrollee>(x => x.ContactPhone);
            config.IgnoreProperty <Enrollee>(x => x.VoicePhone);
            config.IgnoreProperty <Enrollee>(x => x.VoiceExtension);
            if (isObo)
            {
                config.IgnoreProperty <Enrollee>(x => x.Jobs);
            }

            // Ignored fields on models due to the frontend not sending all keys/navigation properties
            config.IgnoreProperty <BaseAuditable>(x => x.CreatedUserId);
            config.IgnoreProperty <BaseAuditable>(x => x.CreatedTimeStamp);
            config.IgnoreProperty <BaseAuditable>(x => x.UpdatedUserId);
            config.IgnoreProperty <BaseAuditable>(x => x.UpdatedTimeStamp);

            config.IgnoreProperty <Certification>(x => x.Id);
            config.IgnoreProperty <Certification>(x => x.Enrollee);
            config.IgnoreProperty <Certification>(x => x.EnrolleeId);
            config.IgnoreProperty <Certification>(x => x.College);
            config.IgnoreProperty <Certification>(x => x.License);
            config.IgnoreProperty <Certification>(x => x.Practice);

            config.IgnoreProperty <Job>(x => x.Id);
            config.IgnoreProperty <Job>(x => x.Enrollee);
            config.IgnoreProperty <Job>(x => x.EnrolleeId);

            config.IgnoreProperty <MailingAddress>(x => x.Id);
            config.IgnoreProperty <MailingAddress>(x => x.Country);
            config.IgnoreProperty <MailingAddress>(x => x.Province);

            config.IgnoreProperty <EnrolleeOrganizationType>(x => x.Id);
            config.IgnoreProperty <EnrolleeOrganizationType>(x => x.Enrollee);
            config.IgnoreProperty <EnrolleeOrganizationType>(x => x.EnrolleeId);
            config.IgnoreProperty <EnrolleeOrganizationType>(x => x.OrganizationType);

            config.IgnoreProperty <SelfDeclaration>(x => x.Id);
            config.IgnoreProperty <SelfDeclaration>(x => x.SelfDeclarationType);
            config.IgnoreProperty <SelfDeclaration>(x => x.EnrolleeId);
            config.IgnoreProperty <SelfDeclaration>(x => x.Enrollee);

            config.IgnoreProperty <SelfDeclarationDocument>(x => x.Id);
            config.IgnoreProperty <SelfDeclarationDocument>(x => x.SelfDeclarationType);
            config.IgnoreProperty <SelfDeclarationDocument>(x => x.EnrolleeId);
            config.IgnoreProperty <SelfDeclarationDocument>(x => x.Enrollee);

            return(new CompareLogic(config));
        }