/// <summary> /// Add or update a mapping, checking that it exists and that the details are compatible. /// </summary> /// <param name="mapping"></param> public void ProcessMapping(SourceSystemMapping mapping) { this.ProcessMapping(Mappings, mapping, Validity.Finish); }
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.SourceSystemDetails(); 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.SourceSystem { Details = cd, MdmSystemData = nexus }; contract.Identifiers.Add(identifier); // Domain var system = new SourceSystem { Name = "Test" }; var mapping = new SourceSystemMapping { System = system, MappingValue = "A" }; var d1 = ObjectMother.Create<SourceSystem>(); d1.Id = 1; d1.Timestamp = 74UL.GetVersionByteArray(); var entity = ObjectMother.Create<SourceSystem>(); entity.Timestamp = 74UL.GetVersionByteArray(); entity.AddDetails(d1); var d2 = ObjectMother.Create<SourceSystem>(); 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.SourceSystem>(), It.IsAny<IList<IRule>>())).Returns(true); repository.Setup(x => x.FindOne<SourceSystem>(1)).Returns(entity); mappingEngine.Setup(x => x.Map<EnergyTrading.Mdm.Contracts.SourceSystemDetails, SourceSystem>(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, SourceSystemMapping>(identifier)).Returns(mapping); var service = new SourceSystemService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object); // Act service.Update(1, 74, contract); // Assert Assert.AreEqual(0, d2.Mappings.Count, "Created entity mappings count differs"); Assert.AreEqual(0, d2.Id, "Created entity id differs"); Assert.AreEqual(1, entity.Mappings.Count, "Mapping count differs"); repository.Verify(x => x.Save(entity)); repository.Verify(x => x.Flush()); // Ok, hack the created one to align it d2.Id = entity.Id; foreach (var m in entity.Mappings) { d2.Mappings.Add(m); } // Should now be the same - avoid exposing what properties we have here Check(d2, entity); }