protected static void Establish_context() { var repository = ObjectScript.Repository; party = ObjectMother.Create <Party>(); partyrole = ObjectMother.Create <PartyRole>(); partyrole.Party = party; broker = ObjectMother.Create <Broker>(); broker.Party = party; counterparty = ObjectMother.Create <Counterparty>(); counterparty.Party = party; exchange = ObjectMother.Create <Exchange>(); exchange.Party = party; repository.Add(party); repository.Flush(); repository.Add(partyrole); repository.Flush(); repository.Add(counterparty); repository.Flush(); repository.Add(broker); repository.Flush(); repository.Add(exchange); repository.Flush(); }
protected static void Establish_context() { entity = Script.PartyData.CreateBasicEntity(); var notAMapping = new EnergyTrading.MDM.Contracts.Sample.Party(); content = HttpContentExtensions.CreateDataContract(notAMapping); client = new HttpClient(); }
public void VersionConflict() { // 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); var message = new AmendMappingRequest { MappingId = 12, Mapping = new MdmId { SystemName = "Test", Identifier = "A" }, Version = 34 }; var party = new MDM.Party(); party.AddDetails(new PartyDetails() { Timestamp = BitConverter.GetBytes(25L) }); var mapping = new PartyMapping { Party = party }; validatorFactory.Setup(x => x.IsValid(It.IsAny <AmendMappingRequest>(), It.IsAny <IList <IRule> >())).Returns(true); repository.Setup(x => x.FindOne <PartyMapping>(12)).Returns(mapping); // Act service.UpdateMapping(message); }
protected static void Establish_context() { entity = Script.PartyData.CreateBasicEntityWithOneMapping(); client = new HttpClient(); var notAMapping = new MDM.Party(); content = HttpContentExtensions.CreateDataContract(notAMapping); startVersion = CurrentEntityVersion(); }
partial void AddDetailsToEntity(MDM.Party entity, DateTime startDate, DateTime endDate) { entity.AddDetails( new PartyDetails() { Name = Guid.NewGuid().ToString(), Validity = new DateRange(startDate, endDate) }); }
protected static void Establish_context() { client = new HttpClient(); entity = Script.PartyData.CreateBasicEntity(); var getResponse = client.Get(ServiceUrl["Party"] + entity.Id); updatedContract = getResponse.Content.ReadAsDataContract<EnergyTrading.MDM.Contracts.Sample.Party>(); content = HttpContentExtensions.CreateDataContract(Script.PartyData.MakeChangeToContract(updatedContract)); }
protected static void Establish_context() { client = new HttpClient(); entity = Script.PartyData.CreateBasicEntity(); var getResponse = client.Get(ServiceUrl["Party"] + entity.Id); updatedContract = getResponse.Content.ReadAsDataContract <EnergyTrading.MDM.Contracts.Sample.Party>(); content = HttpContentExtensions.CreateDataContract(Script.PartyData.MakeChangeToContract(updatedContract)); }
protected static void Because_of() { entity = Script.PartyData.CreateEntityWithTwoDetailsAndTwoMappings(); client = new HttpClient(ServiceUrl["Party"] + "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>(); }
protected static void Because_of() { entity = Script.PartyData.CreateEntityWithTwoDetailsAndTwoMappings(); client = new HttpClient(ServiceUrl["Party"] + "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>(); }
protected static void Establish_context() { client = new HttpClient(); entity = Script.PartyData.CreateBasicEntity(); var getResponse = client.Get(ServiceUrl["Party"] + entity.Id); updatedContract = getResponse.Content.ReadAsDataContract<EnergyTrading.MDM.Contracts.Sample.Party>(); updatedContract.Details.Name = "Bob"; updatedContract.Identifiers.Remove(updatedContract.Identifiers.Where(id => id.IsMdmId).First()); content = HttpContentExtensions.CreateDataContract(updatedContract); }
protected static void Establish_context() { client = new HttpClient(); entity = Script.PartyData.CreateBasicEntity(); var getResponse = client.Get(ServiceUrl["Party"] + entity.Id); updatedContract = getResponse.Content.ReadAsDataContract <EnergyTrading.MDM.Contracts.Sample.Party>(); updatedContract.Details.Name = "Bob"; updatedContract.Identifiers.Remove(updatedContract.Identifiers.Where(id => id.IsMdmId).First()); content = HttpContentExtensions.CreateDataContract(updatedContract); }
protected static void Establish_context() { entity1 = Script.PartyData.CreateBasicEntity(); entity2 = Script.PartyData.CreateBasicEntity(); client = new HttpClient(); var search = new Search(); Script.PartyData.CreateSearch(search, entity1, entity2); content = HttpContentExtensions.CreateDataContract(search); }
protected static void Establish_context() { entity1 = Script.PartyData.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() { entity = Script.PartyData.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.PartyData.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 ValidDetailsSaved() { // 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); var identifier = new MdmId { SystemName = "Test", Identifier = "A" }; var message = new AmendMappingRequest { MappingId = 12, Mapping = identifier, Version = 34 }; var start = new DateTime(2000, 12, 31); var finish = DateUtility.Round(SystemTime.UtcNow().AddDays(5)); var s1 = new MDM.SourceSystem { Name = "Test" }; var m1 = new PartyMapping { Id = 12, System = s1, MappingValue = "1", Version = 34UL.GetVersionByteArray(), Validity = new DateRange(start, DateUtility.MaxDate) }; var m2 = new PartyMapping { Id = 12, System = s1, MappingValue = "1", Validity = new DateRange(start, finish) }; // NB We deliberately bypasses the business logic var party = new MDM.Party(); m1.Party = party; party.Mappings.Add(m1); validatorFactory.Setup(x => x.IsValid(It.IsAny <AmendMappingRequest>(), It.IsAny <IList <IRule> >())).Returns(true); repository.Setup(x => x.FindOne <PartyMapping>(12)).Returns(m1); mappingEngine.Setup(x => x.Map <EnergyTrading.Mdm.Contracts.MdmId, PartyMapping>(identifier)).Returns(m2); // Act service.UpdateMapping(message); // Assert // NB Don't verify result of Update - already covered by PartyMappingFixture repository.Verify(x => x.Save(party)); repository.Verify(x => x.Flush()); }
protected static void Establish_context() { entity = Script.PartyData.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.PartyData.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 Map() { var mockRepository = new Mock<IRepository>(); var fakeParty = new MDM.Party(); mockRepository.Setup(repository => repository.FindOne<MDM.Party>(1)).Returns(fakeParty); // Arrange var source = new EnergyTrading.MDM.Contracts.Sample.ExchangeDetails { Name = "test" }; var mapper = new EnergyTrading.MDM.Contracts.Mappers.ExchangeDetailsMapper(mockRepository.Object); // Act var result = mapper.Map(source); // Assert Assert.IsNotNull(result); Assert.AreEqual(source.Name, result.Name); }
public void Map() { var mockRepository = new Mock <IRepository>(); var fakeParty = new MDM.Party(); mockRepository.Setup(repository => repository.FindOne <MDM.Party>(1)).Returns(fakeParty); // Arrange var source = new EnergyTrading.MDM.Contracts.Sample.PartyRoleDetails { Name = "test" }; var mapper = new EnergyTrading.MDM.Contracts.Mappers.PartyRoleDetailsMapper(mockRepository.Object); // Act var result = mapper.Map(source); // Assert Assert.IsNotNull(result); Assert.AreEqual(source.Name, result.Name); }
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 PartyService(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 PartyMapping { 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, PartyMapping>(identifier)).Returns(mapping); var party = new MDM.Party(); repository.Setup(x => x.FindOne <MDM.Party>(12)).Returns(party); // Act var candidate = (PartyMapping)service.CreateMapping(message); // Assert Assert.AreSame(mapping, candidate); repository.Verify(x => x.Save(party)); repository.Verify(x => x.Flush()); }
public MDM.Party 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.Party(); 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 PartyMapping() { MappingValue = Guid.NewGuid().ToString(), System = trayport, Validity = new DateRange(DateTime.MinValue, DateTime.MaxValue) }; var endurMapping = new PartyMapping() { 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 CompareContractWithEntityDetails(EnergyTrading.MDM.Contracts.Sample.Party contract, MDM.Party entity) { PartyComparer.Compare(contract, 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 PartyService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object); // Domain details var system = new MDM.SourceSystem { Name = "Endur" }; var mapping = new PartyMapping { System = system, MappingValue = "A", }; var targetSystem = new MDM.SourceSystem { Name = "Trayport" }; var targetMapping = new PartyMapping { System = targetSystem, MappingValue = "B", IsDefault = true }; var details = new MDM.PartyDetails { Name = "Party 1" }; var party = new MDM.Party { Id = 1 }; party.AddDetails(details); party.ProcessMapping(mapping); party.ProcessMapping(targetMapping); // Contract details var targetIdentifier = new MdmId { SystemName = "Trayport", Identifier = "B" }; mappingEngine.Setup(x => x.Map <PartyMapping, MdmId>(targetMapping)).Returns(targetIdentifier); var list = new List <PartyMapping> { mapping }; repository.Setup(x => x.Queryable <PartyMapping>()).Returns(list.AsQueryable()); var request = new CrossMappingRequest { SystemName = "Endur", Identifier = "A", TargetSystemName = "trayport", ValidAt = SystemTime.UtcNow(), Version = 1 }; // 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() { party = Script.PartyData.CreateEntityWithTwoDetailsAndTwoMappings(); }
public static void Compare(EnergyTrading.MDM.Contracts.Sample.Party contract, MDM.Party entity) { PartyDetails detailsToCompare = entity.Details[0]; if (contract.MdmSystemData != null) { detailsToCompare = entity.Details.Where(details => details.Validity.Start == contract.MdmSystemData.StartDate).First(); } Assert.AreEqual(contract.Details.Name, detailsToCompare.Name); Assert.AreEqual(contract.Details.FaxNumber, detailsToCompare.Fax); Assert.AreEqual(contract.Details.TelephoneNumber, detailsToCompare.Phone); Assert.AreEqual(contract.Details.Role, detailsToCompare.Role); }
protected static void Establish_context() { entity1 = Script.PartyData.CreateBasicEntity(); entity2 = Script.PartyData.CreateBasicEntity(); }
protected static void Because_of() { entity = Script.PartyData.CreateBasicEntity(); client.DefaultHeaders.Add("If-Match", entity.Version.ToString()); response = client.Post(ServiceUrl["Party"] + entity.Id, content); }
partial void AddDetailsToEntity(MDM.Party entity, DateTime startDate, DateTime endDate);
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 PartyService(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 PartyMapping { 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, PartyMapping>(identifier)).Returns(mapping); var party = new MDM.Party(); repository.Setup(x => x.FindOne<MDM.Party>(12)).Returns(party); // Act var candidate = (PartyMapping)service.CreateMapping(message); // Assert Assert.AreSame(mapping, candidate); repository.Verify(x => x.Save(party)); repository.Verify(x => x.Flush()); }