예제 #1
0
        public void GetFriendship_InvalidFriendshipNotFound()
        {
            //Arrange
            Mock <IFriendshipRepository> mockFriendshipRepository = new Mock <IFriendshipRepository>();

            mockFriendshipRepository.Setup(mr => mr.GetFriendship(
                                               It.IsAny <int>(), It.IsAny <int>())).Returns((int i, int j) => friendships.Where(
                                                                                                (x, y) => x.UserId_1 == i && x.UserId_2 == j).SingleOrDefault());

            var controller = new FriendshipsController(mockFriendshipRepository.Object);

            //Act
            Friendship friend = (Friendship)controller.GetFriendship(1, 1).Value;


            //Assert
            Assert.Null(friend);
        }
예제 #2
0
        public void GetFriendship_ValidFriendshipsAreNotNull()
        {
            //Arrange
            Mock <IFriendshipRepository> mockFrienshipRepository = new Mock <IFriendshipRepository>();

            mockFrienshipRepository.Setup(mr => mr.GetFriendship(
                                              It.IsAny <int>(), It.IsAny <int>())).Returns((int i, int j) => friendships.Where(
                                                                                               (x, y) => x.UserId_1 == i && x.UserId_2 == j).SingleOrDefault());

            var controller = new FriendshipsController(mockFrienshipRepository.Object);

            //Act
            Friendship friend = (Friendship)controller.GetFriendship(2, 3).Value;

            Console.WriteLine(friend.UserId_1);

            //Assert
            Assert.IsNotNull(friend);
            Assert.AreEqual(friend, friendships[2]);
        }