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 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 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 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"); }
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 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"); }