public void ShouldRecalculateFirmHavingClient() { SourceDb.Has(new Facts::Category { Id = 1, Level = 3 }) .Has(new Facts::Project { OrganizationUnitId = 1 }) .Has(new Facts::Client { Id = 1 }) .Has(new Facts::Firm { Id = 1, ClientId = 1, OrganizationUnitId = 1 }); TargetDb.Has(new CI::Firm { Id = 1 }) .Has(new CI::Client { Id = 1 }); Transformation.Create(Query) .Recalculate <CI::Firm>(1) .Verify <CI::Firm>(m => m.Update(It.Is(Predicate.Match(new CI::Firm { Id = 1, ClientId = 1 })))) .Verify <CI::Client>(m => m.Update(It.Is(Predicate.Match(new CI::Client { Id = 1 }))), Times.Never); }
public void ShouldInitializeFirmHavingBalance() { SourceDb.Has(new Facts::Project { Id = 1, OrganizationUnitId = 1 }) .Has(new Facts::Client { Id = 1 }) .Has(new Facts::BranchOfficeOrganizationUnit { Id = 1, OrganizationUnitId = 1 }) .Has(new Facts::LegalPerson { Id = 1, ClientId = 1 }) .Has(new Facts::Account { Id = 1, LegalPersonId = 1, BranchOfficeOrganizationUnitId = 1, Balance = 123.45m }) .Has(new Facts::Firm { Id = 1, ClientId = 1, OrganizationUnitId = 1 }); Transformation.Create(Query) .Initialize <CI::Firm>(1) .Verify <CI::Firm>(m => m.Add(It.Is(Predicate.Match(new CI::Firm { Id = 1, ProjectId = 1, ClientId = 1 })))) .Verify <CI::FirmBalance>(m => m.Add(It.Is(Predicate.Match(new CI::FirmBalance { ProjectId = 1, FirmId = 1, AccountId = 1, Balance = 123.45m })))); }
public void ShouldRecalculateFirmHavingTerritory() { SourceDb.Has(new Facts::Firm { Id = 1 }) .Has(new Facts::FirmAddress { FirmId = 1, TerritoryId = 2 }); TargetDb.Has(new CI::Firm { Id = 1 }) .Has(new CI::FirmTerritory { FirmId = 1, TerritoryId = 3 }); Transformation.Create(Query) .Recalculate <CI::Firm>(1) .Verify <CI::FirmTerritory>(m => m.Add(It.Is(Predicate.Match(new CI::FirmTerritory { FirmId = 1, TerritoryId = 2 })))) .Verify <CI::FirmTerritory>(m => m.Delete(It.Is(Predicate.Match(new CI::FirmTerritory { FirmId = 1, TerritoryId = 3 })))); }
public void ShouldTransformFirmContact() { const long NotNull = 123; SourceDb.Has( new Erm::FirmContact { Id = 1, ContactType = 1, FirmAddressId = NotNull }, new Erm::FirmContact { Id = 2, ContactType = 1, FirmAddressId = null }, new Erm::FirmContact { Id = 3, ContactType = 2, FirmAddressId = NotNull }, new Erm::FirmContact { Id = 4, ContactType = 4, FirmAddressId = NotNull }); Transformation.Create(Query) .VerifyTransform(x => Specs.Map.Erm.ToFacts.FirmContacts.Map(x).ById(1), new Facts::FirmContact { Id = 1, HasPhone = true, FirmAddressId = NotNull }) .VerifyTransform(x => Specs.Map.Erm.ToFacts.FirmContacts.Map(x).ById(2), Enumerable.Empty <Facts::FirmContact>()) .VerifyTransform(x => Specs.Map.Erm.ToFacts.FirmContacts.Map(x).ById(3), Enumerable.Empty <Facts::FirmContact>()) .VerifyTransform(x => Specs.Map.Erm.ToFacts.FirmContacts.Map(x).ById(4), new Facts::FirmContact { Id = 4, HasWebsite = true, FirmAddressId = NotNull }); }
public void ShouldRecalculateFirmIfBranchOfficeOrganizationUnitUpdated() { SourceDb.Has(new Erm::BranchOfficeOrganizationUnit { Id = 1, OrganizationUnitId = 2 }); TargetDb.Has(new Facts::Firm { Id = 1, ClientId = 1, OrganizationUnitId = 1 }) .Has(new Facts::Firm { Id = 2, ClientId = 1, OrganizationUnitId = 2 }) .Has(new Facts::Client { Id = 1 }) .Has(new Facts::BranchOfficeOrganizationUnit { Id = 1, OrganizationUnitId = 1 }) .Has(new Facts::LegalPerson { Id = 1, ClientId = 1 }) .Has(new Facts::Account { Id = 1, LegalPersonId = 1, BranchOfficeOrganizationUnitId = 1 }); Transformation.Create(Query, RepositoryFactory) .ApplyChanges <Facts::BranchOfficeOrganizationUnit>(1) .VerifyDistinct(Aggregate.Recalculate <CI.Firm>(1), Aggregate.Recalculate <CI.Firm>(2)); }
public void ShouldRecalculateClientAndFirmIfCategoryFirmAddressUpdated() { SourceDb.Has(new Erm::CategoryFirmAddress { Id = 1, FirmAddressId = 1, CategoryId = 1 }) .Has(new Erm::FirmAddress { Id = 1, FirmId = 1 }) .Has(new Erm::Firm { Id = 1, OrganizationUnitId = 1, ClientId = 1 }) .Has(new Erm::Client { Id = 1 }); TargetDb.Has(new Facts::CategoryFirmAddress { Id = 1, FirmAddressId = 1, CategoryId = 1 }); TargetDb.Has(new Facts::FirmAddress { Id = 1, FirmId = 1 }); TargetDb.Has(new Facts::Firm { Id = 1, OrganizationUnitId = 1, ClientId = 1 }); TargetDb.Has(new Facts::Client { Id = 1 }); Transformation.Create(Query, RepositoryFactory) .ApplyChanges <Facts::CategoryFirmAddress>(1) .VerifyDistinct(Aggregate.Recalculate <CI::Firm>(1), Aggregate.Recalculate <CI::Client>(1)); }
public void ShouldRecalculateFirmHavingCategory() { SourceDb.Has(new Facts::Category { Id = 1, Level = 3 }, new Facts::Category { Id = 2, Level = 3 }); SourceDb.Has(new Facts::CategoryOrganizationUnit { Id = 1, CategoryId = 1, OrganizationUnitId = 1 }, new Facts::CategoryOrganizationUnit { Id = 2, CategoryId = 2, OrganizationUnitId = 1 }); SourceDb.Has(new Facts::Project { OrganizationUnitId = 1 }); SourceDb.Has(new Facts::FirmAddress { Id = 1, FirmId = 1 }, new Facts::FirmAddress { Id = 2, FirmId = 2 }); SourceDb.Has(new Facts::CategoryFirmAddress { Id = 1, FirmAddressId = 1, CategoryId = 1 }, new Facts::CategoryFirmAddress { Id = 2, FirmAddressId = 2, CategoryId = 2 }); SourceDb.Has(new Facts::Firm { Id = 1, OrganizationUnitId = 1 }, new Facts::Firm { Id = 2, OrganizationUnitId = 1 }, new Facts::Firm { Id = 3, OrganizationUnitId = 1 }); TargetDb.Has(new CI::Firm { Id = 1 }, new CI::Firm { Id = 2 }, new CI::Firm { Id = 3 }) .Has(new CI::FirmCategory { FirmId = 2, CategoryId = 1 }, new CI::FirmCategory { FirmId = 3, CategoryId = 1 }); Transformation.Create(Query) .Recalculate<CI::Firm>(1) .Recalculate<CI::Firm>(2) .Recalculate<CI::Firm>(3) .Verify<CI::Firm>(m => m.Update(It.Is(Predicate.Match(new CI::Firm { Id = 1, AddressCount = 1 })))) .Verify<CI::Firm>(m => m.Update(It.Is(Predicate.Match(new CI::Firm { Id = 2, AddressCount = 1 })))) .Verify<CI::Firm>(m => m.Update(It.Is(Predicate.Match(new CI::Firm { Id = 3 })))) .Verify<CI::FirmCategory>(m => m.Add(It.Is(Predicate.Match(new CI::FirmCategory { FirmId = 1, CategoryId = 1 })))) .Verify<CI::FirmCategory>(m => m.Add(It.Is(Predicate.Match(new CI::FirmCategory { FirmId = 2, CategoryId = 2 })))) .Verify<CI::FirmCategory>(m => m.Delete(It.Is(Predicate.Match(new CI::FirmCategory { FirmId = 2, CategoryId = 1 })))) .Verify<CI::FirmCategory>(m => m.Delete(It.Is(Predicate.Match(new CI::FirmCategory { FirmId = 3, CategoryId = 1 })))); }
public void ShouldRecalculateFirmIfContactUpdated() { SourceDb.Has(new Erm::Contact { Id = 1, ClientId = 2 }); TargetDb.Has(new Facts::Client { Id = 1 }) .Has(new Facts::Client { Id = 2 }) .Has(new Facts::Firm { Id = 1, ClientId = 1 }) .Has(new Facts::Firm { Id = 2, ClientId = 2 }) .Has(new Facts::Contact { Id = 1, ClientId = 1 }); Transformation.Create(Query, RepositoryFactory) .ApplyChanges <Facts::Contact>(1) .VerifyDistinct(Aggregate.Recalculate <CI.Client>(1), Aggregate.Recalculate <CI.Firm>(1), Aggregate.Recalculate <CI.Client>(2), Aggregate.Recalculate <CI.Firm>(2)); }
public void ShouldRecalculateDependentAggregatesIfProjectUpdated() { SourceDb.Has(new Erm::Project { Id = 1, OrganizationUnitId = 2 }); TargetDb.Has(new Facts::Project { Id = 1, OrganizationUnitId = 1 }) .Has(new Facts::Territory { Id = 1, OrganizationUnitId = 1 }) .Has(new Facts::Territory { Id = 2, OrganizationUnitId = 2 }) .Has(new Facts::Firm { Id = 1, OrganizationUnitId = 1 }) .Has(new Facts::Firm { Id = 2, OrganizationUnitId = 2 }); Transformation.Create(Query, RepositoryFactory) .ApplyChanges <Facts::Project>(1) .VerifyDistinct(Statistics.Operation(1), Aggregate.Recalculate <CI::Territory>(1), Aggregate.Recalculate <CI::Firm>(1), Aggregate.Recalculate <CI::Project>(1), Aggregate.Recalculate <CI::Territory>(2), Aggregate.Recalculate <CI::Firm>(2)); }
public void ShouldRecalculateFirmHavingBalance() { SourceDb.Has(new Facts::Project { Id = 1, OrganizationUnitId = 1 }) .Has(new Facts::Client { Id = 1 }, new Facts::Client { Id = 2 }) .Has(new Facts::BranchOfficeOrganizationUnit { Id = 1, OrganizationUnitId = 1 }) .Has(new Facts::LegalPerson { Id = 1, ClientId = 1 }, new Facts::LegalPerson { Id = 2, ClientId = 2 }) .Has(new Facts::Account { Id = 1, LegalPersonId = 1, BranchOfficeOrganizationUnitId = 1, Balance = 123 }, new Facts::Account { Id = 2, LegalPersonId = 2, BranchOfficeOrganizationUnitId = 1, Balance = 456 }) .Has(new Facts::Firm { Id = 1, ClientId = 1, OrganizationUnitId = 1 }, new Facts::Firm { Id = 2, ClientId = 2, OrganizationUnitId = 1 }, new Facts::Firm { Id = 3, OrganizationUnitId = 1 }); TargetDb.Has(new CI::Firm { Id = 1 }, new CI::Firm { Id = 2 }, new CI::Firm { Id = 3 }) .Has(new CI::FirmBalance { FirmId = 2, AccountId = 2, ProjectId = 1, Balance = 123 }, new CI::FirmBalance { FirmId = 3, ProjectId = 1, Balance = 123 }); Transformation.Create(Query) .Recalculate<CI::Firm>(1, 2, 3) .Verify<CI::Firm>(m => m.Update(It.Is(Predicate.Match(new CI::Firm { Id = 1, ClientId = 1, ProjectId = 1 })))) .Verify<CI::Firm>(m => m.Update(It.Is(Predicate.Match(new CI::Firm { Id = 2, ClientId = 2, ProjectId = 1 })))) .Verify<CI::Firm>(m => m.Update(It.Is(Predicate.Match(new CI::Firm { Id = 3, ProjectId = 1 })))) .Verify<CI::FirmBalance>(m => m.Add(It.Is(Predicate.Match(new CI::FirmBalance { FirmId = 1, AccountId = 1, ProjectId = 1, Balance = 123 })))) .Verify<CI::FirmBalance>(m => m.Update(It.Is(Predicate.Match(new CI::FirmBalance { FirmId = 2, AccountId = 2, ProjectId = 1, Balance = 456 })))) .Verify<CI::FirmBalance>(m => m.Delete(It.Is(Predicate.Match(new CI::FirmBalance { FirmId = 3, ProjectId = 1, Balance = 123 })))); }
public void ShouldFillCategoriesWithoutStatisticsWithZeros() { SourceDb.Has(new Bit::FirmCategory { FirmId = 1, CategoryId = 1, ProjectId = 1 }); // Фирма без статистики SourceDb.Has(new Bit::FirmCategory { FirmId = 2, CategoryId = 1, ProjectId = 1 }); // Фирма со статистикой SourceDb.Has(new Bit::FirmCategoryStatistics { FirmId = 2, CategoryId = 1, ProjectId = 1, Hits = 100, Shows = 200 }); SourceDb.Has(new Bit::ProjectCategoryStatistics { ProjectId = 1, CategoryId = 1, AdvertisersCount = 1 }); Transformation.Create(Query) .VerifyTransform( x => Specs.Map.Facts.ToStatistics.FirmCategoryStatistics.Map(x), Inquire( new Statistics::FirmCategoryStatistics { FirmId = 1, CategoryId = 1, ProjectId = 1, AdvertisersShare = 0.5f, FirmCount = 2, Hits = 0, Shows = 0 }, new Statistics::FirmCategoryStatistics { FirmId = 2, CategoryId = 1, ProjectId = 1, AdvertisersShare = 0.5f, FirmCount = 2, Hits = 100, Shows = 200 })); }
public void ShouldTransformFirmCategoryStatistics() { SourceDb.Has(new Bit::FirmCategory { FirmId = 1, CategoryId = 1, ProjectId = 1 }, new Bit::FirmCategory { FirmId = 2, CategoryId = 1, ProjectId = 1 }, new Bit::FirmCategory { FirmId = 2, CategoryId = 2, ProjectId = 1 }) .Has(new Bit::FirmCategoryStatistics { FirmId = 1, CategoryId = 1, ProjectId = 1, Hits = 10000, Shows = 20000 }) .Has(new Bit::ProjectCategoryStatistics { ProjectId = 1, CategoryId = 1, AdvertisersCount = 1 }); Transformation.Create(Query) .VerifyTransform( x => Specs.Map.Facts.ToStatistics.FirmCategoryStatistics.Map(x), Inquire( new Statistics::FirmCategoryStatistics { FirmId = 1, CategoryId = 1, ProjectId = 1, AdvertisersShare = 0.5f, FirmCount = 2, Hits = 10000, Shows = 20000 }, new Statistics::FirmCategoryStatistics { FirmId = 2, CategoryId = 1, ProjectId = 1, AdvertisersShare = 0.5f, FirmCount = 2, Hits = 0, Shows = 0 }, new Statistics::FirmCategoryStatistics { FirmId = 2, CategoryId = 2, ProjectId = 1, AdvertisersShare = 0f, FirmCount = 1, Hits = 0, Shows = 0 })); }
public void ShouldRecalculateFirmIfCategoryOfLevel1Updated() { SourceDb.Has(new Erm::Firm { Id = 1 }) .Has(new Erm::FirmAddress { Id = 1, FirmId = 1 }) .Has(new Erm::Category { Id = 1, Level = 1 }); TargetDb.Has(new Facts::Firm { Id = 1 }) .Has(new Facts::FirmAddress { Id = 1, FirmId = 1 }) .Has(new Facts::CategoryFirmAddress { Id = 1, FirmAddressId = 1, CategoryId = 3 }) .Has(new Facts::Category { Id = 1, Level = 1 }) .Has(new Facts::Category { Id = 2, Level = 2, ParentId = 1 }) .Has(new Facts::Category { Id = 3, Level = 3, ParentId = 2 }); Transformation.Create(Query, RepositoryFactory) .ApplyChanges <Facts::Category>(1) .VerifyDistinct(Aggregate.Recalculate <CI.Firm>(1)); }
public void ShouldRecalculateFirmsIfActivityCreated() { SourceDb.Has(new Appointment { Id = 1, ModifiedOn = DateTimeOffset.Now, IsActive = true, Status = ActivityStatusCompleted }) .Has(new AppointmentReference { ActivityId = 1, Reference = RegardingObjectReference, ReferencedObjectId = 2, ReferencedType = EntityTypeIds.Client }, new AppointmentReference { ActivityId = 1, Reference = RegardingObjectReference, ReferencedObjectId = 3, ReferencedType = EntityTypeIds.Firm }); TargetDb.Has(new Facts::Client { Id = 2 }); TargetDb.Has(new Facts::Firm { Id = 3 }); TargetDb.Has(new Facts::Firm { Id = 4, ClientId = 2 }); TargetDb.Has(new Facts::Firm { Id = 5 }); Transformation.Create(Query, RepositoryFactory) .ApplyChanges <Facts::Activity>(1) .VerifyDistinct(Aggregate.Recalculate <CI::Firm>(3), Aggregate.Recalculate <CI::Firm>(4)); }
public void ShouldTransformContact() { SourceDb.Has( new Erm::Contact { Id = 1, ClientId = 2 }, new Erm::Contact { Id = 2, Role = 200000 }, new Erm::Contact { Id = 3, Role = 200001 }, new Erm::Contact { Id = 4, Role = 200002 }, new Erm::Contact { Id = 5, MainPhoneNumber = "phone" }, new Erm::Contact { Id = 6, MobilePhoneNumber = "phone" }, new Erm::Contact { Id = 7, HomePhoneNumber = "phone" }, new Erm::Contact { Id = 8, AdditionalPhoneNumber = "phone" }, new Erm::Contact { Id = 9, Website = "site" }); Transformation.Create(Query) .VerifyTransform(x => Specs.Map.Erm.ToFacts.Contacts.Map(x).ById(1), new Facts::Contact { Id = 1, ClientId = 2 }) .VerifyTransform(x => Specs.Map.Erm.ToFacts.Contacts.Map(x).ById(2), new Facts::Contact { Id = 2, Role = 1 }) .VerifyTransform(x => Specs.Map.Erm.ToFacts.Contacts.Map(x).ById(3), new Facts::Contact { Id = 3, Role = 2 }) .VerifyTransform(x => Specs.Map.Erm.ToFacts.Contacts.Map(x).ById(4), new Facts::Contact { Id = 4, Role = 3 }) .VerifyTransform(x => Specs.Map.Erm.ToFacts.Contacts.Map(x).ById(5), new Facts::Contact { Id = 5, HasPhone = true }) .VerifyTransform(x => Specs.Map.Erm.ToFacts.Contacts.Map(x).ById(6), new Facts::Contact { Id = 6, HasPhone = true }) .VerifyTransform(x => Specs.Map.Erm.ToFacts.Contacts.Map(x).ById(7), new Facts::Contact { Id = 7, HasPhone = true }) .VerifyTransform(x => Specs.Map.Erm.ToFacts.Contacts.Map(x).ById(8), new Facts::Contact { Id = 8, HasPhone = true }) .VerifyTransform(x => Specs.Map.Erm.ToFacts.Contacts.Map(x).ById(9), new Facts::Contact { Id = 9, HasWebsite = true }); }
private void ShouldReadActivity <T>(Func <IQuery, IReadOnlyCollection <long>, IEnumerable <T> > func) where T : ActivityBase, new() { const int ActivityStatusCompleted = 2; SourceDb.Has(new T { Id = 1, IsActive = true, IsDeleted = false, Status = ActivityStatusCompleted }) .Has(new T { Id = 2, IsActive = false, IsDeleted = false, Status = ActivityStatusCompleted }) .Has(new T { Id = 3, IsActive = true, IsDeleted = true, Status = ActivityStatusCompleted }) .Has(new T { Id = 4, IsActive = true, IsDeleted = false, Status = 0 }); Reader.Create(Query) .VerifyRead(x => func(x, new[] { 1L }), Inquire(new T { Id = 1, IsActive = true, IsDeleted = false, Status = ActivityStatusCompleted })) .VerifyRead(x => func(x, new[] { 2L }), Inquire <T>()) .VerifyRead(x => func(x, new[] { 3L }), Inquire <T>()) .VerifyRead(x => func(x, new[] { 4L }), Inquire <T>()); }
private void ShouldReadActivityReference <TReference>(Func <IQuery, IEnumerable <TReference> > clientsRefs, Func <IQuery, IEnumerable <TReference> > firmsRefs) where TReference : ActivityReference, new() { const int ReferenceRegardingObject = 1; SourceDb.Has(new TReference { Reference = ReferenceRegardingObject, ReferencedType = EntityTypeIds.Firm }) .Has(new TReference { Reference = 0, ReferencedType = EntityTypeIds.Firm }) .Has(new TReference { Reference = ReferenceRegardingObject, ReferencedType = EntityTypeIds.Client }) .Has(new TReference { Reference = 0, ReferencedType = EntityTypeIds.Client }) .Has(new TReference { Reference = ReferenceRegardingObject, ReferencedType = 0 }) .Has(new TReference { Reference = 0, ReferencedType = 0 }); Reader.Create(Query) .VerifyRead(clientsRefs, Inquire(new TReference { Reference = ReferenceRegardingObject, ReferencedType = EntityTypeIds.Client })) .VerifyRead(firmsRefs, Inquire(new TReference { Reference = ReferenceRegardingObject, ReferencedType = EntityTypeIds.Firm })); }
public void AdvertisersShareShouldNotBeMoreThanOne() { SourceDb.Has(new Facts::Project { Id = 1 }) .Has(new Facts::Firm { Id = 1 }) .Has(new Facts::FirmAddress { Id = 1, FirmId = 1 }) .Has(new Facts::Category { Id = 1 }) .Has(new Facts::CategoryFirmAddress { FirmAddressId = 1, CategoryId = 1 }); SourceDb.Has(new Bit::FirmCategoryStatistics { FirmId = 1, CategoryId = 1, ProjectId = 1, Hits = 10000, Shows = 20000 }) .Has(new Bit::ProjectCategoryStatistics { ProjectId = 1, CategoryId = 1, AdvertisersCount = 5 }); Transformation.Create(Query) .VerifyTransform( x => Specs.Map.Facts.ToStatistics.FirmCategory3.Map(x), Inquire(new Statistics::FirmCategory3 { FirmId = 1, CategoryId = 1, ProjectId = 1, AdvertisersShare = 1f, FirmCount = 1, Hits = 10000, Shows = 20000 })); }
public void ShouldTransformFirmContactInfoFromFirm() { SourceDb.Has(new Facts::Project { Id = 1, OrganizationUnitId = 0 }) .Has(new Facts::Firm { Id = 1, Name = "has no addresses" }, new Facts::Firm { Id = 2, Name = "has addresses, but no contacts" }, new Facts::Firm { Id = 3, Name = "has one phone contact" }, new Facts::Firm { Id = 4, Name = "has one website contact" }, new Facts::Firm { Id = 5, Name = "has an unknown contact" }) .Has(new Facts::FirmAddress { Id = 1, FirmId = 2 }, new Facts::FirmAddress { Id = 2, FirmId = 3 }, new Facts::FirmAddress { Id = 3, FirmId = 4 }, new Facts::FirmAddress { Id = 4, FirmId = 5 }) .Has(new Facts::FirmContact { Id = 1, HasPhone = true, FirmAddressId = 2 }, new Facts::FirmContact { Id = 2, HasWebsite = true, FirmAddressId = 3 }, new Facts::FirmContact { Id = 3, FirmAddressId = 4 }); Transformation.Create(Query) .VerifyTransform(x => Specs.Map.Facts.ToCI.Firms.Map(x).ById(1), Inquire(new CI::Firm { HasPhone = false, HasWebsite = false }), x => new { x.HasPhone, x.HasWebsite }) .VerifyTransform(x => Specs.Map.Facts.ToCI.Firms.Map(x).ById(2), Inquire(new CI::Firm { HasPhone = false, HasWebsite = false }), x => new { x.HasPhone, x.HasWebsite }) .VerifyTransform(x => Specs.Map.Facts.ToCI.Firms.Map(x).ById(3), Inquire(new CI::Firm { HasPhone = true, HasWebsite = false }), x => new { x.HasPhone, x.HasWebsite }) .VerifyTransform(x => Specs.Map.Facts.ToCI.Firms.Map(x).ById(4), Inquire(new CI::Firm { HasPhone = false, HasWebsite = true }), x => new { x.HasPhone, x.HasWebsite }) .VerifyTransform(x => Specs.Map.Facts.ToCI.Firms.Map(x).ById(5), Inquire(new CI::Firm { HasPhone = false, HasWebsite = false }), x => new { x.HasPhone, x.HasWebsite }); }
public void ShouldInitializeCategoryGroup() { SourceDb.Has(new Facts::CategoryGroup { Id = 1 }); Transformation.Create(Query) .Initialize<CI::CategoryGroup>(1) .Verify<CI::CategoryGroup>(m => m.Add(It.Is(Predicate.Match(new CI::CategoryGroup { Id = 1 })))); }
public void ShouldInitializeProject() { SourceDb.Has(new Facts::Project { Id = 1 }); Transformation.Create(Query) .Initialize<CI::Project>(1) .Verify<CI::Project>(m => m.Add(It.Is(Predicate.Match(new CI::Project { Id = 1 })))); }
public void CommonFilteringTests <T>(T entity, FindSpecification <T> specification, bool expected) where T : class, IErmObject { SourceDb.Has(entity); Reader.Create(Query) .Verify(x => x.For(specification).Any(), expected); }
public void ShouldInitializeFirm() { SourceDb.Has(new Facts::Project { OrganizationUnitId = 1 }) .Has(new Facts::Firm { Id = 1, OrganizationUnitId = 1 }); Transformation.Create(Query) .Initialize<CI::Firm>(1) .Verify<CI::Firm>(m => m.Add(It.Is(Predicate.Match(new CI::Firm { Id = 1 })))); }
public void ShouldRecalculateClient() { SourceDb.Has(new Facts::Client { Id = 1, Name = "new name" }); TargetDb.Has(new CI::Client { Id = 1, Name = "old name" }); Transformation.Create(Query) .Recalculate<CI::Client>(1) .Verify<CI::Client>(m => m.Update(It.Is(Predicate.Match(new CI::Client { Id = 1, Name = "new name" })))); }
public void ShouldInitializeTerritory() { SourceDb.Has(new Facts::Project { Id = 1, OrganizationUnitId = 1 }) .Has(new Facts::Territory { Id = 2, OrganizationUnitId = 1 }); Transformation.Create(Query) .Initialize<CI::Territory>(2) .Verify<CI::Territory>(m => m.Add(It.Is(Predicate.Match(new CI::Territory { Id = 2, ProjectId = 1 })))); }
private void ShouldTransform <TActivity, TActivityReference>() where TActivity : Erm::ActivityBase, new() where TActivityReference : Erm::ActivityReference, new() { const int ActivityStatusCompleted = 2; const int RegardingObjectReference = 1; const long FirmId = 111; const long ClientId = 222; var date = DateTimeOffset.Parse("2015-01-01"); SourceDb.Has(new TActivity { Id = 1, ModifiedOn = date, IsActive = true, Status = ActivityStatusCompleted }, new TActivity { Id = 2, ModifiedOn = date, IsActive = true, Status = ActivityStatusCompleted }, new TActivity { Id = 3, ModifiedOn = date, IsActive = true, Status = ActivityStatusCompleted }, new TActivity { Id = 4, ModifiedOn = date, IsActive = true, Status = ActivityStatusCompleted }) .Has(new TActivityReference { ActivityId = 1, Reference = RegardingObjectReference, ReferencedObjectId = ClientId, ReferencedType = EntityTypeIds.Client }, new TActivityReference { ActivityId = 1, Reference = RegardingObjectReference, ReferencedObjectId = FirmId, ReferencedType = EntityTypeIds.Firm }, new TActivityReference { ActivityId = 2, Reference = RegardingObjectReference, ReferencedObjectId = FirmId, ReferencedType = EntityTypeIds.Firm }, new TActivityReference { ActivityId = 3, Reference = RegardingObjectReference, ReferencedObjectId = ClientId, ReferencedType = EntityTypeIds.Client }); Assert.That(Specs.Map.Erm.ToFacts.Activities.Map(Query).ById(1).Count(), Is.EqualTo(1)); Assert.That(Specs.Map.Erm.ToFacts.Activities.Map(Query).ById(1).Single().ClientId, Is.EqualTo(ClientId)); Assert.That(Specs.Map.Erm.ToFacts.Activities.Map(Query).ById(1).Single().FirmId, Is.EqualTo(FirmId)); Assert.That(Specs.Map.Erm.ToFacts.Activities.Map(Query).ById(1).Single().ModifiedOn, Is.EqualTo(date)); Assert.That(Specs.Map.Erm.ToFacts.Activities.Map(Query).ById(2).Count(), Is.EqualTo(1)); Assert.That(Specs.Map.Erm.ToFacts.Activities.Map(Query).ById(2).Single().ClientId, Is.Null); Assert.That(Specs.Map.Erm.ToFacts.Activities.Map(Query).ById(2).Single().FirmId, Is.EqualTo(FirmId)); Assert.That(Specs.Map.Erm.ToFacts.Activities.Map(Query).ById(2).Single().ModifiedOn, Is.EqualTo(date)); Assert.That(Specs.Map.Erm.ToFacts.Activities.Map(Query).ById(3).Count(), Is.EqualTo(1)); Assert.That(Specs.Map.Erm.ToFacts.Activities.Map(Query).ById(3).Single().ClientId, Is.EqualTo(ClientId)); Assert.That(Specs.Map.Erm.ToFacts.Activities.Map(Query).ById(3).Single().FirmId, Is.Null); Assert.That(Specs.Map.Erm.ToFacts.Activities.Map(Query).ById(3).Single().ModifiedOn, Is.EqualTo(date)); Assert.That(Specs.Map.Erm.ToFacts.Activities.Map(Query).ById(4).Count(), Is.EqualTo(1)); Assert.That(Specs.Map.Erm.ToFacts.Activities.Map(Query).ById(4).Single().ClientId, Is.Null); Assert.That(Specs.Map.Erm.ToFacts.Activities.Map(Query).ById(4).Single().FirmId, Is.Null); Assert.That(Specs.Map.Erm.ToFacts.Activities.Map(Query).ById(4).Single().ModifiedOn, Is.EqualTo(date)); }
public void ShouldInitializeClientHavingContact() { SourceDb.Has(new Facts::Client { Id = 1 }) .Has(new Facts::Contact { Id = 1, ClientId = 1 }); Transformation.Create(Query) .Initialize<CI::Client>(1) .Verify<CI::Client>(m => m.Add(It.Is(Predicate.Match(new CI::Client { Id = 1 })))) .Verify<CI::ClientContact>(m => m.Add(It.Is(Predicate.Match(new CI::ClientContact { ClientId = 1, ContactId = 1 })))); }
public void ShouldInitializeClientIfClientCreated() { SourceDb.Has(new Erm::Client { Id = 1 }); Transformation.Create(Query, RepositoryFactory) .ApplyChanges <Facts::Client>(1) .VerifyDistinct(Aggregate.Initialize <CI.Client>(1)); }
public void ShouldInitializeTerritoryIfTerritoryCreated() { SourceDb.Has(new Erm::Territory { Id = 1, OrganizationUnitId = 2 }); Transformation.Create(Query, RepositoryFactory) .ApplyChanges <Facts::Territory>(1) .VerifyDistinct(Aggregate.Initialize <CI::Territory>(1)); }
public void ShouldProcessFactAccordingToPriority() { //arrange var factProcessor = new Mock <IFactProcessor>(); factProcessor.Setup(x => x.ApplyChanges(It.IsAny <IReadOnlyCollection <long> >())) .Returns(new IOperation[0]); var provider = new MetadataProvider(new[] { new FactsReplicationMetadataSource() }, new IMetadataProcessor[0]); var factoryInvocationOrder = new List <Type>(); var factProcessorFactory = new Mock <IFactProcessorFactory>(); factProcessorFactory.Setup(x => x.Create(It.IsAny <IMetadataElement>())) .Callback <IMetadataElement>(element => { var type = element.GetType().GenericTypeArguments[0]; factoryInvocationOrder.Add(type); }) .Returns(factProcessor.Object); var transformation = new FactsReplicator(Mock.Of <ITracer>(), Mock.Of <IReplicationSettings>(), provider, factProcessorFactory.Object, new CustomerIntelligenceFactTypePriorityComparer()); SourceDb.Has(new Erm::Firm { Id = 2 }) .Has(new Erm::FirmAddress { Id = 1, FirmId = 1 }, new Erm::FirmAddress { Id = 2, FirmId = 2 }); TargetDb.Has(new Facts::Firm { Id = 1 }); var inputOperations = new[] { new FactOperation(typeof(Facts::FirmAddress), 1), new FactOperation(typeof(Facts::Firm), 2), new FactOperation(typeof(Facts::FirmAddress), 2), }; //act transformation.Replicate(inputOperations); //assert Assert.That(factoryInvocationOrder.Count, Is.EqualTo(2)); Assert.That(factoryInvocationOrder[0], Is.EqualTo(typeof(Facts::Firm))); Assert.That(factoryInvocationOrder[1], Is.EqualTo(typeof(Facts::FirmAddress))); }