Ejemplo n.º 1
0
        public async Task GetAsync_WithCorrectId_WorksCorrectly()
        {
            // Arrange
            var conversation = new Conversation();

            var context = new PoolItDbContext(new DbContextOptionsBuilder <PoolItDbContext>()
                                              .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                              .Options);

            context.Conversations.AddRange(
                conversation,
                new Conversation(),
                new Conversation()
                );

            context.SaveChanges();

            var conversationsService = new ConversationsService(new EfRepository <Conversation>(context), null, null);

            // Act
            var result = await conversationsService.GetAsync(conversation.Id);

            // Assert
            Assert.NotNull(result);
        }
Ejemplo n.º 2
0
            public async Task WhenGetConversationParticipantsGetsCalled()
            {
                Setup();

                AuthService.Setup(service => service.GetUserIdFromToken(It.IsAny <string>())).Returns(_userId.ToString());
                ConversationsService.Setup(service => service.GetConversationParticipants(It.IsAny <Guid>()))
                .ReturnsAsync(new Fixture().CreateMany <Guid>().ToList());

                _result = await ConversationsController.GetConversationParticipants(_conversationId);
            }
Ejemplo n.º 3
0
            public async Task WhenGetConversationsGetsCalled()
            {
                Setup();

                AuthService.Setup(service => service.AuthorizeSelf(It.IsAny <string>(), It.IsAny <Guid>())).Returns(true);
                ConversationsService.Setup(service => service.GetConversations(It.IsAny <Guid>()))
                .ReturnsAsync(new List <Conversation>());

                _result = await ConversationsController.GetConversations(_userId);
            }
            public async Task WhenGetConversationParticipantsGetsCalled()
            {
                Setup();

                _conversationParticipants = new Fixture().CreateMany <ConversationParticipant>().ToList();

                ConversationsRepository.Setup(repository =>
                                              repository.GetConversationParticipantsByConversationId(It.IsAny <Guid>()))
                .ReturnsAsync(_conversationParticipants);

                _participantIds = await ConversationsService.GetConversationParticipants(_conversationId);
            }
Ejemplo n.º 5
0
            public async Task WhenCreateConversationGetsCalled()
            {
                Setup();

                AuthService.Setup(service => service.AuthorizeSelf(
                                      It.IsAny <string>(), It.IsAny <Guid>())).Returns(true);
                ConversationsService.Setup(service => service.CreateConversationWithParticipants(
                                               _createConversationRequest.SenderId, _createConversationRequest.ReceiverId))
                .ReturnsAsync(_conversationId);

                _result = await ConversationsController.CreateConversation(_createConversationRequest);
            }
Ejemplo n.º 6
0
            public async Task WhenGetConversationsGetsCalled()
            {
                Setup();

                var fixture = new Fixture();

                _conversationParticipants = fixture.CreateMany <ConversationParticipant>().ToList();
                _expectedConversations    = fixture.CreateMany <Conversation>().ToList();

                ConversationsRepository.Setup(repository => repository.GetConversationParticipantsByUserId(It.IsAny <Guid>()))
                .ReturnsAsync(_conversationParticipants);
                ConversationsRepository.Setup(repository => repository.GetConversationsByIds(It.IsAny <IList <Guid> >()))
                .ReturnsAsync(_expectedConversations).Callback <IList <Guid> >(ids => _usedConversationIds = ids);

                _conversations = await ConversationsService.GetConversations(_userId);
            }
Ejemplo n.º 7
0
        public async Task SendMessageAsync_WithInvalidModel_ReturnsNull()
        {
            var testMessageContent = string.Empty;
            var testSentOn         = DateTime.UtcNow;

            var context = new PoolItDbContext(new DbContextOptionsBuilder <PoolItDbContext>()
                                              .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                              .Options);

            var conversation = new Conversation();

            context.Conversations.Add(conversation);

            var author = new PoolItUser
            {
                UserName = "******"
            };

            context.Users.Add(author);

            context.SaveChanges();

            var conversationsService = new ConversationsService(
                new EfRepository <Conversation>(context),
                new EfRepository <PoolItUser>(context),
                new EfRepository <Message>(context)
                );

            // Act
            var result = await conversationsService.SendMessageAsync(new MessageServiceModel
            {
                ConversationId = conversation.Id,
                Author         = new PoolItUserServiceModel
                {
                    UserName = author.UserName
                },
                SentOn  = testSentOn,
                Content = testMessageContent
            });

            // Assert
            Assert.Null(result);

            var dbCount = await context.Messages.CountAsync();

            Assert.Equal(0, dbCount);
        }
Ejemplo n.º 8
0
        public async Task SendMessageAsync_WithValidModel_WorksCorrectly()
        {
            const string expectedMessageContent = "Test Message Content";
            var          expectedSentOn         = DateTime.UtcNow;

            var context = new PoolItDbContext(new DbContextOptionsBuilder <PoolItDbContext>()
                                              .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                              .Options);

            var conversation = new Conversation();

            context.Conversations.Add(conversation);

            var author = new PoolItUser
            {
                UserName = "******"
            };

            context.Users.Add(author);

            context.SaveChanges();

            var conversationsService = new ConversationsService(
                new EfRepository <Conversation>(context),
                new EfRepository <PoolItUser>(context),
                new EfRepository <Message>(context)
                );

            // Act
            var result = await conversationsService.SendMessageAsync(new MessageServiceModel
            {
                ConversationId = conversation.Id,
                Author         = new PoolItUserServiceModel
                {
                    UserName = author.UserName
                },
                SentOn  = expectedSentOn,
                Content = expectedMessageContent
            });

            // Assert
            var dbMessage = await context.Messages.SingleAsync(m => m.Id == result.Id);

            Assert.Equal(expectedMessageContent, dbMessage.Content);
            Assert.Equal(expectedSentOn, dbMessage.SentOn);
        }
            public async Task WhenGetConversationParticipantsGetsCalled()
            {
                Setup();

                var fixture = new Fixture();

                _conversationParticipants = fixture.CreateMany <Guid>().ToList();
                _messages = fixture.CreateMany <Message>().ToList();
                _userId   = _conversationParticipants.Last();

                AuthService.Setup(service => service.GetUserIdFromToken(It.IsAny <string>())).Returns(_userId.ToString());
                ConversationsService.Setup(service => service.GetConversationParticipants(It.IsAny <Guid>()))
                .ReturnsAsync(_conversationParticipants);
                MessagesService.Setup(service => service.GetMessagesFromConversation(It.IsAny <Guid>(), It.IsAny <int>(), It.IsAny <int>()))
                .ReturnsAsync(_messages);

                _result = await MessagesController.GetMessagesFromConversation(_conversationId);
            }
Ejemplo n.º 10
0
            public async Task WhenCreateMessageGetsCalled()
            {
                Setup();

                var fixture = new Fixture();

                _conversationParticipants = fixture.CreateMany <Guid>().ToList();
                _createMessageRequest     = fixture.Build <CreateMessageRequest>()
                                            .With(request => request.SenderId, _conversationParticipants.Last())
                                            .Create();

                AuthService.Setup(service => service.GetUserIdFromToken(It.IsAny <string>())).Returns(_createMessageRequest.SenderId.ToString());
                AuthService.Setup(service => service.AuthorizeSelf(It.IsAny <string>(), It.IsAny <Guid>()))
                .Returns(true);
                ConversationsService.Setup(service => service.GetConversationParticipants(It.IsAny <Guid>()))
                .ReturnsAsync(_conversationParticipants);
                MessagesService.Setup(repository => repository.CreateMessage(It.IsAny <Message>()))
                .Callback <Message>(msg => _usedMessage = msg);

                _result = await MessagesController.CreateMessage(_createMessageRequest);
            }
Ejemplo n.º 11
0
 public void ThenConversationsServiceGetConversationParticipantsShouldHaveBeenCalled()
 => ConversationsService.Verify(service => service.GetConversationParticipants(_conversationId), Times.Once);
Ejemplo n.º 12
0
 public void ThenConversationsServiceCreateConversationWithParticipantsShouldNotHaveBeenCalled()
 => ConversationsService.Verify(service => service.CreateConversationWithParticipants(
                                    It.IsAny <Guid>(), It.IsAny <Guid>()), Times.Never);
Ejemplo n.º 13
0
 public void ThenConversationsServiceCreateConversationWithParticipantsShouldHaveBeenCalled()
 => ConversationsService.Verify(service => service.CreateConversationWithParticipants(
                                    _createConversationRequest.SenderId, _createConversationRequest.ReceiverId), Times.Once);
Ejemplo n.º 14
0
        //public List<ConversationInfo> conversations;

        public ConversationsViewModel(ConversationsService service)
        {
            Service = service;
            service.Start();
            SearchEnabled = false;
        }
Ejemplo n.º 15
0
 public void ThenConversationsServiceGetConversationsShouldHaveBeenCalled()
 => ConversationsService.Verify(service => service.GetConversations(It.IsAny <Guid>()), Times.Never);
Ejemplo n.º 16
0
 public void ThenConversationsServiceGetConversationsShouldHaveBeenCalled()
 => ConversationsService.Verify(service => service.GetConversations(_userId), Times.Once);