예제 #1
0
 public void MemberEnsureICanUseObjectInitializerSyntax()
 {
    
     DateTime expected_time = DateTime.Now;
     List<Activities> ListActivities =
        new List<Activities> {
             new Activities {
             ActivityId = 1,
             ActivityName = "run",
             Distance = 2.2,
             Date = expected_time
         },
             new Activities {
             ActivityId = 2,
             ActivityName = "walk",
             Distance = 5.2,
             Date = expected_time
         }
        };
     Member a_member = new Member
     {
         MemberId = 1,
         Family = null,
         FirstName = "Joe",
         Updated = expected_time,
         //Activities = ListActivities
     };
     Assert.AreEqual(1, a_member.MemberId);
     Assert.AreEqual("Joe", a_member.FirstName);
     Assert.AreEqual(null, a_member.Family);
     //Assert.AreEqual(ListActivities, a_member.Activities);
     Assert.AreEqual(expected_time, a_member.Updated);
 }
예제 #2
0
        public void MemberEnsureActivityHasAllTheThings()
        {
            Member a_member = new Member();
            DateTime expected_time = DateTime.Now;
            List<Activities> ListActivities =
               new List<Activities> {
                    new Activities {
                    ActivityId = 1,
                    ActivityName = "run",
                    Distance = 2.2,
                    Date = expected_time
                },
                    new Activities {
                    ActivityId = 2,
                    ActivityName = "walk",
                    Distance = 5.2,
                    Date = expected_time
                }
               };

            a_member.MemberId = 1;
            a_member.Family = null;
            a_member.FirstName = "Joe";
            a_member.Updated = expected_time;
            //a_member.Activities = ListActivities;

            Assert.AreEqual(1, a_member.MemberId);
            Assert.AreEqual("Joe", a_member.FirstName);
            Assert.AreEqual(null, a_member.Family);
            ///Assert.AreEqual(ListActivities, a_member.Activities);
            Assert.AreEqual(expected_time, a_member.Updated);
        }
예제 #3
0
 public List<Activities> GetMembersActivities(Member member)
 {
     if (member != null)
     {
         var person = GetMemberById(member);
         var ActivityQuery = from activity in _context.Activities where activity.Participant.MemberId == person.MemberId select activity;
         var memberActivities = ActivityQuery.ToList();
         return memberActivities;
     }
     else
     {
         return new List<Activities> { new Activities() { ActivityName = "Please Add and Activity" } };
     }
 }
예제 #4
0
 public void MemberEnsureICanCreateInstance()
 {
     Member a_member = new Member();
     Assert.IsNotNull(a_member);
 }
예제 #5
0
 public Member GetMemberById(Member member)
 {
     //string stringMemberId = member.MemberId.ToString();
     var query = from u in _context.Members where u.MemberId == member.MemberId select u;
     return query.SingleOrDefault();
 }
예제 #6
0
        public bool CreateActivity(string activityName, double distance, Member member1)
        {
            Activities an_activity = new Activities { ActivityName = activityName, Distance = distance, Participant = member1, Date = DateTime.Now };
            bool is_added = true;
            try
            {
                Activities added_activities = _context.Activities.Add(an_activity);
                _context.SaveChanges();

            }
            catch (Exception)
            {
                is_added = false;
            }
            return is_added;
        }
예제 #7
0
 public List<Member> GetAllFamilyMembers( Member member)
 {
     
         var query = from u in _context.Members where u.Family == member.Family select u;
         return query.ToList();
 }
예제 #8
0
        public bool CreateGroup(Member member1, string groupName)
        {
            Group a_group = new Group { GroupName = groupName, Members = new List<Member> {  member1 }, Updated = DateTime.Now };
            bool is_added = true;
            try
            {
                Group added_group = _context.Group.Add(a_group);
                _context.SaveChanges();

            }
            catch (Exception)
            {
                is_added = false;
            }
            return is_added;
        }
예제 #9
0
        public bool CreateMember(string firstName, string lastName, Family family1, Group group1)
        {
            Member a_member = new Member { FirstName = firstName, LastName = lastName, Family = family1, Group = group1, Updated = DateTime.Now };
            bool is_added = true;
            try
            {
                Member added_member = _context.Members.Add(a_member);
                _context.SaveChanges();

            }
            catch (Exception)
            {
                is_added = false;
            }
            return is_added;
        }
예제 #10
0
        public void WalkEnsureICanCrateAnActivity()
        {
            List<Activities> expected_activities = new List<Activities>();
            ConnectMocksToDataStore(expected_activities);
            string activityName = "walk";
            double distance = 1.1d;
            Member member1 = new Member { LastName = "Rice" };
            mock_activity_set.Setup(j => j.Add(It.IsAny<Activities>())).Callback((Activities s) => expected_activities.Add(s));
            bool successful = repository.CreateActivity(activityName, distance, member1);

            Assert.AreEqual(1, repository.GetAllActivities().Count);
        }
예제 #11
0
        public void WalkEnsureICanCreateAGroup()
        {
            // Arrange
            List<Group> expected_groups = new List<Group>(); 
            ConnectMocksToDataStore(expected_groups);
            Member Member1 = new Member { LastName = "Rice" };
            string groupName = "St Andrew";
            mock_group_set.Setup(j => j.Add(It.IsAny<Group>())).Callback((Group s) => expected_groups.Add(s));
            // Act
            bool successful = repository.CreateGroup(Member1, groupName);

            // Assert
            Assert.AreEqual(1, repository.GetAllGroups().Count);

        }
예제 #12
0
        public void WalkRepositoryEnsureICanGetMembersActivities()
        {

            var time = DateTime.Now;
            var family = new Family { FamilyName = "Anderson", FamilyId = 1, Updated = time };
            var family2 = new Family { FamilyName = "Anderson", FamilyId = 2, Updated = time };
            var group1 = new Group { GroupId = 1, GroupName = "St. Andrew" };
            var group2 = new Group { GroupId = 2, GroupName = "Fron" };

            var members = new List<Member> {
                new Member { MemberId = 1, LastName = "Anderson", FirstName = "Bernie", Family = family, Updated = time, Group
                 = group1 },
                new Member { MemberId = 2, LastName = "Rice", FirstName = "Laura", Family = family2, Updated = time, Group = group2 },
                new Member { MemberId = 3, LastName = "Anderson", FirstName = "Ruby", Family = family, Updated = time, Group = group1 },
                new Member { MemberId = 4, LastName = "Rice", FirstName = "Adam", Family = family2, Updated = time, Group = group2 },
                new Member { MemberId = 5, LastName = "Anderson", FirstName = "Samuel", Family = family, Updated = time, Group = group1 },
                new Member { MemberId = 6, LastName = "Rice", FirstName = "Noah", Family = family2, Updated = time, Group = group2 }
            };

            mock_member_set.Object.AddRange(members);
            ConnectMocksToDataStore(members);

            var activities = new List<Activities>
            {
                new Activities {ActivityId = 1, ActivityName = "walking", Distance = 1.1d, Date = time, Participant =  members[0]},
                new Activities {ActivityId = 2, ActivityName = "run", Distance = 3.5d, Date = time, Participant =  members[3]},
                new Activities {ActivityId = 3, ActivityName = "swim", Distance = 8d, Date = time, Participant =  members[0] },
                new Activities {ActivityId = 4, ActivityName = "eliptical", Distance = 5d, Date = time, Participant =  members[1] },
                new Activities {ActivityId = 5, ActivityName = "swim", Distance = 6.3d, Date = time, Participant =  members[5]},
                new Activities {ActivityId = 6, ActivityName = "walking", Distance = 7.8d, Date = time, Participant =  members[2]  },
                new Activities {ActivityId = 7, ActivityName = "run", Distance = 12.4d, Date = time, Participant =  members[4] }
            };
            mock_activity_set.Object.AddRange(activities);
            ConnectMocksToDataStore(activities);

            Member Bernie = new Member
            {
                MemberId = 1,
                LastName = "Anderson",
                FirstName = "Bernie",
                Family = family,
                Updated = time,
                Group
                 = group1
            };
            Member Noah = new Member { MemberId = 6, LastName = "Rice", FirstName = "Noah", Family = family2, Updated = time, Group = group2 };

            Member actual = repository.GetMemberById(members[0]);
            var BernieActivities = repository.GetMembersActivities(Bernie);
            var NoahActivities = repository.GetMembersActivities(Noah);

            Assert.AreEqual("walking", BernieActivities.First().ActivityName);
            Assert.AreEqual("swim", BernieActivities[1].ActivityName);
            Assert.AreEqual("swim", NoahActivities.First().ActivityName);
            Assert.AreEqual(6.3d, NoahActivities[0].Distance);

        }
예제 #13
0
        public void WalkContextEnsureCanGetMembersForAFamily()
        {
            var time = DateTime.Now;
            var family = new Family {FamilyName = "Anderson", FamilyId = 1, Updated = time};
            var family2 = new Family { FamilyName = "Anderson", FamilyId = 2, Updated =time};


            var member = new List<Member> {
                new Member { MemberId = 1, LastName = "Anderson", FirstName = "Bernie", Family = family, Updated = time },
                new Member {MemberId = 2, LastName = "Rice", FirstName = "Laura", Family = family2, Updated = time},
                new Member {MemberId = 3, LastName = "Anderson", FirstName = "Ruby", Family = family, Updated = time},
                new Member {MemberId = 4, LastName = "Rice", FirstName = "Adam", Family = family2, Updated = time},
                new Member {MemberId = 5, LastName = "Anderson", FirstName = "Samuel", Family = family, Updated = time},
                new Member {MemberId = 6, LastName = "Rice", FirstName = "Noah", Family = family2, Updated = time}
            };
            mock_member_set.Object.AddRange(member);
            ConnectMocksToDataStore(member);


            var testMember = new Member { MemberId = 1, LastName = "Anderson", FirstName = "Bernie", Family = family };
            var expectedMembers = new List<Member>
            {
                new Member { MemberId = 1, LastName = "Anderson", FirstName = "Bernie", Family = family, Updated = time },
                new Member {MemberId = 3, LastName = "Anderson", FirstName = "Ruby", Family = family, Updated = time},
                new Member {MemberId = 5, LastName = "Anderson", FirstName = "Samuel", Family = family, Updated = time}
            };
            var actual = repository.GetAllFamilyMembers(testMember);

            Assert.AreEqual("Bernie", actual.First().FirstName);
            Assert.AreEqual(expectedMembers[0].Family, actual[0].Family);
            Assert.AreEqual(expectedMembers[0].MemberId, actual[0].MemberId);
            Assert.AreEqual(expectedMembers[1].LastName, actual[1].LastName);
            Assert.AreEqual(expectedMembers[0].Group, actual[0].Group);
            Assert.AreEqual(expectedMembers[0].Updated, actual[0].Updated);
            //Assert.AreEqual(expectedMembers[0], actual[0]);

        }
예제 #14
0
        public void WalkContextEnsureICanGetMemberById()
        {
            var expected = new List<Member> {
                new Member { MemberId = 1, LastName = "Anderson", FirstName = "Bernie" },
                new Member {MemberId = 2, LastName = "Rice", FirstName = "Laura"}
            };
           
            mock_member_set.Object.AddRange(expected);
             ConnectMocksToDataStore(expected);
            Member Anderson = new Member { MemberId = 1, LastName = "Anderson", FirstName = "Bernie" };
            Member actual = repository.GetMemberById(expected[0]);

            Assert.AreEqual("Anderson", actual.LastName);
        }