Ejemplo n.º 1
0
        public void GivenAMessageWhenEditMessageIsCalledThenTheMessageIsEdited()
        {
            // Arrange.
            var message = MessageBuilder.ABuilder().Build();
            var messageAddEditViewModel = MessageAddEditViewModelBuilder.ABuilder().Build();
            var messageViewModel        = MessageViewModelBuilder.ABuilder().Build();

            this.messageComponentTestDouble
            .Setup(component => component.GetMessage(It.IsAny <Guid>()))
            .Returns(message);
            this.mapperTestDouble
            .Setup(mapper => mapper.Map <MessageViewModel>(It.IsAny <Message>()))
            .Returns(messageViewModel);

            // Act.
            var result = this.systemUnderTest.EditMessage(message.ExternalId, messageAddEditViewModel);

            // Assert.
            result.Should().BeOfType <OkObjectResult>();
            var okObjectResult = (OkObjectResult)result;

            okObjectResult.Value.Should().BeEquivalentTo(messageViewModel);
            this.messageComponentTestDouble
            .Verify(component => component.GetMessage(message.ExternalId), Times.Once);
            this.mapperTestDouble
            .Verify(mapper => mapper.Map(messageAddEditViewModel, message), Times.Once);
            this.messageComponentTestDouble
            .Verify(component => component.EditMessage(message), Times.Once);
            this.mapperTestDouble
            .Verify(mapper => mapper.Map <MessageViewModel>(message), Times.Once);
        }
Ejemplo n.º 2
0
        public void GivenAMessageWhenGetMessagesIsCalledThenTheMessageIsReturned()
        {
            // Arrange.
            var message  = MessageBuilder.ABuilder().Build();
            var messages = new List <Message>
            {
                message,
            };
            var messageViewModel  = MessageViewModelBuilder.ABuilder().Build();
            var messageViewModels = new List <MessageViewModel>
            {
                messageViewModel,
            };

            this.messageComponentTestDouble
            .Setup(component => component.GetMessages())
            .Returns(messages);
            this.mapperTestDouble
            .Setup(mapper => mapper.Map <MessageViewModel>(It.IsAny <Message>()))
            .Returns(messageViewModel);

            // Act.
            var result = this.systemUnderTest.GetMessages();

            // Assert.
            result.Should().BeOfType <OkObjectResult>();
            var okObjectResult = (OkObjectResult)result;

            okObjectResult.Value.Should().BeEquivalentTo(messageViewModels);
            this.messageComponentTestDouble
            .Verify(component => component.GetMessages(), Times.Once);
            this.mapperTestDouble
            .Verify(mapper => mapper.Map <MessageViewModel>(message), Times.Once);
        }
Ejemplo n.º 3
0
        public void GivenAMessageWhenAddMessageIsCalledThenTheMessageIsAdded()
        {
            // Arrange.
            var message = MessageBuilder.ABuilder().Build();
            var messageAddEditViewModel = MessageAddEditViewModelBuilder.ABuilder().Build();
            var messageViewModel        = MessageViewModelBuilder.ABuilder().Build();

            this.mapperTestDouble
            .Setup(mapper => mapper.Map <Message>(It.IsAny <MessageAddEditViewModel>()))
            .Returns(message);
            this.mapperTestDouble
            .Setup(mapper => mapper.Map <MessageViewModel>(It.IsAny <Message>()))
            .Returns(messageViewModel);

            // Act.
            var result = this.systemUnderTest.AddMessage(messageAddEditViewModel);

            // Assert.
            result.Should().BeOfType <CreatedResult>();
            var createdresult = (CreatedResult)result;

            createdresult.Value.Should().BeEquivalentTo(messageViewModel);
            createdresult.Location.Should().Be($"/api/v1/Messages/{messageViewModel.Id}");
            this.mapperTestDouble
            .Verify(mapper => mapper.Map <Message>(messageAddEditViewModel), Times.Once);
            this.messageComponentTestDouble
            .Verify(component => component.AddMessage(message), Times.Once);
            this.mapperTestDouble
            .Verify(mapper => mapper.Map <MessageViewModel>(message), Times.Once);
        }
Ejemplo n.º 4
0
        public void GivenAMessageWhenMapMessageViewModelIsCalledThenTheMessageIsCorrectlyMapped()
        {
            // Arrange.
            var message          = MessageBuilder.ABuilder().Build();
            var messageViewModel = MessageViewModelBuilder
                                   .ABuilder()
                                   .WithId(message.ExternalId)
                                   .WithAddedOn(message.AddedOn)
                                   .WithEditedOn(message.EditedOn)
                                   .WithContent(message.Content)
                                   .Build();

            // Act.
            var result = this.systemUnderTest.Map <MessageViewModel>(message);

            // Assert.
            result.Should().BeEquivalentTo(messageViewModel);
        }