public void AddMappingToExpiredEntityNotAllowed() { var start = new DateTime(2000, 12, 31); var finish = DateUtility.Round(SystemTime.UtcNow().AddDays(-1)); var entity = new Person(); var d1 = new PersonDetails { Person = entity, Validity = new DateRange(start, finish) }; // NB Must bypass business rules to set up entity.Details.Add(d1); var s1 = new SourceSystem { Name = "Test" }; var m1 = new PersonMapping { System = s1, MappingValue = "1", Validity = new DateRange(start, DateUtility.MaxDate) }; try { entity.ProcessMapping(m1); } catch (ArgumentOutOfRangeException ex) { Assert.IsTrue(ex.Message.StartsWith("Cannot change mapping for expired entity")); throw; } }
public void Map() { // Arrange var start = new DateTime(2010, 1, 1); var end = DateUtility.MaxDate; var range = new DateRange(start, end); var id = new EnergyTrading.Mdm.Contracts.MdmId { SystemName = "Test", Identifier = "A" }; var contractDetails = new EnergyTrading.MDM.Contracts.Sample.PersonDetails(); var contract = new EnergyTrading.MDM.Contracts.Sample.Person { Identifiers = new EnergyTrading.Mdm.Contracts.MdmIdList { id }, Details = contractDetails, MdmSystemData = new EnergyTrading.Mdm.Contracts.SystemData { StartDate = start, EndDate = end } }; // NB Don't assign validity here, want to prove SUT sets it var personDetails = new PersonDetails(); var mapping = new PersonMapping(); var mappingEngine = new Mock<IMappingEngine>(); mappingEngine.Setup(x => x.Map<EnergyTrading.Mdm.Contracts.MdmId, PersonMapping>(id)).Returns(mapping); mappingEngine.Setup(x => x.Map<EnergyTrading.MDM.Contracts.Sample.PersonDetails, PersonDetails>(contractDetails)).Returns(personDetails); var mapper = new PersonMapper(mappingEngine.Object); // Act var candidate = mapper.Map(contract); // Assert Assert.AreEqual(1, candidate.Details.Count, "Detail count differs"); Assert.AreEqual(1, candidate.Mappings.Count, "Mapping count differs"); Check(range, personDetails.Validity, "Validity differs"); }
public static void Check(this PersonDetails expected, PersonDetails candidate) { Assert.AreEqual(expected.Id, candidate.Id, "Id differs"); Assert.AreEqual(expected.FirstName, candidate.FirstName, "FirstName differs"); Assert.AreEqual(expected.LastName, candidate.LastName, "LastName differs"); Assert.AreEqual(expected.Email, candidate.Email, "Email differs"); expected.Validity.Check(candidate.Validity); }
public void AddFirst() { var person = new Person(); var details = new PersonDetails { Validity = DateRange.MaxDateRange }; person.AddDetails(details); Assert.AreEqual(1, person.Details.Count, "Count differs"); Assert.AreSame(details, person.LatestDetails, "Latest differs"); }
public void VersionReportsLatestTimestamp() { var person = new Person(); var details = new PersonDetails { Id = 12, FirstName = "John", LastName = "Smith", Timestamp = 34UL.GetVersionByteArray() }; person.AddDetails(details); var entity = person as IEntity; Assert.AreEqual(34UL, entity.Version, "Version differs"); }
/// <summary> /// Add a details to the person checking its validity /// </summary> /// <param name="details"></param> public void AddDetails(PersonDetails details) { if (this.ShouldUpdateLatestDetail(this.Details, details)) { this.CopyDetails(details); } else { this.AddDetails(this.Details, details); } // Trim all the mappings that extend past the end of the entity. this.Mappings.TrimMappings(this.Validity.Finish); }
public void AddingDetailsTrimsMappingToEntityFinish() { var start = new DateTime(2000, 1, 1); var finish = DateUtility.Round(SystemTime.UtcNow()).AddDays(3); var person = new Person(); var m1 = new PersonMapping { Validity = new DateRange(start, DateTime.MaxValue) }; person.ProcessMapping(m1); var d1 = new PersonDetails { Validity = new DateRange(start, finish) }; person.AddDetails(d1); Assert.AreEqual(finish, m1.Validity.Finish, "Mapping finish differs"); }
public void AddTwoDetailsCompatibleRanges() { var person = new Person(); var start = new DateTime(2000, 12, 31); var start2 = DateUtility.Round(SystemTime.UtcNow().AddDays(10)); var d1 = new PersonDetails { Validity = new DateRange(start, start2) }; var d2 = new PersonDetails { Validity = new DateRange(start2, start2.AddDays(3)) }; person.AddDetails(d1); person.AddDetails(d2); Assert.AreEqual(2, person.Details.Count, "Count differs"); Assert.AreEqual(start2.Add(-interval), d1.Validity.Finish, "Finish differs"); Assert.AreSame(d2, person.LatestDetails, "Latest differs"); }
public void AddTwoDetailsNotContiguous() { var person = new Person(); var start = new DateTime(2000, 12, 31); var start2 = DateUtility.Round(SystemTime.UtcNow().AddDays(20)); var d1 = new PersonDetails { Validity = new DateRange(start, start2) }; var d2 = new PersonDetails { Validity = new DateRange(start2.AddDays(3), start2.AddDays(5)) }; // NB Bypass business rules person.Details.Add(d1); try { person.AddDetails(d2); } catch (ArgumentOutOfRangeException ex) { Assert.IsTrue(ex.Message.StartsWith("Validity range not contiguous with latest range")); throw; } }
public void EarlierVersionRaisesVersionConflict() { var validatorFactory = new Mock<IValidatorEngine>(); var mappingEngine = new Mock<IMappingEngine>(); var repository = new Mock<IRepository>(); var searchCache = new Mock<ISearchCache>(); validatorFactory.Setup(x => x.IsValid(It.IsAny<EnergyTrading.MDM.Contracts.Sample.Person>(), It.IsAny<IList<IRule>>())).Returns(true); var service = new PersonService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object); var cd = new EnergyTrading.MDM.Contracts.Sample.PersonDetails { Forename = "John", Surname = "Smith", Email = "*****@*****.**" }; var nexus = new EnergyTrading.Mdm.Contracts.SystemData { StartDate = new DateTime(2012, 1, 1) }; var contract = new EnergyTrading.MDM.Contracts.Sample.Person { Details = cd, MdmSystemData = nexus }; var details = new PersonDetails { Id = 2, FirstName = "Bill", LastName = "Jones", Email = "*****@*****.**" }; var entity = new Person(); entity.AddDetails(details); repository.Setup(x => x.FindOne<Person>(1)).Returns(entity); // Act service.Update(1, 1, contract); }
public void BringBackValidityOfMostRecentDetail() { var person = new Person(); var start = new DateTime(2000, 12, 31); var start2 = DateUtility.Round(SystemTime.UtcNow().AddDays(20)); var d1 = new PersonDetails { Validity = new DateRange(start, start2), FirstName = "Detail One", Email = "*****@*****.**" }; var d2 = new PersonDetails { Validity = new DateRange(start, start2), FirstName = "Detail Two", Email = "*****@*****.**" }; // NB Bypass business rules person.Details.Add(d1); person.AddDetails(d2); int oneDay = 1; d2.Validity = new DateRange(start, start2.Subtract(new TimeSpan(oneDay, 0, 0, 0))); person.AddDetails(d2); Assert.AreEqual(1, person.Details.Count, "There should only be one detail"); Assert.AreEqual(start2.Subtract(new TimeSpan(oneDay, 0, 0, 0)), person.LatestDetails.Validity.Finish, "The finish date should have been updated"); }
public void SuccessMatch() { // Arrange var validatorFactory = new Mock<IValidatorEngine>(); var mappingEngine = new Mock<IMappingEngine>(); var repository = new Mock<IRepository>(); var searchCache = new Mock<ISearchCache>(); var service = new PersonService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object); // Domain details var system = new MDM.SourceSystem { Name = "Endur" }; var mapping = new PersonMapping { System = system, MappingValue = "A" }; var targetSystem = new MDM.SourceSystem { Name = "Trayport" }; var targetMapping = new PersonMapping { System = targetSystem, MappingValue = "B", IsDefault = true }; var details = new MDM.PersonDetails { FirstName = "John", LastName = "Smith", Email = "*****@*****.**" }; var person = new MDM.Person { Id = 1 }; person.AddDetails(details); person.ProcessMapping(mapping); person.ProcessMapping(targetMapping); // Contract details var targetIdentifier = new MdmId { SystemName = "Trayport", Identifier = "B" }; mappingEngine.Setup(x => x.Map<PersonMapping, MdmId>(targetMapping)).Returns(targetIdentifier); var list = new List<PersonMapping> { mapping }; repository.Setup(x => x.Queryable<PersonMapping>()).Returns(list.AsQueryable()); var request = new CrossMappingRequest { SystemName = "Endur", Identifier = "A", TargetSystemName = "trayport", ValidAt = SystemTime.UtcNow(), Version = 1 }; // Act var response = service.CrossMap(request); var candidate = response.Contract; // Assert Assert.IsNotNull(response, "Contract null"); Assert.IsTrue(response.IsValid, "Contract invalid"); Assert.IsNotNull(candidate, "Mapping null"); Assert.AreEqual(1, candidate.Mappings.Count, "Identifier count incorrect"); Assert.AreSame(targetIdentifier, candidate.Mappings[0], "Different identifier assigned"); }
public void UpdateNonExistentMapping() { var entity = new Person(); var details = new PersonDetails { Id = 12, FirstName = "John", LastName = "Smith" }; entity.AddDetails(details); var mapping = new PersonMapping { Id = 34 }; entity.ProcessMapping(mapping); }
public void ChangeEndDateConstraintedToEntityValidity() { var start = new DateTime(2000, 12, 31); var finish = DateUtility.Round(SystemTime.UtcNow().AddDays(5)); var entity = new Person(); var d1 = new PersonDetails { Validity = new DateRange(start, finish) }; var s1 = new SourceSystem { Name = "Test" }; var m1 = new PersonMapping { System = s1, MappingValue = "1", Validity = new DateRange(start, DateUtility.MaxDate) }; entity.AddDetails(d1); entity.ProcessMapping(m1); m1.ChangeEndDate(finish.AddDays(5)); Assert.AreEqual(finish, m1.Validity.Finish, "Finish differs"); }
/// <summary> /// Perform the field by field copy operation /// </summary> partial void CopyDetails(PersonDetails details);
public void SuccessMatch() { // Arrange var validatorFactory = new Mock<IValidatorEngine>(); var mappingEngine = new Mock<IMappingEngine>(); var repository = new Mock<IRepository>(); var searchCache = new Mock<ISearchCache>(); var service = new PersonService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object); // Domain details var start = new DateTime(1999, 12, 31); var finish = new DateTime(2020, 1, 1); var system = new SourceSystem { Name = "Endur" }; var mapping = new PersonMapping { System = system, MappingValue = "A" }; var details = new PersonDetails { FirstName = "John", LastName = "Smith", Email = "*****@*****.**", Validity = new DateRange(start, finish) }; var person = new Person { Id = 1 }; person.AddDetails(details); person.ProcessMapping(mapping); // Contract details var identifier = new EnergyTrading.Mdm.Contracts.MdmId { SystemName = "Endur", Identifier = "A" }; var cDetails = new EnergyTrading.MDM.Contracts.Sample.PersonDetails { Forename = "John", Surname = "Smith", Email = "*****@*****.**" }; mappingEngine.Setup(x => x.Map<PersonMapping, EnergyTrading.Mdm.Contracts.MdmId>(mapping)).Returns(identifier); mappingEngine.Setup(x => x.Map<PersonDetails, EnergyTrading.MDM.Contracts.Sample.PersonDetails>(details)).Returns(cDetails); validatorFactory.Setup(x => x.IsValid(It.IsAny<MappingRequest>(), It.IsAny<IList<IRule>>())).Returns(true); var list = new List<PersonMapping> { mapping }; repository.Setup(x => x.Queryable<PersonMapping>()).Returns(list.AsQueryable()); var request = new MappingRequest { SystemName = "Endur", Identifier = "A", ValidAt = SystemTime.UtcNow(), Version = 1 }; // Act var response = service.Map(request); var candidate = response.Contract; // Assert mappingEngine.Verify(x => x.Map<PersonMapping, EnergyTrading.Mdm.Contracts.MdmId>(mapping)); mappingEngine.Verify(x => x.Map<PersonDetails, EnergyTrading.MDM.Contracts.Sample.PersonDetails>(details)); repository.Verify(x => x.Queryable<PersonMapping>()); Assert.IsNotNull(candidate, "Contract null"); Assert.AreEqual(2, candidate.Identifiers.Count, "Identifier count incorrect"); // NB This is order dependent Assert.AreSame(identifier, candidate.Identifiers[1], "Different identifier assigned"); Assert.AreSame(cDetails, candidate.Details, "Different details assigned"); Assert.AreEqual(start, candidate.MdmSystemData.StartDate, "Start date differs"); Assert.AreEqual(finish, candidate.MdmSystemData.EndDate, "End date differs"); }
public void ValidDetailsSaved() { var validatorFactory = new Mock<IValidatorEngine>(); var mappingEngine = new Mock<IMappingEngine>(); var repository = new Mock<IRepository>(); var searchCache = new Mock<ISearchCache>(); // Contract var cd = new EnergyTrading.MDM.Contracts.Sample.PersonDetails { Forename = "John", Surname = "Smith", Email = "*****@*****.**" }; var nexus = new EnergyTrading.Mdm.Contracts.SystemData { StartDate = new DateTime(2012, 1, 1) }; var identifier = new EnergyTrading.Mdm.Contracts.MdmId { SystemName = "Test", Identifier = "A" }; var contract = new EnergyTrading.MDM.Contracts.Sample.Person { Details = cd, MdmSystemData = nexus }; contract.Identifiers.Add(identifier); // Domain var system = new SourceSystem { Name = "Test" }; var mapping = new PersonMapping { System = system, MappingValue = "A" }; var d1 = new PersonDetails { Id = 1, FirstName = "Bill", LastName = "Jones", Email = "*****@*****.**", Timestamp = 74UL.GetVersionByteArray() }; var entity = new Person(); entity.AddDetails(d1); var d2 = new PersonDetails { FirstName = "John", LastName = "Smith", Email = "*****@*****.**" }; var range = new DateRange(new DateTime(2012, 1, 1), DateTime.MaxValue); validatorFactory.Setup(x => x.IsValid(It.IsAny<CreateMappingRequest>(), It.IsAny<IList<IRule>>())).Returns(true); validatorFactory.Setup(x => x.IsValid(It.IsAny<EnergyTrading.MDM.Contracts.Sample.Person>(), It.IsAny<IList<IRule>>())).Returns(true); repository.Setup(x => x.FindOne<Person>(1)).Returns(entity); mappingEngine.Setup(x => x.Map<EnergyTrading.MDM.Contracts.Sample.PersonDetails, PersonDetails>(cd)).Returns(d2); mappingEngine.Setup(x => x.Map<EnergyTrading.Mdm.Contracts.SystemData, DateRange>(nexus)).Returns(range); mappingEngine.Setup(x => x.Map<EnergyTrading.Mdm.Contracts.MdmId, PersonMapping>(identifier)).Returns(mapping); var service = new PersonService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object); // Act service.Update(1, 74, contract); // Assert Assert.AreEqual(2, entity.Details.Count, "Details count differs"); Assert.AreEqual(1, entity.Mappings.Count, "Mapping count differs"); repository.Verify(x => x.Save(entity)); repository.Verify(x => x.Flush()); }