protected static void Establish_context() { broker = BrokerData.CreateContractForEntityCreation(); content = HttpContentExtensions.CreateDataContract(broker); client = new HttpClient(); }
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 BrokerService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object); var cd = new EnergyTrading.MDM.Contracts.Sample.BrokerDetails { Name = "Test" }; var nexus = new EnergyTrading.Mdm.Contracts.SystemData { StartDate = new DateTime(2012, 1, 1) }; var contract = new EnergyTrading.MDM.Contracts.Sample.Broker { Details = cd, MdmSystemData = nexus }; validatorFactory.Setup(x => x.IsValid(It.IsAny <EnergyTrading.MDM.Contracts.Sample.Broker>(), 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"); }
protected static void Establish_context() { entity = BrokerData.CreateBasicEntity(); var notAMapping = new EnergyTrading.MDM.Contracts.Sample.Broker(); content = HttpContentExtensions.CreateDataContract(notAMapping); client = new HttpClient(); }
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.Sample.Broker>(), It.IsAny <IList <IRule> >())).Returns(true); var service = new BrokerService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object); var cd = new EnergyTrading.MDM.Contracts.Sample.BrokerDetails { Name = "Test" }; var nexus = new EnergyTrading.Mdm.Contracts.SystemData { StartDate = new DateTime(2012, 1, 1) }; var contract = new EnergyTrading.MDM.Contracts.Sample.Broker { Details = cd, MdmSystemData = nexus }; var details = new BrokerDetails { Id = 2, Name = "Test" }; var entity = new Broker(); entity.AddDetails(details); repository.Setup(x => x.FindOne <Broker>(1)).Returns(entity); // Act service.Update(1, 1, contract); }
public static EnergyTrading.MDM.Contracts.Sample.Broker CreateContractForEntityCreation() { var contract = new EnergyTrading.MDM.Contracts.Sample.Broker(); AddDetailsToContract(contract); return(contract); }
protected static void Establish_context() { client = new HttpClient(); entity = BrokerData.CreateBasicEntity(); var getResponse = client.Get(ServiceUrl["Broker"] + entity.Id); updatedContract = getResponse.Content.ReadAsDataContract <EnergyTrading.MDM.Contracts.Sample.Broker>(); content = HttpContentExtensions.CreateDataContract(BrokerData.MakeChangeToContract(updatedContract)); }
protected static void Establish_context() { client = new HttpClient(); entity = BrokerData.CreateBasicEntity(); var getResponse = client.Get(ServiceUrl["Broker"] + entity.Id); updatedContract = getResponse.Content.ReadAsDataContract<EnergyTrading.MDM.Contracts.Sample.Broker>(); content = HttpContentExtensions.CreateDataContract(BrokerData.MakeChangeToContract(updatedContract)); }
protected static void Because_of() { using (var client = new HttpClient(ServiceUrl["Broker"] + broker.Id)) { using (HttpResponseMessage response = client.Get()) { returnedBroker = response.Content.ReadAsDataContract<EnergyTrading.MDM.Contracts.Sample.Broker>(); } } }
public void OverlapsRangeFails() { // Assert var start = new DateTime(1999, 1, 1); var finish = new DateTime(2020, 12, 31); var validity = new DateRange(start, finish); var system = new MDM.SourceSystem { Name = "Test" }; var brokerMapping = new PartyRoleMapping { System = system, MappingValue = "1", Validity = validity }; var list = new List <PartyRoleMapping> { brokerMapping }; var repository = new Mock <IRepository>(); repository.Setup(x => x.Queryable <PartyRoleMapping>()).Returns(list.AsQueryable()); var systemList = new List <MDM.SourceSystem>(); var systemRepository = new Mock <IRepository>(); systemRepository.Setup(x => x.Queryable <MDM.SourceSystem>()).Returns(systemList.AsQueryable()); var overlapsRangeIdentifier = new EnergyTrading.Mdm.Contracts.MdmId { SystemName = "Test", Identifier = "1", StartDate = start.AddHours(10), EndDate = start.AddHours(15) }; var identifierValidator = new NexusIdValidator <PartyRoleMapping>(repository.Object); var validatorEngine = new Mock <IValidatorEngine>(); validatorEngine.Setup(x => x.IsValid(It.IsAny <EnergyTrading.Mdm.Contracts.MdmId>(), It.IsAny <IList <IRule> >())) .Returns((EnergyTrading.Mdm.Contracts.MdmId x, IList <IRule> y) => identifierValidator.IsValid(x, y)); var validator = new BrokerValidator(validatorEngine.Object, repository.Object); var broker = new Broker { Identifiers = new EnergyTrading.Mdm.Contracts.MdmIdList { overlapsRangeIdentifier } }; // Act var violations = new List <IRule>(); var result = validator.IsValid(broker, violations); // Assert Assert.IsFalse(result, "Validator succeeded"); }
public void InvalidContractNotSaved() { // Arrange var validatorFactory = new Mock <IValidatorEngine>(); var mappingEngine = new Mock <IMappingEngine>(); var repository = new Mock <IRepository>(); var searchCache = new Mock <ISearchCache>(); var service = new BrokerService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object); var contract = new EnergyTrading.MDM.Contracts.Sample.Broker(); validatorFactory.Setup(x => x.IsValid(It.IsAny <object>(), It.IsAny <IList <IRule> >())).Returns(false); // Act service.Create(contract); }
public void InvalidContractNotSaved() { // Arrange var validatorFactory = new Mock<IValidatorEngine>(); var mappingEngine = new Mock<IMappingEngine>(); var repository = new Mock<IRepository>(); var searchCache = new Mock<ISearchCache>(); var service = new BrokerService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object); var contract = new EnergyTrading.MDM.Contracts.Sample.Broker(); validatorFactory.Setup(x => x.IsValid(It.IsAny<object>(), It.IsAny<IList<IRule>>())).Returns(false); // Act service.Create(contract); }
private static void AddDetailsToContract(EnergyTrading.MDM.Contracts.Sample.Broker contract) { var entity = ObjectMother.Create <Broker>(); repository.Add(entity); repository.Flush(); contract.Details = new EnergyTrading.MDM.Contracts.Sample.BrokerDetails() { Name = entity.LatestDetails.Name, Phone = (entity.LatestDetails as BrokerDetails).Phone, Fax = (entity.LatestDetails as BrokerDetails).Fax, Rate = (entity.LatestDetails as BrokerDetails).Rate, }; contract.Party = entity.Party.CreateNexusEntityId(() => ""); }
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.Sample.BrokerDetails(); var contract = new EnergyTrading.MDM.Contracts.Sample.Broker { Identifiers = new EnergyTrading.Mdm.Contracts.MdmIdList { id }, Details = contractDetails, MdmSystemData = new EnergyTrading.Mdm.Contracts.SystemData { StartDate = start, EndDate = end }, Party = ObjectMother.Create <Party>().CreateNexusEntityId(() => "") }; // NB Don't assign validity here, want to prove SUT sets it var details = new BrokerDetails(); var mapping = new PartyRoleMapping(); var mappingEngine = new Mock <IMappingEngine>(); var repository = new Mock <IRepository>(); mappingEngine.Setup(x => x.Map <EnergyTrading.Mdm.Contracts.MdmId, PartyRoleMapping>(id)).Returns(mapping); mappingEngine.Setup(x => x.Map <EnergyTrading.MDM.Contracts.Sample.BrokerDetails, BrokerDetails>(contractDetails)).Returns(details); repository.Setup(x => x.FindOne <Party>(int.Parse(contract.Party.Identifier.Identifier))).Returns(ObjectMother.Create <Party>()); var mapper = new BrokerMapper(mappingEngine.Object, repository.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"); Assert.AreEqual("Broker", candidate.PartyRoleType); Check(range, details.Validity, "Validity differs"); }
public void ValidBrokerPasses() { // Assert var start = new DateTime(1999, 1, 1); var system = new MDM.SourceSystem { Name = "Test" }; var systemList = new List <MDM.SourceSystem> { system }; var systemRepository = new Mock <IRepository>(); var repository = new StubValidatorRepository(); systemRepository.Setup(x => x.Queryable <MDM.SourceSystem>()).Returns(systemList.AsQueryable()); var identifier = new EnergyTrading.Mdm.Contracts.MdmId { SystemName = "Test", Identifier = "1", StartDate = start.AddHours(-10), EndDate = start.AddHours(-5) }; var validatorEngine = new Mock <IValidatorEngine>(); var validator = new BrokerValidator(validatorEngine.Object, repository); var broker = new Broker { Details = new EnergyTrading.MDM.Contracts.Sample.BrokerDetails { Name = "Test" }, Identifiers = new EnergyTrading.Mdm.Contracts.MdmIdList { identifier } }; this.AddRelatedEntities(broker); // Act var violations = new List <IRule>(); var result = validator.IsValid(broker, violations); // Assert Assert.IsTrue(result, "Validator failed"); Assert.AreEqual(0, violations.Count, "Violation count differs"); }
public static EnergyTrading.MDM.Contracts.Sample.Broker MakeChangeToContract(EnergyTrading.MDM.Contracts.Sample.Broker currentContract) { var entity = ObjectMother.Create <Broker>(); repository.Add(entity); repository.Flush(); currentContract.Details = new EnergyTrading.MDM.Contracts.Sample.BrokerDetails() { Name = entity.LatestDetails.Name, Phone = (entity.LatestDetails as BrokerDetails).Phone, Fax = (entity.LatestDetails as BrokerDetails).Fax, Rate = (entity.LatestDetails as BrokerDetails).Rate, }; currentContract.MdmSystemData.StartDate = currentContract.MdmSystemData.StartDate.Value.AddDays(2); return(currentContract); }
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.Sample.BrokerDetails(); var contract = new EnergyTrading.MDM.Contracts.Sample.Broker { Identifiers = new EnergyTrading.Mdm.Contracts.MdmIdList { id }, Details = contractDetails, MdmSystemData = new EnergyTrading.Mdm.Contracts.SystemData { StartDate = start, EndDate = end }, Party = ObjectMother.Create<Party>().CreateNexusEntityId(() => "") }; // NB Don't assign validity here, want to prove SUT sets it var details = new BrokerDetails(); var mapping = new PartyRoleMapping(); var mappingEngine = new Mock<IMappingEngine>(); var repository = new Mock<IRepository>(); mappingEngine.Setup(x => x.Map<EnergyTrading.Mdm.Contracts.MdmId, PartyRoleMapping>(id)).Returns(mapping); mappingEngine.Setup(x => x.Map<EnergyTrading.MDM.Contracts.Sample.BrokerDetails, BrokerDetails>(contractDetails)).Returns(details); repository.Setup(x => x.FindOne<Party>(int.Parse(contract.Party.Identifier.Identifier))).Returns(ObjectMother.Create<Party>()); var mapper = new BrokerMapper(mappingEngine.Object, repository.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"); Assert.AreEqual("Broker", candidate.PartyRoleType); Check(range, details.Validity, "Validity differs"); }
public void ValidContractIsSaved() { // Arrange var validatorFactory = new Mock<IValidatorEngine>(); var mappingEngine = new Mock<IMappingEngine>(); var repository = new Mock<IRepository>(); var searchCache = new Mock<ISearchCache>(); var service = new BrokerService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object); var broker = new Broker(); var contract = new EnergyTrading.MDM.Contracts.Sample.Broker(); validatorFactory.Setup(x => x.IsValid(It.IsAny<EnergyTrading.MDM.Contracts.Sample.Broker>(), It.IsAny<IList<IRule>>())).Returns(true); mappingEngine.Setup(x => x.Map<EnergyTrading.MDM.Contracts.Sample.Broker, Broker>(contract)).Returns(broker); // Act var expected = service.Create(contract); // Assert Assert.AreSame(expected, broker, "Broker differs"); repository.Verify(x => x.Add(broker)); repository.Verify(x => x.Flush()); }
public void ValidContractIsSaved() { // Arrange var validatorFactory = new Mock <IValidatorEngine>(); var mappingEngine = new Mock <IMappingEngine>(); var repository = new Mock <IRepository>(); var searchCache = new Mock <ISearchCache>(); var service = new BrokerService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object); var broker = new Broker(); var contract = new EnergyTrading.MDM.Contracts.Sample.Broker(); validatorFactory.Setup(x => x.IsValid(It.IsAny <EnergyTrading.MDM.Contracts.Sample.Broker>(), It.IsAny <IList <IRule> >())).Returns(true); mappingEngine.Setup(x => x.Map <EnergyTrading.MDM.Contracts.Sample.Broker, Broker>(contract)).Returns(broker); // Act var expected = service.Create(contract); // Assert Assert.AreSame(expected, broker, "Broker differs"); repository.Verify(x => x.Add(broker)); repository.Verify(x => x.Flush()); }
public void BadSystemFails() { // Assert var start = new DateTime(1999, 1, 1); var finish = new DateTime(2020, 12, 31); var validity = new DateRange(start, finish); var system = new MDM.SourceSystem { Name = "Test" }; var brokerMapping = new PartyRoleMapping { System = system, MappingValue = "1", Validity = validity }; var list = new List<PartyRoleMapping> { brokerMapping }; var repository = new Mock<IRepository>(); repository.Setup(x => x.Queryable<PartyRoleMapping>()).Returns(list.AsQueryable()); var badSystemIdentifier = new EnergyTrading.Mdm.Contracts.MdmId { SystemName = "Jim", Identifier = "1", StartDate = start.AddHours(-10), EndDate = start.AddHours(-5) }; var identifierValidator = new NexusIdValidator<PartyRoleMapping>(repository.Object); var validatorEngine = new Mock<IValidatorEngine>(); validatorEngine.Setup(x => x.IsValid(It.IsAny<EnergyTrading.Mdm.Contracts.MdmId>(), It.IsAny<IList<IRule>>())) .Returns((EnergyTrading.Mdm.Contracts.MdmId x, IList<IRule> y) => identifierValidator.IsValid(x, y)); var validator = new BrokerValidator(validatorEngine.Object, repository.Object); var broker = new Broker { Identifiers = new EnergyTrading.Mdm.Contracts.MdmIdList { badSystemIdentifier } }; // Act var violations = new List<IRule>(); var result = validator.IsValid(broker, violations); // Assert Assert.IsFalse(result, "Validator succeeded"); }
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.Sample.Broker>(), It.IsAny<IList<IRule>>())).Returns(true); var service = new BrokerService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object); var cd = new EnergyTrading.MDM.Contracts.Sample.BrokerDetails { Name = "Test" }; var nexus = new EnergyTrading.Mdm.Contracts.SystemData { StartDate = new DateTime(2012, 1, 1) }; var contract = new EnergyTrading.MDM.Contracts.Sample.Broker { Details = cd, MdmSystemData = nexus }; var details = new BrokerDetails { Id = 2, Name = "Test" }; var entity = new Broker(); entity.AddDetails(details); repository.Setup(x => x.FindOne<Broker>(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 BrokerService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object); var cd = new EnergyTrading.MDM.Contracts.Sample.BrokerDetails { Name = "Test" }; var nexus = new EnergyTrading.Mdm.Contracts.SystemData { StartDate = new DateTime(2012, 1, 1) }; var contract = new EnergyTrading.MDM.Contracts.Sample.Broker { Details = cd, MdmSystemData = nexus }; validatorFactory.Setup(x => x.IsValid(It.IsAny<EnergyTrading.MDM.Contracts.Sample.Broker>(), 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"); }
protected static void Establish_context() { client = new HttpClient(); var broker = new EnergyTrading.MDM.Contracts.Sample.Broker(); content = HttpContentExtensions.CreateDataContract(broker); }
public static EnergyTrading.MDM.Contracts.Sample.Broker CreateContractForEntityCreation() { var contract = new EnergyTrading.MDM.Contracts.Sample.Broker(); AddDetailsToContract(contract); return contract; }
protected static void Because_of() { asof = Script.baseDate.AddSeconds(1); client = new HttpClient(ServiceUrl["Broker"] + string.Format("{0}?as-of={1}", broker.Id.ToString(), asof.ToString(DateFormatString))); HttpResponseMessage response = client.Get(); returnedBroker = response.Content.ReadAsDataContract<EnergyTrading.MDM.Contracts.Sample.Broker>(); }
public void ValidBrokerPasses() { // Assert var start = new DateTime(1999, 1, 1); var system = new MDM.SourceSystem { Name = "Test" }; var systemList = new List<MDM.SourceSystem> { system }; var systemRepository = new Mock<IRepository>(); var repository = new StubValidatorRepository(); systemRepository.Setup(x => x.Queryable<MDM.SourceSystem>()).Returns(systemList.AsQueryable()); var identifier = new EnergyTrading.Mdm.Contracts.MdmId { SystemName = "Test", Identifier = "1", StartDate = start.AddHours(-10), EndDate = start.AddHours(-5) }; var validatorEngine = new Mock<IValidatorEngine>(); var validator = new BrokerValidator(validatorEngine.Object, repository); var broker = new Broker { Details = new EnergyTrading.MDM.Contracts.Sample.BrokerDetails{Name = "Test"}, Identifiers = new EnergyTrading.Mdm.Contracts.MdmIdList { identifier } }; this.AddRelatedEntities(broker); // Act var violations = new List<IRule>(); var result = validator.IsValid(broker, violations); // Assert Assert.IsTrue(result, "Validator failed"); Assert.AreEqual(0, violations.Count, "Violation count 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.Sample.BrokerDetails { Name = "Test" }; 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.Sample.Broker { Details = cd, MdmSystemData = nexus }; contract.Identifiers.Add(identifier); // Domain var system = new SourceSystem { Name = "Test" }; var mapping = new PartyRoleMapping { System = system, MappingValue = "A" }; var d1 = new BrokerDetails { Id = 1, Name = "Test", Timestamp = 74UL.GetVersionByteArray() }; var entity = new Broker() { Party = new Party() { Id = 999 } }; entity.AddDetails(d1); var d2 = new BrokerDetails { Name = "Test" }; 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.Sample.Broker>(), It.IsAny <IList <IRule> >())).Returns(true); repository.Setup(x => x.FindOne <Broker>(1)).Returns(entity); mappingEngine.Setup(x => x.Map <EnergyTrading.MDM.Contracts.Sample.BrokerDetails, BrokerDetails>(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, PartyRoleMapping>(identifier)).Returns(mapping); var service = new BrokerService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object); // Act service.Update(1, 74, contract); // Assert Assert.AreEqual(2, entity.Details.Count, "Details count differs"); Assert.AreEqual(1, entity.Mappings.Count, "Mapping count differs"); repository.Verify(x => x.Save(entity)); repository.Verify(x => x.Flush()); }
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.Sample.BrokerDetails { Name = "Test" }; 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.Sample.Broker { Details = cd, MdmSystemData = nexus }; contract.Identifiers.Add(identifier); // Domain var system = new SourceSystem { Name = "Test" }; var mapping = new PartyRoleMapping { System = system, MappingValue = "A" }; var d1 = new BrokerDetails { Id = 1, Name = "Test", Timestamp = 74UL.GetVersionByteArray() }; var entity = new Broker() { Party = new Party() { Id = 999 } }; entity.AddDetails(d1); var d2 = new BrokerDetails { Name = "Test" }; 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.Sample.Broker>(), It.IsAny<IList<IRule>>())).Returns(true); repository.Setup(x => x.FindOne<Broker>(1)).Returns(entity); mappingEngine.Setup(x => x.Map<EnergyTrading.MDM.Contracts.Sample.BrokerDetails, BrokerDetails>(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, PartyRoleMapping>(identifier)).Returns(mapping); var service = new BrokerService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object); // Act service.Update(1, 74, contract); // Assert Assert.AreEqual(2, entity.Details.Count, "Details count differs"); Assert.AreEqual(1, entity.Mappings.Count, "Mapping count differs"); repository.Verify(x => x.Save(entity)); repository.Verify(x => x.Flush()); }