public void AddMappingToExpiredEntityNotAllowed() { var start = new DateTime(2000, 12, 31); var finish = DateUtility.Round(SystemTime.UtcNow().AddDays(-1)); var entity = new Party(); var d1 = new PartyDetails { Party = 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 PartyMapping { 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 VersionMinValueIfNoDetails() { var party = new Party(); var entity = party as IEntity; Assert.AreEqual(ulong.MinValue, entity.Version, "Version differs"); }
public static void Check(this Party expected, Party candidate) { Assert.AreEqual(expected.Id, candidate.Id, "Id differs"); for (int i = 0; i < expected.Details.Count; i++) { expected.Details[i].Check(candidate.Details[i]); } }
public void AddFirst() { var party = new Party(); var details = new PartyDetails { Validity = DateRange.MaxDateRange }; party.AddDetails(details); Assert.AreEqual(1, party.Details.Count, "Count differs"); Assert.AreSame(details, party.LatestDetails, "Latest differs"); }
public void AddFirst() { var entity = new Party(); var system = new SourceSystem { Name = "Test" }; var mapping = new PartyMapping { System = system, MappingValue = "1", Validity = DateRange.MaxDateRange }; entity.ProcessMapping(mapping); Assert.AreEqual(1, entity.Mappings.Count, "Count differs"); }
public void VersionReportsLatestTimestamp() { var party = new Party(); var details = new PartyDetails() { Id = 12, Name = "Party 1", Timestamp = 34UL.GetVersionByteArray() }; party.AddDetails(details); var entity = party as IEntity; Assert.AreEqual(34UL, entity.Version, "Version differs"); }
public void should_return_the_min_and_max_date_of_all_party_details() { var range1 = new DateRange(DateTime.Today, DateTime.Today.AddDays(2)); var range2 = new DateRange(DateTime.Today.AddDays(2), DateTime.Today.AddDays(4)); var party = new Party(); party.AddDetails(new PartyDetails() { Name = "Rob", Validity = range1 }); party.AddDetails(new PartyDetails() { Name = "Bob", Validity = range2 }); Assert.AreEqual(range1.Start, party.Validity.Start); Assert.AreEqual(range2.Finish, party.Validity.Finish); }
public void AddTwoDifferentSystems() { var entity = new Party(); var s1 = new SourceSystem { Name = "Test" }; var m1 = new PartyMapping { System = s1, MappingValue = "1", Validity = DateRange.MaxDateRange }; var s2 = new SourceSystem { Name = "Bob" }; var m2 = new PartyMapping { System = s2, MappingValue = "1", Validity = DateRange.MaxDateRange }; entity.ProcessMapping(m1); entity.ProcessMapping(m2); Assert.AreEqual(2, entity.Mappings.Count, "Count differs"); }
public void AddingDetailsTrimsMappingToEntityFinish() { var start = new DateTime(2000, 1, 1); var finish = DateUtility.Round(SystemTime.UtcNow()).AddDays(3); var party = new Party(); var m1 = new PartyMapping { Validity = new DateRange(start, DateTime.MaxValue) }; party.ProcessMapping(m1); var d1 = new PartyDetails { Validity = new DateRange(start, finish) }; party.AddDetails(d1); Assert.AreEqual(finish, m1.Validity.Finish, "Mapping finish differs"); }
protected static void Establish_context() { entity = Script.PartyData.CreateBasicEntity(); mapping = new EnergyTrading.Mdm.Contracts.Mapping{ SystemName = "Endur", Identifier = Guid.NewGuid().ToString(), SourceSystemOriginated = false, DefaultReverseInd = false, StartDate = Script.baseDate, EndDate = Script.baseDate.AddDays(2) }; content = HttpContentExtensions.CreateDataContract(mapping); client = new HttpClient(); }
public void AddTwoDetailsCompatibleRanges() { var party = new Party(); var start = new DateTime(2000, 12, 31); var start2 = DateUtility.Round(SystemTime.UtcNow().AddDays(10)); var d1 = new PartyDetails { Validity = new DateRange(start, start2) }; var d2 = new PartyDetails { Validity = new DateRange(start2, start2.AddDays(3)) }; party.AddDetails(d1); party.AddDetails(d2); Assert.AreEqual(2, party.Details.Count, "Count differs"); Assert.AreEqual(start2.Add(-interval), d1.Validity.Finish, "Finish differs"); Assert.AreSame(d2, party.LatestDetails, "Latest differs"); }
public void AddTwoDifferentValidity() { var start = new DateTime(2000, 12, 31); var start2 = new DateTime(2010, 1, 1); var entity = new Party(); var s1 = new SourceSystem { Name = "Test" }; var m1 = new PartyMapping { System = s1, MappingValue = "1", Validity = new DateRange(start, start.AddDays(3)) }; var m2 = new PartyMapping { System = s1, MappingValue = "1", Validity = new DateRange(start2, DateUtility.MaxDate) }; entity.ProcessMapping(m1); entity.ProcessMapping(m2); Assert.AreEqual(2, entity.Mappings.Count, "Count differs"); Assert.AreEqual(start2.Add(-Interval), m1.Validity.Finish, "Finish differs"); }
public void AddTwoDetailsNotContiguous() { var party = new Party(); var start = new DateTime(2000, 12, 31); var start2 = DateUtility.Round(SystemTime.UtcNow().AddDays(20)); var d1 = new PartyDetails { Validity = new DateRange(start, start2) }; var d2 = new PartyDetails { Validity = new DateRange(start2.AddDays(3), start2.AddDays(5)) }; // NB Bypass business rules party.Details.Add(d1); try { party.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.Party>(), It.IsAny<IList<IRule>>())).Returns(true); var service = new PartyService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object); var cd = new EnergyTrading.MDM.Contracts.Sample.PartyDetails { Name = "Party 1" }; var nexus = new EnergyTrading.Mdm.Contracts.SystemData { StartDate = new DateTime(2012, 1, 1) }; var contract = new EnergyTrading.MDM.Contracts.Sample.Party { Details = cd, MdmSystemData = nexus }; var details = new PartyDetails { Id = 2, Name = "Party 1" }; var entity = new Party(); entity.AddDetails(details); repository.Setup(x => x.FindOne<Party>(1)).Returns(entity); // Act service.Update(1, 1, contract); }
public MDM.Party CreateEntityWithTwoDetailsAndTwoMappings() { var endur = repository.Queryable<SourceSystem>().Where(system => system.Name == "Endur").First(); var trayport = repository.Queryable<SourceSystem>().Where(system => system.Name == "Trayport").First(); var entity = new MDM.Party(); baseDate = DateTime.Today.Subtract(new TimeSpan(72, 0, 0)); SystemTime.UtcNow = () => new DateTime(DateTime.Today.Subtract(new TimeSpan(73, 0, 0)).Ticks); this.AddDetailsToEntity(entity, DateTime.MinValue, baseDate); this.AddDetailsToEntity(entity, baseDate, DateTime.MaxValue); SystemTime.UtcNow = () => DateTime.Now; var trayportMapping = new PartyMapping() { MappingValue = Guid.NewGuid().ToString(), System = trayport, Validity = new DateRange(DateTime.MinValue, DateTime.MaxValue) }; var endurMapping = new PartyMapping() { MappingValue = Guid.NewGuid().ToString(), System = endur, IsDefault = true, Validity = new DateRange(DateTime.MinValue, DateTime.MaxValue) }; entity.ProcessMapping(trayportMapping); entity.ProcessMapping(endurMapping); repository.Add(entity); repository.Flush(); return entity; }
public void BringBackValidityOfMostRecentDetail() { var party = new Party(); var start = new DateTime(2000, 12, 31); var start2 = DateUtility.Round(SystemTime.UtcNow().AddDays(20)); var d1 = new PartyDetails { Validity = new DateRange(start, start2), Name = "Detail One" }; var d2 = new PartyDetails { Validity = new DateRange(start, start2), Name = "Detail Two" }; // NB Bypass business rules party.Details.Add(d1); party.AddDetails(d2); int oneDay = 1; d2.Validity = new DateRange(start, start2.Subtract(new TimeSpan(oneDay, 0, 0, 0))); party.AddDetails(d2); Assert.AreEqual(1, party.Details.Count, "There should only be one detail"); Assert.AreEqual(start2.Subtract(new TimeSpan(oneDay, 0, 0, 0)), party.LatestDetails.Validity.Finish, "The finish date should have been updated"); }
public void AttemptUpdateNonExistentMapping() { var details = new PartyDetails { Id = 12, Name = "Party" }; var entity = new Party(); entity.AddDetails(details); var mapping = new PartyMapping { 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 Party(); var s1 = new SourceSystem { Name = "Test" }; var d1 = new PartyDetails { Validity = new DateRange(start, finish) }; var m1 = new PartyMapping { 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"); }
public void UpdateIncompatibleMapping() { var start = new DateTime(2000, 12, 31); var finish = DateUtility.Round(SystemTime.UtcNow().AddDays(5)); var entity = new Party(); var s1 = new SourceSystem { Name = "Test" }; var m1 = new PartyMapping { Id = 12, System = s1, MappingValue = "1", Validity = new DateRange(start, DateUtility.MaxDate) }; var m2 = new PartyMapping { Id = 12, System = s1, MappingValue = "2", Validity = new DateRange(start, finish) }; // NB We deliberately bypasses the business logic m1.Party = entity; entity.Mappings.Add(m1); try { entity.ProcessMapping(m2); } catch (ArgumentOutOfRangeException ex) { Assert.IsTrue(ex.Message.StartsWith("Mapping not compatible")); throw; } }
public void ValidDetailsSaved() { // Arrange var validatorFactory = new Mock<IValidatorEngine>(); var mappingEngine = new Mock<IMappingEngine>(); var repository = new Mock<IRepository>(); var searchCache = new Mock<ISearchCache>(); var service = new PartyService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object); var identifier = new MdmId { SystemName = "Test", Identifier = "A" }; var message = new AmendMappingRequest { MappingId = 12, Mapping = identifier, Version = 34 }; var start = new DateTime(2000, 12, 31); var finish = DateUtility.Round(SystemTime.UtcNow().AddDays(5)); var s1 = new MDM.SourceSystem { Name = "Test" }; var m1 = new PartyMapping { Id = 12, System = s1, MappingValue = "1", Version = 34UL.GetVersionByteArray(), Validity = new DateRange(start, DateUtility.MaxDate) }; var m2 = new PartyMapping { Id = 12, System = s1, MappingValue = "1", Validity = new DateRange(start, finish) }; // NB We deliberately bypasses the business logic var party = new MDM.Party(); m1.Party = party; party.Mappings.Add(m1); validatorFactory.Setup(x => x.IsValid(It.IsAny<AmendMappingRequest>(), It.IsAny<IList<IRule>>())).Returns(true); repository.Setup(x => x.FindOne<PartyMapping>(12)).Returns(m1); mappingEngine.Setup(x => x.Map<EnergyTrading.Mdm.Contracts.MdmId, PartyMapping>(identifier)).Returns(m2); // Act service.UpdateMapping(message); // Assert // NB Don't verify result of Update - already covered by PartyMappingFixture repository.Verify(x => x.Save(party)); repository.Verify(x => x.Flush()); }
public void VersionConflict() { // Arrange var validatorFactory = new Mock<IValidatorEngine>(); var mappingEngine = new Mock<IMappingEngine>(); var repository = new Mock<IRepository>(); var searchCache = new Mock<ISearchCache>(); var service = new PartyService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object); var message = new AmendMappingRequest { MappingId = 12, Mapping = new MdmId { SystemName = "Test", Identifier = "A" }, Version = 34 }; var party = new MDM.Party(); party.AddDetails(new PartyDetails() { Timestamp = BitConverter.GetBytes(25L) }); var mapping = new PartyMapping { Party = party }; validatorFactory.Setup(x => x.IsValid(It.IsAny<AmendMappingRequest>(), It.IsAny<IList<IRule>>())).Returns(true); repository.Setup(x => x.FindOne<PartyMapping>(12)).Returns(mapping); // Act service.UpdateMapping(message); }
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 PartyService(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 PartyMapping { System = system, MappingValue = "A" }; var details = new PartyDetails { Name = "Party 1", Validity = new DateRange(start, finish) }; var party = new Party { Id = 1 }; party.AddDetails(details); party.ProcessMapping(mapping); // Contract details var identifier = new EnergyTrading.Mdm.Contracts.MdmId { SystemName = "Endur", Identifier = "A" }; var cDetails = new EnergyTrading.MDM.Contracts.Sample.PartyDetails { Name = "Party 1" }; mappingEngine.Setup(x => x.Map<PartyMapping, EnergyTrading.Mdm.Contracts.MdmId>(mapping)).Returns(identifier); mappingEngine.Setup(x => x.Map<PartyDetails, EnergyTrading.MDM.Contracts.Sample.PartyDetails>(details)).Returns(cDetails); validatorFactory.Setup(x => x.IsValid(It.IsAny<MappingRequest>(), It.IsAny<IList<IRule>>())).Returns(true); var list = new List<PartyMapping> { mapping }; repository.Setup(x => x.Queryable<PartyMapping>()).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 repository.Verify(x => x.Queryable<PartyMapping>()); Assert.IsTrue(response.IsValid); Assert.IsNotNull(candidate, "Contract null"); mappingEngine.Verify(x => x.Map<PartyMapping, EnergyTrading.Mdm.Contracts.MdmId>(mapping)); mappingEngine.Verify(x => x.Map<PartyDetails, EnergyTrading.MDM.Contracts.Sample.PartyDetails>(details)); 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 AddTwoDetailsStartAndEndSame() { var party = new Party(); var start = new DateTime(2000, 12, 31); var start2 = DateUtility.Round(SystemTime.UtcNow().AddDays(20)); var d1 = new PartyDetails { Validity = new DateRange(start, start2), Name = "Detail One" }; var d2 = new PartyDetails { Validity = new DateRange(start, start2), Name = "Detail Two" }; // NB Bypass business rules party.Details.Add(d1); party.AddDetails(d2); Assert.AreEqual(1, party.Details.Count, "There should only be one detail"); Assert.AreEqual("Detail Two", party.LatestDetails.Name, "The detail name should be updated"); }
public void UpdateMappingAdjustsEndDate() { var start = new DateTime(2000, 12, 31); var finish = DateUtility.Round(SystemTime.UtcNow().AddDays(5)); var entity = new Party(); var s1 = new SourceSystem { Name = "Test" }; var m1 = new PartyMapping { Id = 12, System = s1, MappingValue = "1", Validity = new DateRange(start, DateUtility.MaxDate) }; var m2 = new PartyMapping { Id = 12, System = s1, MappingValue = "1", Validity = new DateRange(start, finish) }; // NB We deliberately bypasses the business logic m1.Party = entity; entity.Mappings.Add(m1); entity.ProcessMapping(m2); Assert.AreEqual(finish, m1.Validity.Finish, "Finish differs"); }
public void AddNull() { var entity = new Party(); entity.ProcessMapping(null); }
public void AddTwoOverlapValidity() { var start = new DateTime(2000, 12, 31); var start2 = new DateTime(2010, 1, 1); var entity = new Party(); var s1 = new SourceSystem { Name = "Test" }; var m1 = new PartyMapping { System = s1, MappingValue = "1", Validity = new DateRange(start, DateUtility.MaxDate) }; var m2 = new PartyMapping { System = s1, MappingValue = "1", Validity = new DateRange(start2, DateUtility.MaxDate) }; var m3 = new PartyMapping { System = s1, MappingValue = "1", Validity = new DateRange(start.AddDays(2), DateUtility.MaxDate) }; entity.ProcessMapping(m1); entity.ProcessMapping(m2); try { entity.ProcessMapping(m3); } catch (ArgumentOutOfRangeException ex) { Assert.IsTrue(ex.Message.StartsWith("Validity range starts on or before start of latest range")); throw; } }
public void AddNull() { var party = new Party(); party.AddDetails(null); }
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 PartyService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object); // Domain details var system = new MDM.SourceSystem { Name = "Endur" }; var mapping = new PartyMapping { System = system, MappingValue = "A", }; var targetSystem = new MDM.SourceSystem { Name = "Trayport" }; var targetMapping = new PartyMapping { System = targetSystem, MappingValue = "B", IsDefault = true }; var details = new MDM.PartyDetails { Name = "Party 1" }; var party = new MDM.Party { Id = 1 }; party.AddDetails(details); party.ProcessMapping(mapping); party.ProcessMapping(targetMapping); // Contract details var targetIdentifier = new MdmId { SystemName = "Trayport", Identifier = "B" }; mappingEngine.Setup(x => x.Map<PartyMapping, MdmId>(targetMapping)).Returns(targetIdentifier); var list = new List<PartyMapping> { mapping }; repository.Setup(x => x.Queryable<PartyMapping>()).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.IsNotNull(candidate, "Mapping null"); Assert.AreEqual(1, candidate.Mappings.Count, "Identifier count incorrect"); Assert.AreSame(targetIdentifier, candidate.Mappings[0], "Different identifier assigned"); }
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.PartyDetails { Name = "Party 1" }; 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.Party { Details = cd, MdmSystemData = nexus }; contract.Identifiers.Add(identifier); // Domain var system = new SourceSystem { Name = "Test" }; var mapping = new PartyMapping { System = system, MappingValue = "A" }; var d1 = new PartyDetails { Id = 1, Name = "Party 1", Timestamp = 74UL.GetVersionByteArray() }; var entity = new Party(); entity.AddDetails(d1); var d2 = new PartyDetails { Name = "Party 1" }; 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.Party>(), It.IsAny<IList<IRule>>())).Returns(true); repository.Setup(x => x.FindOne<Party>(1)).Returns(entity); mappingEngine.Setup(x => x.Map<EnergyTrading.MDM.Contracts.Sample.PartyDetails, PartyDetails>(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, PartyMapping>(identifier)).Returns(mapping); var service = new PartyService(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()); }