public async void Index_MemberViewsFriendList_NoFreindRequestsNoFriends_ReturnsCorrectViewModel()
        {
            Member member = new Member
            {
                UserId = UserId,
                RequestedFriendships = new List<Friendship>(),
                ReceivedFriendships = new List<Friendship>()  
            };

            Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake();
            Mock<DbSet<Member>> memberDbSetStub = TestHelpers.GetFakeAsyncDbSet(new List<Member> { member }.AsQueryable());
            memberDbSetStub.Setup(db => db.FindAsync(member.UserId)).ReturnsAsync(member);
            dbStub.Setup(db => db.Members).Returns(memberDbSetStub.Object);
            memberDbSetStub.SetupForInclude();

            Mock<ControllerContext> context = new Mock<ControllerContext>();
            context.Setup(c => c.HttpContext.User.Identity).Returns<IIdentity>(null);
            context.Setup(c => c.HttpContext.User.Identity.IsAuthenticated).Returns(true);

            Mock<IGuidUserIdGetter> idGetterStub = new Mock<IGuidUserIdGetter>();
            idGetterStub.Setup(id => id.GetUserId(It.IsAny<IIdentity>())).Returns(member.UserId);

            FriendListController controller = new FriendListController(dbStub.Object, idGetterStub.Object)
            {
                ControllerContext = context.Object
            };

            var result = await controller.Index() as ViewResult;

            Assert.That(result.Model != null);

            var model = (FriendsListViewModel)result.Model;

            Assert.That(model.PendingReceivedFriendships.Count == 0);
            Assert.That(model.PendingSentFriendships.Count == 0);
            Assert.That(model.ConfirmedFriends.Count == 0);
        }
        public async void Cancel_UserCancelsRequest_DeletesFriendship()
        {
            Friendship received = new Friendship
            {
                ReceiverId = member.UserId,
                Receiver = member,
                RequesterId = otherMember1.UserId,
                Requester = otherMember1,
                RequestStatus = FriendshipRequestStatus.Pending
            };

            Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake();

            Mock<DbSet<Member>> memberDbSetStub = TestHelpers.GetFakeAsyncDbSet(new List<Member> { member, otherMember1 }.AsQueryable());
            memberDbSetStub.Setup(db => db.FindAsync(member.UserId)).ReturnsAsync(member);

            Mock<DbSet<Friendship>> friendshipDbSetStub = TestHelpers.GetFakeAsyncDbSet(new List<Friendship> { received }.AsQueryable());
            friendshipDbSetStub.Setup(db => db.Remove(It.IsAny<Friendship>())).Verifiable();

            dbStub.Setup(db => db.Members).Returns(memberDbSetStub.Object);
            dbStub.Setup(db => db.Friendships).Returns(friendshipDbSetStub.Object);

            Mock<ControllerContext> context = new Mock<ControllerContext>();
            context.Setup(c => c.HttpContext.User.Identity).Returns<IIdentity>(null);
            context.Setup(c => c.HttpContext.User.Identity.IsAuthenticated).Returns(true);

            Mock<IGuidUserIdGetter> idGetterStub = new Mock<IGuidUserIdGetter>();
            idGetterStub.Setup(id => id.GetUserId(It.IsAny<IIdentity>())).Returns(member.UserId);

            FriendListController controller = new FriendListController(dbStub.Object, idGetterStub.Object)
            {
                ControllerContext = context.Object
            };

            await controller.Cancel(otherMember1.UserId);

            Assert.That(
                () =>
                    friendshipDbSetStub.Verify(db => db.Remove(It.IsAny<Friendship>()),
                    Times.Exactly(1)),
                Throws.Nothing);
        }
        public async void AddFriendRequest_AddRequestedNotAcceptedYet_NothingChanged()
        {
            Friendship friendship = new Friendship
            {
                RequesterId = member.UserId,
                Requester = member,
                ReceiverId = otherMember1.UserId,
                Receiver = otherMember1,
                RequestStatus = FriendshipRequestStatus.Pending
            };

            Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake();

            Mock<DbSet<Member>> memberDbSetStub = TestHelpers.GetFakeAsyncDbSet(new List<Member> { member, otherMember1 }.AsQueryable());
            memberDbSetStub.Setup(db => db.FindAsync(member.UserId)).ReturnsAsync(member);

            Mock<DbSet<Friendship>> friendshipDbSetStub = TestHelpers.GetFakeAsyncDbSet(new List<Friendship> { friendship }.AsQueryable());
            friendshipDbSetStub.Setup(db => db.Add(It.IsAny<Friendship>())).Returns<Friendship>(i => i).Verifiable();

            dbStub.Setup(db => db.Members).Returns(memberDbSetStub.Object);
            dbStub.Setup(db => db.Friendships).Returns(friendshipDbSetStub.Object);

            Mock<ControllerContext> context = new Mock<ControllerContext>();
            context.Setup(c => c.HttpContext.User.Identity).Returns<IIdentity>(null);
            context.Setup(c => c.HttpContext.User.Identity.IsAuthenticated).Returns(true);

            Mock<IGuidUserIdGetter> idGetterStub = new Mock<IGuidUserIdGetter>();
            idGetterStub.Setup(id => id.GetUserId(It.IsAny<IIdentity>())).Returns(member.UserId);

            FriendListController controller = new FriendListController(dbStub.Object, idGetterStub.Object)
            {
                ControllerContext = context.Object
            };

            await controller.AddFriendRequest(otherMember1.UserAccount.UserName);

            Assert.That(
                () =>
                    friendshipDbSetStub.Verify(db => db.Add(It.IsAny<Friendship>()),
                    Times.Never),
                Throws.Nothing);
            Assert.That(
                () =>
                    dbStub.Verify(db => db.SaveChangesAsync(),
                    Times.Never),
                Throws.Nothing);
        }
        public async void Decline_DeclineNullFriendship_NothingHappens()
        {
            Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake();

            Mock<DbSet<Member>> memberDbSetStub = TestHelpers.GetFakeAsyncDbSet(new List<Member> { member, otherMember1 }.AsQueryable());
            memberDbSetStub.Setup(db => db.FindAsync(member.UserId)).ReturnsAsync(member);

            Mock<DbSet<Friendship>> friendshipDbSetStub = TestHelpers.GetFakeAsyncDbSet(new List<Friendship>().AsQueryable());
            friendshipDbSetStub.Setup(db => db.Remove(It.IsAny<Friendship>())).Verifiable();

            dbStub.Setup(db => db.Members).Returns(memberDbSetStub.Object);
            dbStub.Setup(db => db.Friendships).Returns(friendshipDbSetStub.Object);

            Mock<ControllerContext> context = new Mock<ControllerContext>();
            context.Setup(c => c.HttpContext.User.Identity).Returns<IIdentity>(null);
            context.Setup(c => c.HttpContext.User.Identity.IsAuthenticated).Returns(true);

            Mock<IGuidUserIdGetter> idGetterStub = new Mock<IGuidUserIdGetter>();
            idGetterStub.Setup(id => id.GetUserId(It.IsAny<IIdentity>())).Returns(member.UserId);

            FriendListController controller = new FriendListController(dbStub.Object, idGetterStub.Object)
            {
                ControllerContext = context.Object
            };

            await controller.Decline(otherMember1.UserId);

            Assert.That(
                () =>
                    friendshipDbSetStub.Verify(db => db.Remove(It.IsAny<Friendship>()),
                    Times.Never),
                Throws.Nothing);
        }
        public async void AddFriendRequest_AddFriendIncorrectUsername_DoesntAddFriendship()
        {
            Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake();

            Mock<DbSet<Member>> memberDbSetStub = TestHelpers.GetFakeAsyncDbSet(new List<Member> { member }.AsQueryable());
            memberDbSetStub.Setup(db => db.FindAsync(member.UserId)).ReturnsAsync(member);

            Mock<DbSet<Friendship>> friendshipDbSetStub = TestHelpers.GetFakeAsyncDbSet(new List<Friendship>().AsQueryable());

            dbStub.Setup(db => db.Members).Returns(memberDbSetStub.Object);
            dbStub.Setup(db => db.Friendships).Returns(friendshipDbSetStub.Object);

            Mock<ControllerContext> context = new Mock<ControllerContext>();
            context.Setup(c => c.HttpContext.User.Identity).Returns<IIdentity>(null);
            context.Setup(c => c.HttpContext.User.Identity.IsAuthenticated).Returns(true);

            Mock<IGuidUserIdGetter> idGetterStub = new Mock<IGuidUserIdGetter>();
            idGetterStub.Setup(id => id.GetUserId(It.IsAny<IIdentity>())).Returns(member.UserId);

            FriendListController controller = new FriendListController(dbStub.Object, idGetterStub.Object)
            {
                ControllerContext = context.Object
            };


            Friendship friend = new Friendship()
            {
                ReceiverId = member.UserId,
                RequesterId = otherMember1.UserId,
                RequestStatus = FriendshipRequestStatus.Pending
            };

            dbStub.Setup(db => db.Friendships.Add(friend)).Verifiable();

            //otherMember1 isn't in the mocked db
            await controller.AddFriendRequest(otherMember1.UserAccount.UserName);

            Assert.That(
                () =>
                    dbStub.Verify(db => db.Friendships.Add(friend),
                    Times.Never),
                Throws.Nothing);
        }