public void Add(PersonLogic personLogic)
        {
            var personsAccess = new PersonsAccess();
            var personDB      = personsAccess.FindPersonByName(personLogic.Name);

            if (personDB == null)
            {
                personDB = LogicToDB(personLogic);
                personsAccess.AddPerson(personDB);
            }
        }
        public List <PersonLogic> GetAll()
        {
            var personsAccess = new PersonsAccess();
            var peopleDB      = personsAccess.GetAllPersons();

            var peopleLogic = new List <PersonLogic>();

            peopleDB.ForEach(p => peopleLogic.Add(DBToLogic(p)));

            return(peopleLogic);
        }
Beispiel #3
0
        public void TestPersonsLogin()
        {
            var context     = new cse136Context();
            var access      = new GenericAccess(context);
            var spec_access = new PersonsAccess(context);
            var person      = access.Add(new Persons {
                Age = 12, Email = "*****@*****.**", Name = "MyUnitTest", Password = "******", Sex = "M", Profile = "For unit test"
            });

            Assert.AreEqual("MyUnitTest", person.Name);
            var returned = spec_access.Login(person.Email, person.Password);

            Assert.AreEqual(person, returned);
            access.Delete <Persons>(returned.Id);
        }
Beispiel #4
0
        public void TestPersonGetPersonById()
        {
            var context     = new cse136Context();
            var access      = new GenericAccess(context);
            var spec_access = new PersonsAccess(context);
            var person      = access.Add(new Persons {
                Age = 12, Email = "*****@*****.**", Name = "MyUnitTest", Password = "******", Sex = "M", Profile = "For unit test"
            });

            Assert.AreEqual("MyUnitTest", person.Name);
            var diet_plan_1 = access.Add(new DietPlans {
                Name = "Unit Diet 1", Information = "Unit test diet 1", PersonId = 2
            });
            var diet_plan_2 = access.Add(new DietPlans {
                Name = "Unit Diet 2", Information = "Unit test diet 2", PersonId = 2
            });
            var diet_plan_3 = access.Add(new DietPlans {
                Name = "Unit Diet 3", Information = "Unit test diet 3", PersonId = person.Id
            });
            var pinned_diet_plan1 = access.Add(new PinnedDietPlans {
                DietPlanId = diet_plan_1.Id, PersonId = person.Id
            });
            var pinned_diet_plan2 = access.Add(new PinnedDietPlans {
                DietPlanId = diet_plan_2.Id, PersonId = person.Id
            });
            var followings = access.Add(new Followings {
                Follower = person.Id, Following = 2
            });
            var returned = spec_access.GetPersonById(person.Id);

            // var returned = access.GetById<Persons>(person.Id);
            Assert.AreEqual("MyUnitTest", returned.Name);
            access.Delete <Followings>(followings.Id);
            access.Delete <PinnedDietPlans>(pinned_diet_plan1.Id);
            access.Delete <PinnedDietPlans>(pinned_diet_plan2.Id);
            access.Delete <Persons>(person.Id);
            access.Delete <DietPlans>(diet_plan_1.Id);
            access.Delete <DietPlans>(diet_plan_2.Id);
        }