public void Then_Email_Is_Set()
        {
            //Act
            var actual = _personMapping.Map(_employerUser);

            //Assert
            Assert.AreEqual(_employerUser.Email, actual.Email);
        }
        public IActionResult Get()
        {
            var data = _repository.Get();

            var aliases  = data.Select(d => d.Alias);
            var userData = _identityService.GetUsers(aliases);

            var result = _mapper.Map(data, userData.EmailAddresses).ToList();

            return(Ok(result));
        }
        public void Map_FirstLastNameSet_SetFullNameInPersonInfo()
        {
            var person = new Person
            {
                FirstName   = "Bob",
                LastName    = "Martin",
                DateOfBirth = new DateTime(1960, 06, 21)
            };

            var personInfo = _mapper.Map(person);

            Assert.AreEqual("Bob Martin", personInfo.Name);
        }
예제 #4
0
        public IEnumerable <PersonVM> GetAllFriendsForUser(string username = "******")
        {
            var context = new hackathon_shift_2016_testEntities();
            var id      = context.Person.Single(_person => _person.Username == username).Id;

            //context.Dispose();

            context = new hackathon_shift_2016_testEntities();
            var friends = context.PersonSubscription.Where(_person => _person.SubscriberID == id);
            //context.Dispose();

            var viewModels = new List <PersonVM>();

            foreach (var friend in friends)
            {
                context = new hackathon_shift_2016_testEntities();
                var _person = context.Person.SingleOrDefault(person => person.Id == friend.Id);
                if (_person != null)
                {
                    viewModels.Add(PersonMapper.Map(_person));
                }
                //context.Dispose();
            }

            return(viewModels);
        }
예제 #5
0
        public void Map_Theory(string name, PersonGender?gender, int?age, int?numberOfPets)
        {
            var mapper = new PersonMapper();
            var pets   = new List <PetDto>();

            if (numberOfPets == null)
            {
                pets = null;
            }
            else
            {
                for (var i = 0; i < numberOfPets; i++)
                {
                    pets.Add(new PetDto {
                        Name = $"name{i}"
                    });
                }
            }

            var model = mapper.Map(new PersonDto
            {
                Name   = name,
                Gender = gender,
                Age    = age,
                Pets   = pets
            });

            Assert.Equal(name, model.Name);
            Assert.Equal(age ?? 0, model.Age);
            Assert.Equal(gender ?? PersonGender.Other, model.Gender);
            Assert.NotNull(model.Pets);
            Assert.Equal(numberOfPets ?? 0, model.Pets.Count());
        }
예제 #6
0
        public async Task <Person> GetPersonByID(Guid id)
        {
            var param = new DynamicParameters();

            param.Add("@ID", id);

            var personMapper = new PersonMapper();

            return((await SqlMapper.QueryAsync(
                        _unitOfWork.Connection,
                        "GetPersonByID",
                        new[]
            {
                typeof(Person),
                typeof(ContactInfo)
            },
                        obj =>
            {
                var person = obj[0] as Person;
                var contactinfo = obj[1] as ContactInfo;

                return personMapper.Map(person, contactinfo);
            },
                        param,
                        splitOn: "ID,ContactID",
                        commandType: CommandType.StoredProcedure,
                        transaction: _unitOfWork.Transaction))?.FirstOrDefault());
        }
        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");
        }
예제 #8
0
        public SidebarVM GetSidebarData()
        {
            var person = context.Person
                         .FirstOrDefault(p => p.Id == currentlyLoggedInUserId);

            var friends = context.Person
                          .Where(p => p.Id != currentlyLoggedInUserId)
                          .Take(3)
                          .ToList()
                          .Select(PersonMapper.Map)
                          .ToList();

            var events = context.Event
                         .Take(3)
                         .ToList()
                         .Select(EventMapper.Map)
                         .ToList();

            context.Dispose();

            var result = new SidebarVM
            {
                User    = PersonMapper.Map(person),
                Friends = friends,
                Events  = events
            };

            return(result);
        }
        public void Add(PersonBusiness person)
        {
            var entity = PersonMapper.Map(person);

            databaseContext.Person.Add(entity);
            databaseContext.SaveChanges();
        }
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            PersonMapper.Map(modelBuilder);
            PersonRelationMapper.Map(modelBuilder);
            PhoneNumberMapper.Map(modelBuilder);
            CityMapper.Map(modelBuilder);

            base.OnModelCreating(modelBuilder);
        }
        public void Update(PersonBusiness person)
        {
            var entity = databaseContext.Person.Find(person.Id);

            if (entity != null)
            {
                entity = PersonMapper.Map(person);
                databaseContext.SaveChanges();
            }
        }
예제 #12
0
        public PersonVM GetByUsername(string username)
        {
            var context = new Model.hackathon_shift_2016_testEntities();

            var viewModel = PersonMapper.Map(context.Person.Single(person => person.Username == username));

            context.Dispose();

            return(viewModel);
        }
예제 #13
0
        public PersonVM Get(int id)
        {
            if (id == 0)
            {
                id = 14; //14 is currently logged in user
            }
            var context   = new Model.hackathon_shift_2016_testEntities();
            var viewModel = PersonMapper.Map(context.Person.Single(person => person.Id == id));

            context.Dispose();

            return(viewModel);
        }
예제 #14
0
        public async Task <ActionResult <BLL.App.DTO.Person> > PostPerson(Person person)
        {
            var prePerson = await _bll.Persons.OnePerson(User.UserId());

            person.AppUserId = User.UserId();
            person.FamilyId  = prePerson.FamilyId;

            var bllEntity = _mapper.Map(person);

            _bll.Persons.Add(bllEntity);
            await _bll.SaveChangesAsync();

            person.Id = bllEntity.Id;

            return(CreatedAtAction("GetPerson",
                                   new { id = person.Id, version = HttpContext.GetRequestedApiVersion()?.ToString() ?? "0" },
                                   person));
        }
        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");
        }
예제 #16
0
        public void Update(PersonVM personData)
        {
            var dataModel = PersonMapper.Map(personData);

            using (var context = new Model.hackathon_shift_2016_testEntities())
            {
                var personToUpdate = context.Person.Single(p => p.Id == dataModel.Id);

                personToUpdate.Username  = dataModel.Username;
                personToUpdate.FirstName = dataModel.FirstName;
                personToUpdate.LastName  = dataModel.LastName;
                personToUpdate.Password  = dataModel.Password;
                personToUpdate.BirthDate = dataModel.BirthDate;
                personToUpdate.Rating    = dataModel.Rating;
                personToUpdate.Email     = dataModel.Email;
                personToUpdate.ImageUrl  = dataModel.ImageUrl;

                context.SaveChanges();
            }
        }
예제 #17
0
        public void Map_ReturnsListOfRecords()
        {
            int id        = 123;
            var firstName = "first name";
            var lastName  = "Last Name";
            int age       = 88;

            _mockReader.Setup(row => row["Id"])
            .Returns(id);
            _mockReader.Setup(row => row["FirstName"])
            .Returns(firstName);
            _mockReader.Setup(row => row["LastName"])
            .Returns(lastName);
            _mockReader.Setup(row => row["Age"])
            .Returns(age);
            var sut    = new PersonMapper();
            var result = sut.Map(_mockReader.Object);

            Assert.AreEqual(1, result.Count);
            Assert.AreEqual(id, result[0].Id);
            Assert.AreEqual(firstName, result[0].FirstName);
            Assert.AreEqual(lastName, result[0].LastName);
            Assert.AreEqual(age, result[0].Age);
        }
예제 #18
0
        public static void SavePerson(PersonVm person)
        {
            var personDm = PersonMapper.Map(person);

            PersonDAL.SavePersonData(personDm);
        }
예제 #19
0
        public static PersonVm GetPerson()
        {
            var person = PersonDAL.GetPersonData();

            return(PersonMapper.Map(person));
        }
예제 #20
0
 public async Task <PersonModel> CreatePerson(PersonModel model)
 {
     return(_personMapper.Map(await _personRepository.AddAsync(_personMapper.MapBack(model))));
 }
 public PersonBusiness GetByid(int id)
 {
     return((from p in databaseContext.Person where p.Id == id select PersonMapper.Map(p)).FirstOrDefault());
 }
 public List <PersonBusiness> GetAll()
 {
     return((from p in databaseContext.Person select PersonMapper.Map(p)).ToList());
 }