protected static void Establish_context() { entity = Script.LocationData.CreateBasicEntity(); var notAMapping = new EnergyTrading.MDM.Contracts.Sample.Location(); content = HttpContentExtensions.CreateDataContract(notAMapping); client = new HttpClient(); }
protected static void Establish_context() { client = new HttpClient(); entity = Script.LocationData.CreateBasicEntity(); content = HttpContentExtensions.CreateDataContract(new EnergyTrading.MDM.Contracts.Sample.Location()); startVersion = CurrentEntityVersion(); }
protected static void Establish_context() { entity = Script.LocationData.CreateBasicEntityWithOneMapping(); client = new HttpClient(); var notAMapping = new MDM.Location(); content = HttpContentExtensions.CreateDataContract(notAMapping); startVersion = CurrentEntityVersion(); }
protected static void Establish_context() { client = new HttpClient(); entity = Script.LocationData.CreateBasicEntity(); var getResponse = client.Get(ServiceUrl["Location"] + entity.Id); updatedContract = getResponse.Content.ReadAsDataContract<EnergyTrading.MDM.Contracts.Sample.Location>(); content = HttpContentExtensions.CreateDataContract(Script.LocationData.MakeChangeToContract(updatedContract)); }
protected static void Establish_context() { client = new HttpClient(); entity = Script.LocationData.CreateBasicEntity(); var getResponse = client.Get(ServiceUrl["Location"] + entity.Id); updatedContract = getResponse.Content.ReadAsDataContract <EnergyTrading.MDM.Contracts.Sample.Location>(); content = HttpContentExtensions.CreateDataContract(Script.LocationData.MakeChangeToContract(updatedContract)); }
protected static void Because_of() { entity = Script.LocationData.CreateEntityWithTwoDetailsAndTwoMappings(); client = new HttpClient(ServiceUrl["Location"] + "crossmap?source-system=trayport&destination-system=endur&mapping-string=" + entity.Mappings[0].MappingValue + "&as-of=" + entity.Mappings[0].Validity.Start.ToString(DateFormatString)); response = client.Get(); mappingResponse = response.Content.ReadAsDataContract <EnergyTrading.Mdm.Contracts.MappingResponse>(); }
public void ValidDetailsSaved() { const int mappingId = 12; // Arrange var validatorFactory = new Mock <IValidatorEngine>(); var mappingEngine = new Mock <IMappingEngine>(); var repository = new Mock <IRepository>(); var searchCache = new Mock <ISearchCache>(); var service = new LocationService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object); // NB Don't put mappingId here - service assigns it var identifier = new MdmId { SystemName = "Test", Identifier = "A" }; var message = new AmendMappingRequest { MappingId = mappingId, Mapping = identifier, Version = 34 }; var start = new DateTime(2000, 12, 31); var finish = DateUtility.Round(SystemTime.UtcNow().AddDays(5)); var s1 = new SourceSystem { Name = "Test" }; var m1 = new LocationMapping { Id = mappingId, System = s1, MappingValue = "1", Version = 34UL.GetVersionByteArray(), Validity = new DateRange(start, DateUtility.MaxDate) }; var m2 = new LocationMapping { Id = mappingId, System = s1, MappingValue = "1", Validity = new DateRange(start, finish) }; // NB We deliberately bypasses the business logic var entity = new MDM.Location(); m1.Location = entity; entity.Mappings.Add(m1); validatorFactory.Setup(x => x.IsValid(It.IsAny <AmendMappingRequest>(), It.IsAny <IList <IRule> >())).Returns(true); repository.Setup(x => x.FindOne <LocationMapping>(mappingId)).Returns(m1); mappingEngine.Setup(x => x.Map <EnergyTrading.Mdm.Contracts.MdmId, LocationMapping>(identifier)).Returns(m2); // Act service.UpdateMapping(message); // Assert Assert.AreEqual(mappingId, identifier.MappingId, "Mapping identifier differs"); // Proves we have an update not an add Assert.AreEqual(1, entity.Mappings.Count, "Mapping count differs"); // NB Don't verify result of Update - already covered by LocationMappingFixture repository.Verify(x => x.Save(entity)); repository.Verify(x => x.Flush()); }
protected static void Establish_context() { entity1 = Script.LocationData.CreateBasicEntity(); entity2 = Script.LocationData.CreateBasicEntity(); client = new HttpClient(); var search = new Search(); Script.LocationData.CreateSearch(search, entity1, entity2); content = HttpContentExtensions.CreateDataContract(search); }
protected static void Establish_context() { entity1 = Script.LocationData.CreateBasicEntityWithOneMapping(); client = new HttpClient(); Search search = SearchBuilder.CreateSearch(isMappingSearch: true); search.AddSearchCriteria(SearchCombinator.And).AddCriteria( "MappingValue", SearchCondition.Equals, entity1.Mappings[0].MappingValue).AddCriteria( "System.Name", SearchCondition.Equals, "Endur"); content = HttpContentExtensions.CreateDataContract(search); }
protected static void Establish_context() { entity1 = Script.LocationData.CreateBasicEntity(); entity2 = Script.LocationData.CreateBasicEntity(); client = new HttpClient(); var search = new Search().IsMutliPage().MaxPageSize(1); Script.LocationData.CreateSearch(search, entity1, entity2); content = HttpContentExtensions.CreateDataContract(search); }
protected static void Establish_context() { entity = Script.LocationData.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(); }
protected static void Establish_context() { entity = Script.LocationData.CreateBasicEntity(); mapping = new EnergyTrading.Mdm.Contracts.Mapping{ SystemName = "Endur", Identifier = "Test", SourceSystemOriginated = false, DefaultReverseInd = true, StartDate = Script.baseDate, EndDate = Script.baseDate.AddDays(2) }; content = HttpContentExtensions.CreateDataContract(mapping); content2 = HttpContentExtensions.CreateDataContract(mapping); client = new HttpClient(); }
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); }
protected static void Establish_context() { entity = Script.LocationData.CreateBasicEntityWithOneMapping(); currentTrayportMapping = entity.Mappings[0]; mapping = new EnergyTrading.Mdm.Contracts.Mapping { SystemName = currentTrayportMapping.System.Name, Identifier = currentTrayportMapping.MappingValue, SourceSystemOriginated = currentTrayportMapping.IsMaster, DefaultReverseInd = currentTrayportMapping.IsDefault, StartDate = currentTrayportMapping.Validity.Start, EndDate = currentTrayportMapping.Validity.Finish.AddDays(2) }; content = HttpContentExtensions.CreateDataContract(mapping); client = new HttpClient(); }
protected static void Establish_context() { entity = Script.LocationData.CreateBasicEntityWithOneMapping(); currentTrayportMapping = entity.Mappings[0]; mapping = new EnergyTrading.Mdm.Contracts.Mapping{ SystemName = currentTrayportMapping.System.Name, Identifier = currentTrayportMapping.MappingValue, SourceSystemOriginated = currentTrayportMapping.IsMaster, DefaultReverseInd = currentTrayportMapping.IsDefault, StartDate = currentTrayportMapping.Validity.Start, EndDate = currentTrayportMapping.Validity.Finish.AddDays(2) }; content = HttpContentExtensions.CreateDataContract(mapping); client = new HttpClient(); }
public void ValidContractAdded() { // Arrange var validatorFactory = new Mock <IValidatorEngine>(); var mappingEngine = new Mock <IMappingEngine>(); var repository = new Mock <IRepository>(); var searchCache = new Mock <ISearchCache>(); var service = new LocationService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object); var identifier = new MdmId { SystemName = "Test", Identifier = "A" }; var message = new CreateMappingRequest { EntityId = 12, Mapping = identifier }; var system = new MDM.SourceSystem { Name = "Test" }; var mapping = new LocationMapping { System = system, MappingValue = "A" }; validatorFactory.Setup(x => x.IsValid(It.IsAny <CreateMappingRequest>(), It.IsAny <IList <IRule> >())).Returns(true); mappingEngine.Setup(x => x.Map <EnergyTrading.Mdm.Contracts.MdmId, LocationMapping>(identifier)).Returns(mapping); var location = new MDM.Location(); repository.Setup(x => x.FindOne <MDM.Location>(12)).Returns(location); // Act var candidate = (LocationMapping)service.CreateMapping(message); // Assert Assert.AreSame(mapping, candidate); repository.Verify(x => x.Save(location)); repository.Verify(x => x.Flush()); }
public MDM.Location 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.Location(); 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 LocationMapping() { MappingValue = Guid.NewGuid().ToString(), System = trayport, Validity = new DateRange(DateTime.MinValue, DateTime.MaxValue) }; var endurMapping = new LocationMapping() { 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 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 LocationService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object); // Domain details var system = new MDM.SourceSystem { Name = "Endur" }; var mapping = new LocationMapping { System = system, MappingValue = "A" }; var targetSystem = new MDM.SourceSystem { Name = "Trayport" }; var targetMapping = new LocationMapping { System = targetSystem, MappingValue = "B", IsDefault = true }; var location = new MDM.Location { Id = 1, Timestamp = new byte[] { 1, 0, 0, 0, 0, 0, 0, 0 } }; //Location.AddDetails(details); location.ProcessMapping(mapping); location.ProcessMapping(targetMapping); // Contract details var targetIdentifier = new MdmId { SystemName = "Trayport", Identifier = "B" }; mappingEngine.Setup(x => x.Map <LocationMapping, MdmId>(targetMapping)).Returns(targetIdentifier); var list = new List <LocationMapping> { mapping }; repository.Setup(x => x.Queryable <LocationMapping>()).Returns(list.AsQueryable()); var request = new CrossMappingRequest { SystemName = "Endur", Identifier = "A", TargetSystemName = "trayport", ValidAt = SystemTime.UtcNow(), Version = 0 }; // 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"); }
protected static void Establish_context() { location = Script.LocationData.CreateBasicEntity(); }
public void ValidContractAdded() { // Arrange var validatorFactory = new Mock<IValidatorEngine>(); var mappingEngine = new Mock<IMappingEngine>(); var repository = new Mock<IRepository>(); var searchCache = new Mock<ISearchCache>(); var service = new LocationService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object); var identifier = new MdmId { SystemName = "Test", Identifier = "A" }; var message = new CreateMappingRequest { EntityId = 12, Mapping = identifier }; var system = new MDM.SourceSystem { Name = "Test" }; var mapping = new LocationMapping { System = system, MappingValue = "A" }; validatorFactory.Setup(x => x.IsValid(It.IsAny<CreateMappingRequest>(), It.IsAny<IList<IRule>>())).Returns(true); mappingEngine.Setup(x => x.Map<EnergyTrading.Mdm.Contracts.MdmId, LocationMapping>(identifier)).Returns(mapping); var location = new MDM.Location(); repository.Setup(x => x.FindOne<MDM.Location>(12)).Returns(location); // Act var candidate = (LocationMapping)service.CreateMapping(message); // Assert Assert.AreSame(mapping, candidate); repository.Verify(x => x.Save(location)); repository.Verify(x => x.Flush()); }
protected static void Establish_context() { location = Script.LocationData.CreateEntityWithTwoDetailsAndTwoMappings(); }
protected static void Because_of() { entity = Script.LocationData.CreateBasicEntity(); client.DefaultHeaders.Add("If-Match", entity.Version.ToString()); response = client.Post(ServiceUrl["Location"] + entity.Id, content); }
public void CompareContractWithEntityDetails(EnergyTrading.MDM.Contracts.Sample.Location contract, MDM.Location entity) { LocationComparer.Compare(contract, entity); }
partial void AddDetailsToEntity(MDM.Location entity, DateTime startDate, DateTime endDate);