public void AddMappingToExpiredEntityNotAllowed()
        {
            var start  = new DateTime(2000, 12, 31);
            var finish = DateUtility.Round(SystemTime.UtcNow().AddDays(-1));
            var entity = new Person();

            var d1 = new PersonDetails
            {
                Person   = entity,
                Validity = new DateRange(start, finish)
            };

            // NB Must bypass business rules to set up
            entity.Details.Add(d1);

            var s1 = new SourceSystem {
                Name = "Test"
            };
            var m1 = new PersonMapping {
                System = s1, MappingValue = "1", Validity = new DateRange(start, DateUtility.MaxDate)
            };

            try
            {
                entity.ProcessMapping(m1);
            }
            catch (ArgumentOutOfRangeException ex)
            {
                Assert.IsTrue(ex.Message.StartsWith("Cannot change mapping for expired entity"));
                throw;
            }
        }
示例#2
0
        public void LazyMapping_Test()
        {
            var mapping = new PersonMapping();

            AssertExtension.IsTrue(mapping.GetMappingValue(1).Name == "A", 0, 0);
            AssertExtension.IsTrue(mapping.GetMappingValue(2).Name == "B", 0, 1);
        }
        public void AddTwoOverlapValidity()
        {
            var start  = new DateTime(2000, 12, 31);
            var start2 = new DateTime(2010, 1, 1);
            var entity = new Person();

            var s1 = new SourceSystem {
                Name = "Test"
            };
            var m1 = new PersonMapping {
                System = s1, MappingValue = "1", Validity = new DateRange(start, DateUtility.MaxDate)
            };
            var m2 = new PersonMapping {
                System = s1, MappingValue = "1", Validity = new DateRange(start2, DateUtility.MaxDate)
            };
            var m3 = new PersonMapping {
                System = s1, MappingValue = "1", Validity = new DateRange(start.AddDays(2), DateUtility.MaxDate)
            };

            entity.ProcessMapping(m1);
            entity.ProcessMapping(m2);
            try
            {
                entity.ProcessMapping(m3);
            }
            catch (ArgumentOutOfRangeException ex)
            {
                Assert.IsTrue(ex.Message.StartsWith("Validity range starts on or before start of latest range"));
                throw;
            }
        }
        public async Task <IActionResult> PutPersonMapping(int id, PersonMapping PersonMapping)
        {
            if (id != PersonMapping.PersonMappingId)
            {
                return(BadRequest());
            }

            _context.Entry(PersonMapping).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PersonMappingExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <ActionResult <PersonMapping> > PostPersonMapping(PersonMapping PersonMapping)
        {
            _context.PersonMapping.Add(PersonMapping);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetPersonMapping", new { id = PersonMapping.PersonMappingId }, PersonMapping));
        }
        public void UpdateIncompatibleMapping()
        {
            var start  = new DateTime(2000, 12, 31);
            var finish = DateUtility.Round(SystemTime.UtcNow().AddDays(5));
            var entity = new Person();

            var s1 = new SourceSystem {
                Name = "Test"
            };
            var m1 = new PersonMapping {
                Id = 12, System = s1, MappingValue = "1", Validity = new DateRange(start, DateUtility.MaxDate)
            };
            var m2 = new PersonMapping {
                Id = 12, System = s1, MappingValue = "2", Validity = new DateRange(start, finish)
            };

            // NB We deliberately bypasses the business logic
            m1.Person = entity;
            entity.Mappings.Add(m1);
            try
            {
                entity.ProcessMapping(m2);
            }
            catch (ArgumentOutOfRangeException ex)
            {
                Assert.IsTrue(ex.Message.StartsWith("Mapping not compatible"));
                throw;
            }
        }
        public void OverlappingIdentifierFails()
        {
            // 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 expected = new PersonMapping { System = system, MappingValue = "1", Validity = validity };
            var list = new System.Collections.Generic.List<PersonMapping> { expected };
            var repository = new Mock<IRepository>();
            repository.Setup(x => x.Queryable<PersonMapping>()).Returns(list.AsQueryable());

            var identifier = new EnergyTrading.Mdm.Contracts.MdmId
            {
                SystemName = "Test",
                Identifier = "1",
                StartDate = start.AddHours(5),
                EndDate = start.AddHours(10)
            };

            var request = new AmendMappingRequest() { EntityId = 1, Mapping = identifier, MappingId = 1 };

            var rule = new AmendMappingNoOverlappingRule<PersonMapping>(repository.Object);

            // Act
            var result = rule.IsValid(request);

            // Assert
            repository.Verify(x => x.Queryable<PersonMapping>());
            Assert.IsFalse(result, "Rule failed");
        }
示例#8
0
        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 PersonService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object);

            var message = new AmendMappingRequest
            {
                MappingId = 12,
                Mapping   = new MdmId {
                    SystemName = "Test", Identifier = "A"
                },
                Version = 34
            };

            var person = new MDM.Person();

            person.AddDetails(new MDM.PersonDetails()
            {
                Timestamp = BitConverter.GetBytes(25L)
            });
            var mapping = new PersonMapping {
                Person = person
            };

            validatorFactory.Setup(x => x.IsValid(It.IsAny <AmendMappingRequest>(), It.IsAny <IList <IRule> >())).Returns(true);
            repository.Setup(x => x.FindOne <PersonMapping>(12)).Returns(mapping);

            // Act
            service.UpdateMapping(message);
        }
        protected static void Because_of()
        {
            entity = Script.PersonData.CreateBasicEntityWithOneMapping();
            mapping = entity.Mappings[0];
            client = new HttpClient(ServiceUrl["Person"] + string.Format("{0}/mapping/{1}", entity.Id, mapping.Id));

            response = client.Get();
            mappingResponse = response.Content.ReadAsDataContract<EnergyTrading.Mdm.Contracts.MappingResponse>();
        }
示例#10
0
        protected static void Because_of()
        {
            entity  = Script.PersonData.CreateBasicEntityWithOneMapping();
            mapping = entity.Mappings[0];
            client  = new HttpClient(ServiceUrl["Person"] + string.Format("{0}/mapping/{1}", entity.Id, mapping.Id));

            response        = client.Get();
            mappingResponse = response.Content.ReadAsDataContract <EnergyTrading.Mdm.Contracts.MappingResponse>();
        }
示例#11
0
 public int SavePerson(Contoso.Apps.Insurance.Data.DTOs.Person person)
 {
     using (var actions = new PersonActions())
     {
         var personModel = PersonMapping.MapDtoToEntity(person);
         actions.SavePerson(personModel);
         person.Id = personModel.Id;
     }
     return(person.Id);
 }
示例#12
0
 public int SavePerson(Data.DTOs.Person person)
 {
     using (var actions = new PersonActions(_connectionString))
     {
         var personModel = PersonMapping.MapDtoToEntity(person);
         actions.SavePerson(personModel);
         person.Id = personModel.Id;
     }
     return(person.Id);
 }
示例#13
0
        // GET api/people/5
        public Data.DTOs.Person GetPerson(int id)
        {
            Data.DTOs.Person person;

            using (var ctx = new ContosoInsuranceContext(_connectionString))
            {
                person = PersonMapping.MapEntityToDto(ctx.People.FirstOrDefault(p => p.Id == id));
            }

            return(person);
        }
示例#14
0
        public Contoso.Apps.Insurance.Data.DTOs.Person GetPerson(int id)
        {
            Contoso.Apps.Insurance.Data.DTOs.Person person;

            using (var ctx = new ContosoInsuranceContext())
            {
                person = PersonMapping.MapEntityToDto(ctx.People.FirstOrDefault(p => p.Id == id));
            }

            return(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");
        }
示例#16
0
 public static void UpdatePersonUuid(string cprNumber, Guid uuid)
 {
     using (var dataContext = new PartDataContext())
     {
         PersonMapping map = new PersonMapping()
         {
             CprNumber = cprNumber,
             UUID      = uuid
         };
         dataContext.PersonMappings.InsertOnSubmit(map);
         dataContext.SubmitChanges();
     }
 }
        public void AddFirst()
        {
            var entity = new Person();
            var system = new SourceSystem {
                Name = "Test"
            };
            var mapping = new PersonMapping {
                System = system, MappingValue = "1", Validity = DateRange.MaxDateRange
            };

            entity.ProcessMapping(mapping);

            Assert.AreEqual(1, entity.Mappings.Count, "Count differs");
        }
        public void UpdateNonExistentMapping()
        {
            var entity  = new Person();
            var details = new PersonDetails {
                Id = 12, FirstName = "John", LastName = "Smith"
            };

            entity.AddDetails(details);

            var mapping = new PersonMapping {
                Id = 34
            };

            entity.ProcessMapping(mapping);
        }
        public override StandardReturType ValidateInput()
        {
            if (PersonUuids == null)
            {
                return(StandardReturType.NullInput());
            }
            else
            {
                /*
                 * I'm not entirely sure if any single element is allowed to be empty, but not the entire set or if no element may be empty.
                 * Therefore the two different attempts.
                 */
                // Not any empty elements are allowed
                foreach (Guid person in PersonUuids)
                {
                    if (person == Guid.Empty || person == null)
                    {
                        return(StandardReturType.NullInput());
                    }
                }
                // Random empty elements are allowed, but not the entire set
                int count = 0;
                foreach (Guid person in PersonUuids)
                {
                    if (person != null && person != Guid.Empty)
                    {
                        count++;
                    }
                }
                if (PersonIdentifiers.Length != count)
                {
                    return(StandardReturType.NullInput());
                }
            }


            PersonIdentifiers = PersonMapping.GetPersonIdentifiers(PersonUuids);

            foreach (PersonIdentifier pi in PersonIdentifiers)
            {
                if (pi == null)
                {
                    return(StandardReturType.NullInput());
                }
            }

            return(StandardReturType.OK());
        }
示例#20
0
        public void Should_Be_Readed_A_Line_Using_Mapping()
        {
            //Arrange
            var readFile = new ReadFile(LoadFakerFile("Pessoa.txt"), ";", true);

            var personMapping = new PersonMapping();
            var person        = readFile.ReadCurrentLine(personMapping);

            //Act
            var validTest = readFile.ReadText("nome") == person.FirstName &&
                            readFile.ReadText("sobrenome") == person.LastName &&
                            readFile.ReadText("email") == person.Mail;

            //Assert
            validTest.Should().BeTrue();
        }
示例#21
0
        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 PersonService(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 PersonMapping {
                Id = 12, System = s1, MappingValue = "1", Version = 34UL.GetVersionByteArray(), Validity = new DateRange(start, DateUtility.MaxDate)
            };
            var m2 = new PersonMapping {
                Id = 12, System = s1, MappingValue = "1", Validity = new DateRange(start, finish)
            };

            // NB We deliberately bypasses the business logic
            var person = new MDM.Person();

            m1.Person = person;
            person.Mappings.Add(m1);

            validatorFactory.Setup(x => x.IsValid(It.IsAny <AmendMappingRequest>(), It.IsAny <IList <IRule> >())).Returns(true);
            repository.Setup(x => x.FindOne <PersonMapping>(12)).Returns(m1);
            mappingEngine.Setup(x => x.Map <EnergyTrading.Mdm.Contracts.MdmId, PersonMapping>(identifier)).Returns(m2);

            // Act
            service.UpdateMapping(message);

            // Assert
            // NB Don't verify result of Update - already covered by PersonMappingFixture
            repository.Verify(x => x.Save(person));
            repository.Verify(x => x.Flush());
        }
示例#22
0
        public void SavePerson(Person person)
        {
            if (person.Id > 0)
            {
                var pModel = _db.People.FirstOrDefault(p => p.Id == person.Id);
                if (pModel != null)
                {
                    PersonMapping.CopyPropertiesForUpdate(person, ref pModel);
                }
            }
            else
            {
                _db.People.Add(person);
            }

            _db.SaveChanges();
        }
示例#23
0
        protected static void Establish_context()
        {
            entity = Script.PersonData.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.PersonData.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();
        }
示例#25
0
        public SubMethodInfo[] ToSubMethodInfos()
        {
            var personIdentifiers = PersonMapping.GetPersonIdentifiers(UUIDs.Select(uuid => new Guid(uuid)).ToArray());

            return(personIdentifiers.Select(pId =>
                                            new PeriodLookupSubMethodInfo()
            {
                PersonIdentifier = pId,
                EffectDateFrom = EffectDateFrom.Value,
                EffectDateTo = EffectDateTo.Value,
                LocalDataProviderOption = SourceUsageOrder,
                CurrentResult = null,
                FailIfNoDataProvider = true,
                FailOnDefaultOutput = true,
                Method = null,
                UpdateMethod = null
            }
                                            ).ToArray());
        }
        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 ValidContractAdded()
        {
            // Arrange
            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 <object>(), It.IsAny <IList <IRule> >())).Returns(false);

            var service    = new PersonService(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 PersonMapping {
                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, PersonMapping>(identifier)).Returns(mapping);

            var person = new MDM.Person();

            repository.Setup(x => x.FindOne <MDM.Person>(12)).Returns(person);

            // Act
            var candidate = (PersonMapping)service.CreateMapping(message);

            // Assert
            Assert.AreSame(mapping, candidate);
            repository.Verify(x => x.Save(person));
            repository.Verify(x => x.Flush());
        }
示例#28
0
        public void AddingDetailsTrimsMappingToEntityFinish()
        {
            var start  = new DateTime(2000, 1, 1);
            var finish = DateUtility.Round(SystemTime.UtcNow()).AddDays(3);

            var person = new Person();
            var m1     = new PersonMapping {
                Validity = new DateRange(start, DateTime.MaxValue)
            };

            person.ProcessMapping(m1);

            var d1 = new PersonDetails {
                Validity = new DateRange(start, finish)
            };

            person.AddDetails(d1);

            Assert.AreEqual(finish, m1.Validity.Finish, "Mapping finish differs");
        }
        public MDM.Person CreateBasicEntityWithOneMapping()
        {
            var endur = repository.Queryable<SourceSystem>().Where(system => system.Name == "Endur").First();

            var entity = ObjectMother.Create<Person>();

            var endurMapping = new PersonMapping()
                {
                    MappingValue = Guid.NewGuid().ToString(),
                    System = endur,
                    IsDefault = true,
                    Validity = new DateRange(DateTime.MinValue,  DateTime.MaxValue.Subtract(new TimeSpan(72, 0, 0)))
                };

            entity.ProcessMapping(endurMapping);
            this.repository.Add(entity);
            this.repository.Flush();

            return entity;
        }
示例#30
0
        public MDM.Person CreateBasicEntityWithOneMapping()
        {
            var endur = repository.Queryable <SourceSystem>().Where(system => system.Name == "Endur").First();

            var entity = ObjectMother.Create <Person>();

            var endurMapping = new PersonMapping()
            {
                MappingValue = Guid.NewGuid().ToString(),
                System       = endur,
                IsDefault    = true,
                Validity     = new DateRange(DateTime.MinValue, DateTime.MaxValue.Subtract(new TimeSpan(72, 0, 0)))
            };

            entity.ProcessMapping(endurMapping);
            this.repository.Add(entity);
            this.repository.Flush();

            return(entity);
        }
示例#31
0
        public void OverlappingIdentifierFails()
        {
            // 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 expected = new PersonMapping {
                System = system, MappingValue = "1", Validity = validity
            };
            var list = new System.Collections.Generic.List <PersonMapping> {
                expected
            };
            var repository = new Mock <IRepository>();

            repository.Setup(x => x.Queryable <PersonMapping>()).Returns(list.AsQueryable());

            var identifier = new EnergyTrading.Mdm.Contracts.MdmId
            {
                SystemName = "Test",
                Identifier = "1",
                StartDate  = start.AddHours(5),
                EndDate    = start.AddHours(10)
            };

            var request = new AmendMappingRequest()
            {
                EntityId = 1, Mapping = identifier, MappingId = 1
            };

            var rule = new AmendMappingNoOverlappingRule <PersonMapping>(repository.Object);

            // Act
            var result = rule.IsValid(request);

            // Assert
            repository.Verify(x => x.Queryable <PersonMapping>());
            Assert.IsFalse(result, "Rule failed");
        }
        public void AddTwoDifferentSystems()
        {
            var entity = new Person();
            var s1     = new SourceSystem {
                Name = "Test"
            };
            var m1 = new PersonMapping {
                System = s1, MappingValue = "1", Validity = DateRange.MaxDateRange
            };
            var s2 = new SourceSystem {
                Name = "Bob"
            };
            var m2 = new PersonMapping {
                System = s2, MappingValue = "1", Validity = DateRange.MaxDateRange
            };

            entity.ProcessMapping(m1);
            entity.ProcessMapping(m2);

            Assert.AreEqual(2, entity.Mappings.Count, "Count differs");
        }
示例#33
0
        public void RangeOverlapsStart()
        {
            // Arrange
            var repository = new Mock <IRepository>();
            var pm         = new PersonMapping {
                Validity = this.validity
            };

            var list = new List <PersonMapping> {
                pm
            };

            repository.Setup(x => x.Queryable <PersonMapping>()).Returns(list.AsQueryable());
            var range = new DateRange(this.validity.Start.AddHours(-1), this.validity.Start.AddHours(1));

            // Act
            var candidate = repository.Object.Queryable <PersonMapping>().Overlaps(range).ToList();

            // Assert
            Assert.AreEqual(1, candidate.Count, "Count differs");
        }
        public void DateDuringValidity()
        {
            // Arrange
            var repository = new Mock <IRepository>();
            var pm         = new PersonMapping {
                Validity = this.range
            };

            var list = new List <PersonMapping> {
                pm
            };

            repository.Setup(x => x.Queryable <PersonMapping>()).Returns(list.AsQueryable());
            var date = this.range.Start.AddHours(12);

            // Act
            var candidate = repository.Object.Queryable <PersonMapping>().ValidAt(date).ToList();

            // Assert
            Assert.AreEqual(1, candidate.Count, "Count differs");
        }
        public MDM.Person 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.Person();
            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 PersonMapping()
                {
                    MappingValue = Guid.NewGuid().ToString(),
                    System = trayport,
                    Validity = new DateRange(DateTime.MinValue,  DateTime.MaxValue)
                };

            var endurMapping = new PersonMapping()
                {
                    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;
        }