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<MDM.Contracts.Curve>(), It.IsAny<IList<IRule>>())).Returns(true); var service = new CurveService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object); var cd = new MDM.Contracts.CurveDetails(); var nexus = new MDM.Contracts.SystemData { StartDate = new DateTime(2012, 1, 1) }; var contract = new MDM.Contracts.Curve { Details = cd, Nexus = nexus }; var details = ObjectMother.Create<Curve>(); details.Id = 1; var entity = ObjectMother.Create<Curve>(); entity.Id = 2; entity.AddDetails(details); repository.Setup(x => x.FindOne<Curve>(1)).Returns(entity); // Act service.Update(1, 1, contract); }
public void Map() { // Arrange var start = new DateTime(2010, 1, 1); var end = DateUtility.MaxDate; var range = new DateRange(start, end); var id = new MDM.Contracts.NexusId { SystemName = "Test", Identifier = "A" }; var contractDetails = new MDM.Contracts.CurveDetails(); var contract = new MDM.Contracts.Curve { Identifiers = new MDM.Contracts.NexusIdList { id }, Details = contractDetails, Nexus = new MDM.Contracts.SystemData { StartDate = start, EndDate = end } }; // NB Don't assign validity here, want to prove SUT sets it var details = new Curve(); var mapping = new CurveMapping(); var mappingEngine = new Mock<IMappingEngine>(); mappingEngine.Setup(x => x.Map<MDM.Contracts.NexusId, CurveMapping>(id)).Returns(mapping); mappingEngine.Setup(x => x.Map<MDM.Contracts.CurveDetails, Curve>(contractDetails)).Returns(details); var mapper = new CurveMapper(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 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 <MDM.Contracts.Curve>(), It.IsAny <IList <IRule> >())).Returns(true); var service = new CurveService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object); var cd = new MDM.Contracts.CurveDetails(); var nexus = new MDM.Contracts.SystemData { StartDate = new DateTime(2012, 1, 1) }; var contract = new MDM.Contracts.Curve { Details = cd, Nexus = nexus }; var details = ObjectMother.Create <Curve>(); details.Id = 1; var entity = ObjectMother.Create <Curve>(); entity.Id = 2; entity.AddDetails(details); repository.Setup(x => x.FindOne <Curve>(1)).Returns(entity); // Act service.Update(1, 1, contract); }
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 CurveService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object); var cd = new MDM.Contracts.CurveDetails(); var nexus = new MDM.Contracts.SystemData { StartDate = new DateTime(2012, 1, 1) }; var contract = new MDM.Contracts.Curve { Details = cd, Nexus = nexus }; validatorFactory.Setup(x => x.IsValid(It.IsAny <MDM.Contracts.Curve>(), 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 mockRepository = new Mock <IRepository>(); var fakeCommodity = new MDM.Commodity(); var fakeLocation = new MDM.Location(); mockRepository.Setup(repository => repository.FindOne <MDM.Location>(1)).Returns(fakeLocation); mockRepository.Setup(repository => repository.FindOne <MDM.Commodity>(1)).Returns(fakeCommodity); // Arrange var source = new MDM.Contracts.CurveDetails { Name = "Test Curve", CurveType = "Forward", Currency = "GBP", Commodity = new EntityId { Identifier = new NexusId { IsNexusId = true, Identifier = "1" } }, CommodityUnit = "ton", Location = new EntityId { Identifier = new NexusId { IsNexusId = true, Identifier = "1" } }, DefaultSpread = .005m }; var mapper = new MDM.Contracts.Mappers.CurveDetailsMapper(mockRepository.Object); // Act var result = mapper.Map(source); // Assert // TODO_UnitTestGeneration_Curve - assert properties are mapped correctly Assert.IsNotNull(result); Assert.AreEqual(source.Name, result.Name); Assert.AreEqual(fakeCommodity, result.Commodity); Assert.AreEqual(fakeLocation, result.Location); Assert.AreEqual(source.Currency, result.Currency); Assert.AreEqual(source.CurveType, result.Type); Assert.AreEqual(source.CommodityUnit, result.CommodityUnit); Assert.AreEqual(source.DefaultSpread, result.DefaultSpread); }
public void Map() { // Arrange var start = new DateTime(2010, 1, 1); var end = DateUtility.MaxDate; var range = new DateRange(start, end); var id = new MDM.Contracts.NexusId { SystemName = "Test", Identifier = "A" }; var contractDetails = new MDM.Contracts.CurveDetails(); var contract = new MDM.Contracts.Curve { Identifiers = new MDM.Contracts.NexusIdList { id }, Details = contractDetails, Nexus = new MDM.Contracts.SystemData { StartDate = start, EndDate = end } }; // NB Don't assign validity here, want to prove SUT sets it var details = new Curve(); var mapping = new CurveMapping(); var mappingEngine = new Mock <IMappingEngine>(); mappingEngine.Setup(x => x.Map <MDM.Contracts.NexusId, CurveMapping>(id)).Returns(mapping); mappingEngine.Setup(x => x.Map <MDM.Contracts.CurveDetails, Curve>(contractDetails)).Returns(details); var mapper = new CurveMapper(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 CurveService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object); var cd = new MDM.Contracts.CurveDetails(); var nexus = new MDM.Contracts.SystemData { StartDate = new DateTime(2012, 1, 1) }; var contract = new MDM.Contracts.Curve { Details = cd, Nexus = nexus }; validatorFactory.Setup(x => x.IsValid(It.IsAny<MDM.Contracts.Curve>(), 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 MDM.Contracts.CurveDetails(); var nexus = new MDM.Contracts.SystemData { StartDate = new DateTime(2012, 1, 1) }; var identifier = new MDM.Contracts.NexusId { SystemName = "Test", Identifier = "A" }; var contract = new MDM.Contracts.Curve { Details = cd, Nexus = nexus }; contract.Identifiers.Add(identifier); // Domain var system = new SourceSystem { Name = "Test" }; var mapping = new CurveMapping { System = system, MappingValue = "A" }; var d1 = ObjectMother.Create<Curve>(); d1.Id = 1; d1.Timestamp = new byte[] { 74, 0, 0, 0, 0, 0, 0, 0 }; var entity = ObjectMother.Create<Curve>(); entity.Timestamp = new byte[] { 74, 0, 0, 0, 0, 0, 0, 0 }; entity.AddDetails(d1); var d2 = ObjectMother.Create<Curve>(); 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<MDM.Contracts.Curve>(), It.IsAny<IList<IRule>>())).Returns(true); repository.Setup(x => x.FindOne<Curve>(1)).Returns(entity); mappingEngine.Setup(x => x.Map<MDM.Contracts.CurveDetails, Curve>(cd)).Returns(d2); mappingEngine.Setup(x => x.Map<MDM.Contracts.SystemData, DateRange>(nexus)).Returns(range); mappingEngine.Setup(x => x.Map<MDM.Contracts.NexusId, CurveMapping>(identifier)).Returns(mapping); var service = new CurveService(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 CurveService(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 CurveMapping { System = system, MappingValue = "A" }; var curve = new Curve { Id = 1, Validity = new DateRange(start, finish) }; //Curve.AddDetails(details); curve.ProcessMapping(mapping); // Contract details var identifier = new MDM.Contracts.NexusId { SystemName = "Endur", Identifier = "A" }; var cdetails = new MDM.Contracts.CurveDetails(); mappingEngine.Setup(x => x.Map <CurveMapping, MDM.Contracts.NexusId>(mapping)).Returns(identifier); mappingEngine.Setup(x => x.Map <Curve, MDM.Contracts.CurveDetails>(curve)).Returns(cdetails); validatorFactory.Setup(x => x.IsValid(It.IsAny <MappingRequest>(), It.IsAny <IList <IRule> >())).Returns(true); var list = new List <CurveMapping> { mapping }; repository.Setup(x => x.Queryable <CurveMapping>()).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 <CurveMapping, MDM.Contracts.NexusId>(mapping)); mappingEngine.Verify(x => x.Map <Curve, MDM.Contracts.CurveDetails>(curve)); repository.Verify(x => x.Queryable <CurveMapping>()); 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.Nexus.StartDate, "Start date differs"); Assert.AreEqual(finish, candidate.Nexus.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 MDM.Contracts.CurveDetails(); var nexus = new MDM.Contracts.SystemData { StartDate = new DateTime(2012, 1, 1) }; var identifier = new MDM.Contracts.NexusId { SystemName = "Test", Identifier = "A" }; var contract = new MDM.Contracts.Curve { Details = cd, Nexus = nexus }; contract.Identifiers.Add(identifier); // Domain var system = new SourceSystem { Name = "Test" }; var mapping = new CurveMapping { System = system, MappingValue = "A" }; var d1 = ObjectMother.Create <Curve>(); d1.Id = 1; d1.Timestamp = new byte[] { 74, 0, 0, 0, 0, 0, 0, 0 }; var entity = ObjectMother.Create <Curve>(); entity.Timestamp = new byte[] { 74, 0, 0, 0, 0, 0, 0, 0 }; entity.AddDetails(d1); var d2 = ObjectMother.Create <Curve>(); 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 <MDM.Contracts.Curve>(), It.IsAny <IList <IRule> >())).Returns(true); repository.Setup(x => x.FindOne <Curve>(1)).Returns(entity); mappingEngine.Setup(x => x.Map <MDM.Contracts.CurveDetails, Curve>(cd)).Returns(d2); mappingEngine.Setup(x => x.Map <MDM.Contracts.SystemData, DateRange>(nexus)).Returns(range); mappingEngine.Setup(x => x.Map <MDM.Contracts.NexusId, CurveMapping>(identifier)).Returns(mapping); var service = new CurveService(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); }