Exemplo n.º 1
0
        public void RepositoryTestCrate()
        {
            var mock = new Mock <IRepository <PDomain.Person> >();

            mock.Setup(a => a.Create(persone));
            mock.Setup(a => a.GetByID(persone.ID)).Returns(persone);
            PersonServices  service = new PersonServices(mock.Object);
            PersonViewModel p       = service.ToViewModel(persone);

            service.Add(p);
            PersonViewModel personSavedVM = service.GetById(persone.ID);

            PDomain.Person personSaved = service.FromViewModel(personSavedVM);
            Assert.AreEqual(personSavedVM.ToString(), p.ToString());
            Assert.AreEqual(personSaved.ToString(), persone.ToString());
        }
Exemplo n.º 2
0
 public PersonViewModel ToViewModel(Person personR)
 {
     PersonViewModel personVM = new PersonViewModel()
     {
         Id = personR.ID,
         FirstName = personR.FirstName,
         LastName = personR.LastName,
         Age = personR.Age,
         PhoneNumbers = new List<PhoneNumberViewModel>()
     };
     if (personR.phonenumbers != null)
     {
         foreach (var pn in personR.phonenumbers)
         {
             personVM.PhoneNumbers.Add(new PhoneNumberViewModel()
             {
                 Id = pn.ID,
                 PhoneNumber = pn.PhoneNumber,
                 PhoneNumberType = pn.PhoneNumberType
             });
         }
     }
     return personVM;
 }
Exemplo n.º 3
0
 private Person FromViewModel(PersonViewModel person)
 {
     Person personR = new Person()
     {
         ID = person.Id,
         FirstName = person.FirstName,
         LastName = person.LastName,
         Age = person.Age,
         phonenumbers = new List<PhoneNumbers>()
     };
     foreach (var pn in person.PhoneNumbers)
     {
         if (pn.PhoneNumberType == null)
         {
             throw new ArgumentException();
         }
         personR.phonenumbers.Add(new PhoneNumbers()
         {
             ID = pn.Id,
             PersonID = person.Id,
             PhoneNumber = pn.PhoneNumber,
             PhoneNumberType = pn.PhoneNumberType,
         });
     }
     return personR;
 }