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.SourceSystem>(), It.IsAny<IList<IRule>>())).Returns(true); var service = new SourceSystemService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object); var cd = new EnergyTrading.Mdm.Contracts.SourceSystemDetails(); var nexus = new EnergyTrading.Mdm.Contracts.SystemData { StartDate = new DateTime(2012, 1, 1) }; var contract = new EnergyTrading.Mdm.Contracts.SourceSystem { Details = cd, MdmSystemData = nexus }; var details = ObjectMother.Create<SourceSystem>(); details.Id = 1; var entity = ObjectMother.Create<SourceSystem>(); entity.Id = 2; entity.AddDetails(details); repository.Setup(x => x.FindOne<SourceSystem>(1)).Returns(entity); // Act service.Update(1, 1, contract); }
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.SourceSystem>(), It.IsAny <IList <IRule> >())).Returns(true); var service = new SourceSystemService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object); var cd = new EnergyTrading.Mdm.Contracts.SourceSystemDetails(); var nexus = new EnergyTrading.Mdm.Contracts.SystemData { StartDate = new DateTime(2012, 1, 1) }; var contract = new EnergyTrading.Mdm.Contracts.SourceSystem { Details = cd, MdmSystemData = nexus }; var details = ObjectMother.Create <SourceSystem>(); details.Id = 1; var entity = ObjectMother.Create <SourceSystem>(); entity.Id = 2; entity.AddDetails(details); repository.Setup(x => x.FindOne <SourceSystem>(1)).Returns(entity); // Act service.Update(1, 1, contract); }
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 SourceSystemService(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 SourceSystemMapping { System = system, MappingValue = "A" }; var sourcesystem = new SourceSystem { Id = 1, Validity = new DateRange(start, finish) }; //SourceSystem.AddDetails(details); sourcesystem.ProcessMapping(mapping); // Contract details var identifier = new EnergyTrading.Mdm.Contracts.MdmId { SystemName = "Endur", Identifier = "A" }; var cDetails = new EnergyTrading.Mdm.Contracts.SourceSystemDetails(); mappingEngine.Setup(x => x.Map<SourceSystemMapping, EnergyTrading.Mdm.Contracts.MdmId>(mapping)).Returns(identifier); mappingEngine.Setup(x => x.Map<SourceSystem, EnergyTrading.Mdm.Contracts.SourceSystemDetails>(sourcesystem)).Returns(cDetails); validatorFactory.Setup(x => x.IsValid(It.IsAny<MappingRequest>(), It.IsAny<IList<IRule>>())).Returns(true); var list = new List<SourceSystemMapping> { mapping }; repository.Setup(x => x.Queryable<SourceSystemMapping>()).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<SourceSystemMapping, EnergyTrading.Mdm.Contracts.MdmId>(mapping)); mappingEngine.Verify(x => x.Map<SourceSystem, EnergyTrading.Mdm.Contracts.SourceSystemDetails>(sourcesystem)); repository.Verify(x => x.Queryable<SourceSystemMapping>()); 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 EntityNotFound() { // Arrange var validatorFactory = new Mock <IValidatorEngine>(); var mappingEngine = new Mock <IMappingEngine>(); var repository = new Mock <IRepository>(); var searchCache = new Mock <ISearchCache>(); var service = new SourceSystemService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object); var cd = new EnergyTrading.Mdm.Contracts.SourceSystemDetails(); var nexus = new EnergyTrading.Mdm.Contracts.SystemData { StartDate = new DateTime(2012, 1, 1) }; var contract = new EnergyTrading.Mdm.Contracts.SourceSystem { Details = cd, MdmSystemData = nexus }; validatorFactory.Setup(x => x.IsValid(It.IsAny <EnergyTrading.Mdm.Contracts.SourceSystem>(), It.IsAny <IList <IRule> >())).Returns(true); // Act var response = service.Update(1, 1, contract); // Assert Assert.IsNotNull(response, "Response is null"); Assert.IsFalse(response.IsValid, "Response is valid"); Assert.AreEqual(ErrorType.NotFound, response.Error.Type, "ErrorType differs"); }
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.SourceSystemDetails(); var contract = new EnergyTrading.Mdm.Contracts.SourceSystem { 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 details = new SourceSystem(); var mapping = new SourceSystemMapping(); var mappingEngine = new Mock<IMappingEngine>(); mappingEngine.Setup(x => x.Map<EnergyTrading.Mdm.Contracts.MdmId, SourceSystemMapping>(id)).Returns(mapping); mappingEngine.Setup(x => x.Map<EnergyTrading.Mdm.Contracts.SourceSystemDetails, SourceSystem>(contractDetails)).Returns(details); var mapper = new SourceSystemMapper(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, details.Validity, "Validity differs"); }
public void Map() { // Arrange var mockRepository = new Mock<IRepository>(); var source = new EnergyTrading.Mdm.Contracts.SourceSystemDetails { }; var mapper = new EnergyTrading.MDM.Contracts.Mappers.SourceSystemDetailsMapper(mockRepository.Object); // Act var result = mapper.Map(source); // Assert Assert.IsNotNull(result); }
public void Map() { // Arrange var mockRepository = new Mock <IRepository>(); var source = new EnergyTrading.Mdm.Contracts.SourceSystemDetails { }; var mapper = new EnergyTrading.Mdm.Contracts.Mappers.SourceSystemDetailsMapper(mockRepository.Object); // Act var result = mapper.Map(source); // Assert Assert.IsNotNull(result); }
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.SourceSystemDetails(); var contract = new EnergyTrading.Mdm.Contracts.SourceSystem { 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 details = new SourceSystem(); var mapping = new SourceSystemMapping(); var mappingEngine = new Mock <IMappingEngine>(); mappingEngine.Setup(x => x.Map <EnergyTrading.Mdm.Contracts.MdmId, SourceSystemMapping>(id)).Returns(mapping); mappingEngine.Setup(x => x.Map <EnergyTrading.Mdm.Contracts.SourceSystemDetails, SourceSystem>(contractDetails)).Returns(details); var mapper = new SourceSystemMapper(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, details.Validity, "Validity differs"); }
public void EntityNotFound() { // Arrange var validatorFactory = new Mock<IValidatorEngine>(); var mappingEngine = new Mock<IMappingEngine>(); var repository = new Mock<IRepository>(); var searchCache = new Mock<ISearchCache>(); var service = new SourceSystemService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object); var cd = new EnergyTrading.Mdm.Contracts.SourceSystemDetails(); var nexus = new EnergyTrading.Mdm.Contracts.SystemData { StartDate = new DateTime(2012, 1, 1) }; var contract = new EnergyTrading.Mdm.Contracts.SourceSystem { Details = cd, MdmSystemData = nexus }; validatorFactory.Setup(x => x.IsValid(It.IsAny<EnergyTrading.Mdm.Contracts.SourceSystem>(), It.IsAny<IList<IRule>>())).Returns(true); // Act var response = service.Update(1, 1, contract); // Assert Assert.IsNotNull(response, "Response is null"); Assert.IsFalse(response.IsValid, "Response is valid"); Assert.AreEqual(ErrorType.NotFound, response.Error.Type, "ErrorType 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.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); }
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); }
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 SourceSystemService(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 SourceSystemMapping { System = system, MappingValue = "A" }; var sourcesystem = new SourceSystem { Id = 1, Validity = new DateRange(start, finish) }; //SourceSystem.AddDetails(details); sourcesystem.ProcessMapping(mapping); // Contract details var identifier = new EnergyTrading.Mdm.Contracts.MdmId { SystemName = "Endur", Identifier = "A" }; var cDetails = new EnergyTrading.Mdm.Contracts.SourceSystemDetails(); mappingEngine.Setup(x => x.Map <SourceSystemMapping, EnergyTrading.Mdm.Contracts.MdmId>(mapping)).Returns(identifier); mappingEngine.Setup(x => x.Map <SourceSystem, EnergyTrading.Mdm.Contracts.SourceSystemDetails>(sourcesystem)).Returns(cDetails); validatorFactory.Setup(x => x.IsValid(It.IsAny <MappingRequest>(), It.IsAny <IList <IRule> >())).Returns(true); var list = new List <SourceSystemMapping> { mapping }; repository.Setup(x => x.Queryable <SourceSystemMapping>()).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 <SourceSystemMapping, EnergyTrading.Mdm.Contracts.MdmId>(mapping)); mappingEngine.Verify(x => x.Map <SourceSystem, EnergyTrading.Mdm.Contracts.SourceSystemDetails>(sourcesystem)); repository.Verify(x => x.Queryable <SourceSystemMapping>()); 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"); }