public async Task ShouldAddAndReturnMessage()
        {
            // Arrange
            Mock <IDateTime> dateTimeMock = new Mock <IDateTime>();

            var handler = new AddMessageCommandHandler(_context, dateTimeMock.Object);

            // Act
            Message message = await handler.Handle(new AddMessageCommand(), CancellationToken.None);

            // Assert
            message.Should().NotBeNull();

            IQueryable <Message> messages = _context.Messages;

            messages.Should().NotBeNull();
            messages.Should().HaveCount(1);
        }
예제 #2
0
        public async Task When_AddMessageCommandHandler_Should_ReturnNewCreatedId()
        {
            // arrange
            var guid = Guid.NewGuid();

            _messageRepositoryMock
            .Setup(x => x.CreateAsync(It.IsAny <Message>()))
            .ReturnsAsync(new Message {
                Id = guid
            });

            var handler = new AddMessageCommandHandler(_messageRepositoryMock.Object, _mapMock.Object);

            // act
            var result = await handler.Handle(new AddMessageCommand(), CancellationToken.None);

            // assert
            result.ShouldBe(guid.ToString());
            result.ShouldBeOfType(typeof(string));
        }