public async void GetUserById_UserNotExists_ReturnNull(int nonExistantId)
        {
            //Arrange
            ILoggerFactory           loggerFactory = new LoggerFactory();
            ILogger <UserRepository> logger        = loggerFactory.CreateLogger <UserRepository>();
            IList <User>             users         = new List <User> {
                new User()
                {
                    Id          = 1000,
                    Username    = "******",
                    Firstname   = "Test",
                    Lastname    = "Person",
                    Email       = "*****@*****.**",
                    IsSuspended = false,
                    Country     = "Sweden",
                    City        = "Göteborg",
                    Role        = Role.Regular
                },
                GenerateFake.User(),
                GenerateFake.User()
            };

            _mockContext.Setup(x => x.Users).ReturnsDbSet(users);

            //Act
            var user = await _mockRepo.GetUserById(nonExistantId);

            //Assert
            Assert.Null(user);
        }
        public async Task GetConversationsById_ReturnsObjectResult()
        {
            // Arrange
            var conversation = GenerateFake.Conversation();

            _mockRepo.Setup(repo => repo.GetConversationById(conversation.Id))
            .ReturnsAsync(conversation);

            // Act
            var response = await _conversationController.GetConversationById(1);

            // Assert
            Assert.IsAssignableFrom <ObjectResult>(response);
        }
Beispiel #3
0
        public async Task GetPostById_ReturnsOk()
        {
            // Arrange
            var post = GenerateFake.Post();

            _mockRepo.Setup(repo => repo.GetPostById(post.Id))
            .ReturnsAsync(post);

            // Act
            var response = await _postController.GetPostById(post.Id);

            // Assert
            Assert.IsAssignableFrom <ObjectResult>(response);
        }
        public async Task GetUserById_ReturnsObject()
        {
            // Arrange
            var user = GenerateFake.User();

            _mockRepo.Setup(repo => repo.GetUserById(user.Id))
            .ReturnsAsync(user);

            // Act
            var response = await _userController.GetUserById(user.Id);

            // Assert
            Assert.IsAssignableFrom <ObjectResult>(response);
        }
        public async void GetConversations_ConversationsAmount_ReturnsCorrectAmountOfConversations(int expectedAmountConversations)
        {
            //Arrange
            IList<Conversation> conversations = new List<Conversation>();
            for (int i = 0; i < expectedAmountConversations; i++)
            {
                conversations.Add(GenerateFake.Conversation());
            }
            _mockContext.Setup(x => x.Conversations).ReturnsDbSet(conversations);

            //Act
            var conversationsFromRepo = await _mockRepo.GetConversations();

            //Assert
            Assert.Equal(expectedAmountConversations, conversationsFromRepo.Count());
        }
Beispiel #6
0
        public async void GetLikesByPostId_LikesCount_ReturnsZero(int nonExistantPostId)
        {
            // Arrange
            IList <Like> likes = new List <Like> {
                GenerateFake.Like(),
                         GenerateFake.Like(),
                         GenerateFake.Like()
            };

            _mockContext.Setup(x => x.Likes).ReturnsDbSet(likes);

            // Act
            var like = await _mockRepo.GetLikesByPostId(nonExistantPostId);

            // Assert
            Assert.Equal(0, like.Count());
        }
        public async Task GetConversations_ReturnOk()
        {
            //Arrange
            IList <Conversation> conversations = new List <Conversation> {
                GenerateFake.Conversation(),
                                 GenerateFake.Conversation(),
                                 GenerateFake.Conversation()
            };

            _mockRepo.Setup(repo => repo.GetConversations()).ReturnsAsync(conversations);

            //Act
            var response = await _conversationController.GetConversations();

            //Assert
            Assert.IsAssignableFrom <OkObjectResult>(response);
        }
Beispiel #8
0
        public async void GetMessages_MessagesAmount_ReturnsCorrectAmountOfMessages(int expectedAmountMessages)
        {
            //Arrange
            IList <Message> messages = new List <Message>();

            for (int i = 0; i < expectedAmountMessages; i++)
            {
                messages.Add(GenerateFake.Message());
            }
            _mockContext.Setup(x => x.Messages).ReturnsDbSet(messages);

            //Act
            var messagesFromRepo = await _mockRepo.GetMessages();

            //Assert
            Assert.Equal(expectedAmountMessages, messagesFromRepo.Count());
        }
        public async void GetComments_CommentsAmount_ReturnsInCorrectAmountOfComments(int incorrectAmountComments)
        {
            //Arrange
            IList <Comment> comments = new List <Comment>();

            for (int i = 0; i < 2; i++)
            {
                comments.Add(GenerateFake.Comment());
            }
            _mockContext.Setup(x => x.Comments).ReturnsDbSet(comments);

            //Act
            var commentsFromRepo = await _mockRepo.GetComments();

            //Assert
            Assert.NotEqual(incorrectAmountComments, commentsFromRepo.Count());
        }
        public async Task GetUsers_ReturnsOk()
        {
            // Arrange
            IList <User> users = new List <User> {
                GenerateFake.User(),
                         GenerateFake.User(),
                         GenerateFake.User()
            };

            _mockRepo.Setup(repo => repo.GetUsers(""))
            .ReturnsAsync(users);

            // Act
            var response = await _userController.GetUsers();

            // Assert
            Assert.IsAssignableFrom <OkObjectResult>(response);
        }
Beispiel #11
0
        public async Task GetLikesByPostId_ReturnsOk()
        {
            // Arrange
            IList <Like> likes = new List <Like> {
                GenerateFake.Like(),
                         GenerateFake.Like(),
                         GenerateFake.Like()
            };

            _mockRepo.Setup(repo => repo.GetLikesByPostId(1))
            .ReturnsAsync(likes);

            // Act
            var response = await _likesController.GetLikesByPostId(1);

            // Assert
            Assert.IsAssignableFrom <OkObjectResult>(response);
        }
Beispiel #12
0
        public async Task GetPosts_ReturnsObject()
        {
            // Arrange
            IList <Post> posts = new List <Post> {
                GenerateFake.Post(),
                         GenerateFake.Post(),
                         GenerateFake.Post()
            };

            _mockRepo.Setup(repo => repo.GetPosts())
            .ReturnsAsync(posts);

            // Act
            var response = await _postController.GetPosts();

            // Assert
            Assert.IsAssignableFrom <ObjectResult>(response);
        }
        public async void GetConversationById_ConversationNotExists_ReturnsNull(int nonExistantId)
        {
            // Arrange
            IList<Conversation> conversations = new List<Conversation> {
                    new Conversation() {
                       Id = 1000,
                       ConversationName = "This should work."
                    },
                    GenerateFake.Conversation(),
                    GenerateFake.Conversation()
            };
            _mockContext.Setup(x => x.Conversations).ReturnsDbSet(conversations);

            // Act
            var conversation = await _mockRepo.GetConversationById(nonExistantId);

            // Assert
            Assert.Null(conversation);
        }
        public async void GetConversationById_ConversationExists_ReturnsCorrectConversationId(int expectedId)
        {
            // Arrange
            IList<Conversation> conversations = new List<Conversation> {
                    new Conversation() {
                       Id = expectedId,
                       ConversationName = "This should work."
                    },
                    GenerateFake.Conversation(),
                    GenerateFake.Conversation()
            };
            _mockContext.Setup(x => x.Conversations).ReturnsDbSet(conversations);

            // Act
            var conversation = await _mockRepo.GetConversationById(expectedId);

            // Assert
            Assert.Equal(expectedId, conversation.Id);
        }
Beispiel #15
0
        public async void GetLikeByPostId_LikesExist_ReturnsNotNull(int ExistantPostId)
        {
            // Arrange
            IList <Like> likes = new List <Like> {
                new Like()
                {
                    Id = 1, User = GenerateFake.User(), Post = new Post()
                    {
                        Id = ExistantPostId
                    }
                },
                new Like()
                {
                    Id = 2, User = GenerateFake.User(), Post = new Post()
                    {
                        Id = ExistantPostId
                    }
                },
                new Like()
                {
                    Id = 3, User = GenerateFake.User(), Post = new Post()
                    {
                        Id = ExistantPostId
                    }
                },
                new Like()
                {
                    Id = 4, User = GenerateFake.User(), Post = new Post()
                    {
                        Id = ExistantPostId
                    }
                }
            };

            _mockContext.Setup(x => x.Likes).ReturnsDbSet(likes);

            // Act
            var likesList = await _mockRepo.GetLikesByPostId(ExistantPostId);

            // Assert
            Assert.NotNull(likesList);
        }
Beispiel #16
0
        public async void GetMessageById_MessageExists_ReturnsCorrectMessageId(int expectedId)
        {
            // Arrange
            IList <Message> messages = new List <Message> {
                new Message()
                {
                    Id   = expectedId,
                    Text = "This should work."
                },
                GenerateFake.Message(),
                GenerateFake.Message()
            };

            _mockContext.Setup(x => x.Messages).ReturnsDbSet(messages);

            // Act
            var message = await _mockRepo.GetMessageById(expectedId);

            // Assert
            Assert.Equal(expectedId, message.Id);
        }
        public async void GetPosts_PostsAmount_ReturnsCorrectAmountOfPosts(int expectedAmountPosts)
        {
            //Arrange
            ILoggerFactory           loggerFactory = new LoggerFactory();
            ILogger <PostRepository> logger        = loggerFactory.CreateLogger <PostRepository>();
            IList <Post>             posts         = new List <Post>();

            for (int i = 0; i < expectedAmountPosts; i++)
            {
                posts.Add(GenerateFake.Post());
            }
            var dataContext = new Mock <DataContext>();

            dataContext.Setup(x => x.Posts).ReturnsDbSet(posts);
            var postRepository = new PostRepository(dataContext.Object, logger);

            //Act
            var postsFromRepo = await postRepository.GetPosts();

            //Assert
            Assert.Equal(expectedAmountPosts, postsFromRepo.Count());
        }
Beispiel #18
0
        public async void GetMessageById_MessageNotExists_ReturnsNull(int nonExistantId)
        {
            // Arrange
            IList <Message> messages = new List <Message> {
                new Message()
                {
                    Id      = 1000,
                    Text    = "This should work.",
                    Created = DateTime.Now
                },
                GenerateFake.Message(),
                GenerateFake.Message()
            };

            _mockContext.Setup(x => x.Messages).ReturnsDbSet(messages);

            // Act
            var message = await _mockRepo.GetMessageById(nonExistantId);

            // Assert
            Assert.Null(message);
        }
        public async void GetPostById_PostExists_ReturnsCorrectPostId(int expectedId)
        {
            // Arrange
            IList <Post> posts = new List <Post> {
                new Post()
                {
                    Id      = expectedId,
                    Text    = $"This post should have the Id {expectedId}.",
                    Created = DateTime.Now
                },
                GenerateFake.Post(),
                GenerateFake.Post()
            };

            _mockContext.Setup(x => x.Posts).ReturnsDbSet(posts);

            // Act
            var post = await _mockRepo.GetPostById(expectedId);

            // Assert
            Assert.Equal(expectedId, post.Id);
        }
Beispiel #20
0
        public async void GetLikeByPostId_LikesAmount_ReturnsCorrectAmountOfLikes(int expectedAmountLikes, int postId)
        {
            //Arrange
            IList <Like> likes = new List <Like>();

            for (int i = 0; i < expectedAmountLikes; i++)
            {
                likes.Add(new Like()
                {
                    Id = i + 1, User = GenerateFake.User(), Post = new Post()
                    {
                        Id = postId
                    }
                });
            }
            _mockContext.Setup(x => x.Likes).ReturnsDbSet(likes);

            //Act
            var likesFromRepo = await _mockRepo.GetLikesByPostId(postId);

            //Assert
            Assert.Equal(expectedAmountLikes, likesFromRepo.Count());
        }