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);
        }
 partial void AddDetailsToEntity(MDM.Party entity, DateTime startDate, DateTime endDate)
 {
     entity.AddDetails(
         new PartyDetails()
     {
         Name = Guid.NewGuid().ToString(), Validity = new DateRange(startDate, endDate)
     });
 }
        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");
        }