protected override void Because_of() { var bobSmith = new EnergyTrading.MDM.Contracts.Sample.Person() { Details = new EnergyTrading.MDM.Contracts.Sample.PersonDetails() { Forename = "Bob", Surname = "Smith" } }; var fredJones = new EnergyTrading.MDM.Contracts.Sample.Person() { Details = new EnergyTrading.MDM.Contracts.Sample.PersonDetails() { Forename = "Fred", Surname = "Jones" } }; var personList = new List <EnergyTrading.MDM.Contracts.Sample.Person>() { bobSmith, fredJones }; var cacheSearchResultPage = new CacheSearchResultPage(new List <int>() { 1, 2 }, DateTime.Now, null, this.currentSearch.ToString()); var searchResultPage = new SearchResultPage <EnergyTrading.MDM.Contracts.Sample.Person>(cacheSearchResultPage, personList); this.response = this.Sut.CreateFeed(searchResultPage, "Person", this.baseUri); }
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.Person>(), It.IsAny <IList <IRule> >())).Returns(true); var service = new PersonService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object); var cd = new EnergyTrading.MDM.Contracts.Sample.PersonDetails { Forename = "John", Surname = "Smith", Email = "*****@*****.**" }; var nexus = new EnergyTrading.Mdm.Contracts.SystemData { StartDate = new DateTime(2012, 1, 1) }; var contract = new EnergyTrading.MDM.Contracts.Sample.Person { Details = cd, MdmSystemData = nexus }; var details = new PersonDetails { Id = 2, FirstName = "Bill", LastName = "Jones", Email = "*****@*****.**" }; var entity = new Person(); entity.AddDetails(details); repository.Setup(x => x.FindOne <Person>(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 EnergyTrading.Mdm.Contracts.MdmId { SystemName = "Test", Identifier = "A" }; var contractDetails = new EnergyTrading.MDM.Contracts.Sample.PersonDetails(); var contract = new EnergyTrading.MDM.Contracts.Sample.Person { 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 personDetails = new PersonDetails(); var mapping = new PersonMapping(); var mappingEngine = new Mock<IMappingEngine>(); mappingEngine.Setup(x => x.Map<EnergyTrading.Mdm.Contracts.MdmId, PersonMapping>(id)).Returns(mapping); mappingEngine.Setup(x => x.Map<EnergyTrading.MDM.Contracts.Sample.PersonDetails, PersonDetails>(contractDetails)).Returns(personDetails); var mapper = new PersonMapper(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, personDetails.Validity, "Validity differs"); }
protected static void Establish_context() { person = Script.PersonData.CreateContractForEntityCreation(); content = HttpContentExtensions.CreateDataContract(person); client = new HttpClient(); }
public EnergyTrading.MDM.Contracts.Sample.Person CreateContractForEntityCreation() { var contract = new EnergyTrading.MDM.Contracts.Sample.Person(); this.AddDetailsToContract(contract); return(contract); }
protected static void Establish_context() { client = new HttpClient(); var person = new EnergyTrading.MDM.Contracts.Sample.Person(); content = HttpContentExtensions.CreateDataContract(person); }
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 PersonService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object); var cd = new EnergyTrading.MDM.Contracts.Sample.PersonDetails { Forename = "John", Surname = "Smith", Email = "*****@*****.**" }; var nexus = new EnergyTrading.Mdm.Contracts.SystemData { StartDate = new DateTime(2012, 1, 1) }; var contract = new EnergyTrading.MDM.Contracts.Sample.Person { Details = cd, MdmSystemData = nexus }; validatorFactory.Setup(x => x.IsValid(It.IsAny <EnergyTrading.MDM.Contracts.Sample.Person>(), 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 = Script.PersonData.CreateBasicEntity(); var notAMapping = new EnergyTrading.MDM.Contracts.Sample.Person(); content = HttpContentExtensions.CreateDataContract(notAMapping); client = new HttpClient(); }
protected static void Establish_context() { client = new HttpClient(); entity = Script.PersonData.CreateBasicEntity(); var getResponse = client.Get(ServiceUrl["Person"] + entity.Id); updatedContract = getResponse.Content.ReadAsDataContract <EnergyTrading.MDM.Contracts.Sample.Person>(); content = HttpContentExtensions.CreateDataContract(Script.PersonData.MakeChangeToContract(updatedContract)); }
protected static void Because_of() { asof = Script.baseDate.AddSeconds(1); client = new HttpClient(ServiceUrl["Person"] + string.Format("{0}?as-of={1}", person.Id.ToString(), asof.ToString(DateFormatString))); HttpResponseMessage response = client.Get(); returnedPerson = response.Content.ReadAsDataContract <EnergyTrading.MDM.Contracts.Sample.Person>(); }
protected static void Because_of() { using (var client = new HttpClient(ServiceUrl["Person"] + person.Id)) { using (HttpResponseMessage response = client.Get()) { returnedPerson = response.Content.ReadAsDataContract <EnergyTrading.MDM.Contracts.Sample.Person>(); } } }
protected static void Establish_context() { client = new HttpClient(); entity = Script.PersonData.CreateBasicEntity(); var getResponse = client.Get(ServiceUrl["Person"] + entity.Id); updatedContract = getResponse.Content.ReadAsDataContract <EnergyTrading.MDM.Contracts.Sample.Person>(); updatedContract.Details.Forename = "Bob"; updatedContract.Identifiers.Remove(updatedContract.Identifiers.Where(id => id.IsMdmId).First()); content = HttpContentExtensions.CreateDataContract(updatedContract); }
protected static void Because_of() { using (var client = new HttpClient(ServiceUrl["Person"] + person.Id)) { using (HttpResponseMessage response = client.Get()) { returnedPerson = response.Content.ReadAsDataContract<EnergyTrading.MDM.Contracts.Sample.Person>(); } } }
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 SourceSystem { Name = "Test" }; var personMapping = new PersonMapping { System = system, MappingValue = "1", Validity = validity }; var list = new List <PersonMapping> { personMapping }; var repository = new Mock <IRepository>(); repository.Setup(x => x.Queryable <PersonMapping>()).Returns(list.AsQueryable()); var systemList = new List <SourceSystem>(); repository.Setup(x => x.Queryable <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 <PersonMapping>(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 PersonValidator(validatorEngine.Object, null); var person = new EnergyTrading.MDM.Contracts.Sample.Person { Identifiers = new EnergyTrading.Mdm.Contracts.MdmIdList { overlapsRangeIdentifier } }; // Act var violations = new List <IRule>(); var result = validator.IsValid(person, violations); // Assert Assert.IsFalse(result, "Validator succeeded"); }
public static void Compare(EnergyTrading.MDM.Contracts.Sample.Person contract, MDM.Person entity) { PersonDetails detailsToCompare = entity.Details[0]; if (contract.MdmSystemData != null) { detailsToCompare = entity.Details.Where(details => details.Validity.Start == contract.MdmSystemData.StartDate).First(); } Assert.AreEqual(contract.Details.Forename, detailsToCompare.FirstName); Assert.AreEqual(contract.Details.Surname, detailsToCompare.LastName); Assert.AreEqual(contract.Details.FaxNumber, detailsToCompare.Fax); Assert.AreEqual(contract.Details.Role, detailsToCompare.Role); Assert.AreEqual(contract.Details.TelephoneNumber, detailsToCompare.Phone); Assert.AreEqual(contract.Details.Email, detailsToCompare.Email); }
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 PersonService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object); var contract = new EnergyTrading.MDM.Contracts.Sample.Person(); 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 PersonService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object); var contract = new EnergyTrading.MDM.Contracts.Sample.Person(); validatorFactory.Setup(x => x.IsValid(It.IsAny <object>(), It.IsAny <IList <IRule> >())).Returns(false); // Act service.Create(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 EnergyTrading.Mdm.Contracts.MdmId { SystemName = "Test", Identifier = "A" }; var contractDetails = new EnergyTrading.MDM.Contracts.Sample.PersonDetails(); var contract = new EnergyTrading.MDM.Contracts.Sample.Person { 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 personDetails = new PersonDetails(); var mapping = new PersonMapping(); var mappingEngine = new Mock <IMappingEngine>(); mappingEngine.Setup(x => x.Map <EnergyTrading.Mdm.Contracts.MdmId, PersonMapping>(id)).Returns(mapping); mappingEngine.Setup(x => x.Map <EnergyTrading.MDM.Contracts.Sample.PersonDetails, PersonDetails>(contractDetails)).Returns(personDetails); var mapper = new PersonMapper(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, personDetails.Validity, "Validity differs"); }
public void ValidPersonPasses() { // Assert var start = new DateTime(1999, 1, 1); var system = new SourceSystem { Name = "Test" }; var systemList = new List <SourceSystem> { system }; var systemRepository = new Mock <IRepository>(); 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 PersonValidator(validatorEngine.Object, null); var person = new EnergyTrading.MDM.Contracts.Sample.Person { Details = new EnergyTrading.MDM.Contracts.Sample.PersonDetails { Surname = "Test" }, Identifiers = new EnergyTrading.Mdm.Contracts.MdmIdList { identifier } }; // Act var violations = new List <IRule>(); var result = validator.IsValid(person, violations); // Assert Assert.IsTrue(result, "Validator failed"); Assert.AreEqual(0, violations.Count, "Violation count 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 PersonService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object); var cd = new EnergyTrading.MDM.Contracts.Sample.PersonDetails { Forename = "John", Surname = "Smith", Email = "*****@*****.**" }; var nexus = new EnergyTrading.Mdm.Contracts.SystemData { StartDate = new DateTime(2012, 1, 1) }; var contract = new EnergyTrading.MDM.Contracts.Sample.Person { Details = cd, MdmSystemData = nexus }; validatorFactory.Setup(x => x.IsValid(It.IsAny<EnergyTrading.MDM.Contracts.Sample.Person>(), 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 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.Person>(), It.IsAny<IList<IRule>>())).Returns(true); var service = new PersonService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object); var cd = new EnergyTrading.MDM.Contracts.Sample.PersonDetails { Forename = "John", Surname = "Smith", Email = "*****@*****.**" }; var nexus = new EnergyTrading.Mdm.Contracts.SystemData { StartDate = new DateTime(2012, 1, 1) }; var contract = new EnergyTrading.MDM.Contracts.Sample.Person { Details = cd, MdmSystemData = nexus }; var details = new PersonDetails { Id = 2, FirstName = "Bill", LastName = "Jones", Email = "*****@*****.**" }; var entity = new Person(); entity.AddDetails(details); repository.Setup(x => x.FindOne<Person>(1)).Returns(entity); // Act service.Update(1, 1, contract); }
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 PersonService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object); var person = new MDM.Person(); var contract = new EnergyTrading.MDM.Contracts.Sample.Person(); validatorFactory.Setup(x => x.IsValid(It.IsAny<EnergyTrading.MDM.Contracts.Sample.Person>(), It.IsAny<IList<IRule>>())).Returns(true); mappingEngine.Setup(x => x.Map<EnergyTrading.MDM.Contracts.Sample.Person, MDM.Person>(contract)).Returns(person); // Act var expected = service.Create(contract); // Assert Assert.AreSame(expected, person, "Person differs"); repository.Verify(x => x.Add(person)); 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 PersonService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object); var person = new MDM.Person(); var contract = new EnergyTrading.MDM.Contracts.Sample.Person(); validatorFactory.Setup(x => x.IsValid(It.IsAny <EnergyTrading.MDM.Contracts.Sample.Person>(), It.IsAny <IList <IRule> >())).Returns(true); mappingEngine.Setup(x => x.Map <EnergyTrading.MDM.Contracts.Sample.Person, MDM.Person>(contract)).Returns(person); // Act var expected = service.Create(contract); // Assert Assert.AreSame(expected, person, "Person differs"); repository.Verify(x => x.Add(person)); 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 SourceSystem { Name = "Test" }; var personMapping = new PersonMapping { System = system, MappingValue = "1", Validity = validity }; var list = new List<PersonMapping> { personMapping }; var repository = new Mock<IRepository>(); repository.Setup(x => x.Queryable<PersonMapping>()).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<PersonMapping>(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 PersonValidator(validatorEngine.Object, null); var person = new EnergyTrading.MDM.Contracts.Sample.Person { Identifiers = new EnergyTrading.Mdm.Contracts.MdmIdList { badSystemIdentifier } }; // Act var violations = new List<IRule>(); var result = validator.IsValid(person, violations); // Assert Assert.IsFalse(result, "Validator succeeded"); }
protected static void Because_of() { asof = Script.baseDate.AddSeconds(1); client = new HttpClient(ServiceUrl["Person"] + string.Format("{0}?as-of={1}", person.Id.ToString(), asof.ToString(DateFormatString))); HttpResponseMessage response = client.Get(); returnedPerson = response.Content.ReadAsDataContract<EnergyTrading.MDM.Contracts.Sample.Person>(); }
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.PersonDetails { Forename = "John", Surname = "Smith", Email = "*****@*****.**" }; 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.Person { Details = cd, MdmSystemData = nexus }; contract.Identifiers.Add(identifier); // Domain var system = new SourceSystem { Name = "Test" }; var mapping = new PersonMapping { System = system, MappingValue = "A" }; var d1 = new PersonDetails { Id = 1, FirstName = "Bill", LastName = "Jones", Email = "*****@*****.**", Timestamp = 74UL.GetVersionByteArray() }; var entity = new Person(); entity.AddDetails(d1); var d2 = new PersonDetails { FirstName = "John", LastName = "Smith", Email = "*****@*****.**" }; 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.Person>(), It.IsAny <IList <IRule> >())).Returns(true); repository.Setup(x => x.FindOne <Person>(1)).Returns(entity); mappingEngine.Setup(x => x.Map <EnergyTrading.MDM.Contracts.Sample.PersonDetails, PersonDetails>(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, PersonMapping>(identifier)).Returns(mapping); var service = new PersonService(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 EnergyTrading.MDM.Contracts.Sample.Person CreateContractForEntityCreation() { var contract = new EnergyTrading.MDM.Contracts.Sample.Person(); this.AddDetailsToContract(contract); return contract; }
public void ValidPersonPasses() { // Assert var start = new DateTime(1999, 1, 1); var system = new SourceSystem { Name = "Test" }; var systemList = new List<SourceSystem> { system }; var systemRepository = new Mock<IRepository>(); 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 PersonValidator(validatorEngine.Object, null); var person = new EnergyTrading.MDM.Contracts.Sample.Person { Details = new EnergyTrading.MDM.Contracts.Sample.PersonDetails{Surname = "Test"}, Identifiers = new EnergyTrading.Mdm.Contracts.MdmIdList { identifier } }; // Act var violations = new List<IRule>(); var result = validator.IsValid(person, violations); // Assert Assert.IsTrue(result, "Validator failed"); Assert.AreEqual(0, violations.Count, "Violation count differs"); }
public EnergyTrading.MDM.Contracts.Sample.Person MakeChangeToContract(EnergyTrading.MDM.Contracts.Sample.Person currentContract) { this.AddDetailsToContract(currentContract); currentContract.MdmSystemData.StartDate = currentContract.MdmSystemData.StartDate.Value.AddDays(2); return(currentContract); }
partial void AddDetailsToContract(EnergyTrading.MDM.Contracts.Sample.Person contract);
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.PersonDetails { Forename = "John", Surname = "Smith", Email = "*****@*****.**" }; 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.Person { Details = cd, MdmSystemData = nexus }; contract.Identifiers.Add(identifier); // Domain var system = new SourceSystem { Name = "Test" }; var mapping = new PersonMapping { System = system, MappingValue = "A" }; var d1 = new PersonDetails { Id = 1, FirstName = "Bill", LastName = "Jones", Email = "*****@*****.**", Timestamp = 74UL.GetVersionByteArray() }; var entity = new Person(); entity.AddDetails(d1); var d2 = new PersonDetails { FirstName = "John", LastName = "Smith", Email = "*****@*****.**" }; 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.Person>(), It.IsAny<IList<IRule>>())).Returns(true); repository.Setup(x => x.FindOne<Person>(1)).Returns(entity); mappingEngine.Setup(x => x.Map<EnergyTrading.MDM.Contracts.Sample.PersonDetails, PersonDetails>(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, PersonMapping>(identifier)).Returns(mapping); var service = new PersonService(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()); }