Exemplo n.º 1
0
        public async void Update()
        {
            var mock  = new ServiceMockFacade <IReplyRepository>();
            var model = new ApiReplyRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Reply>())).Returns(Task.FromResult(new Reply()));
            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult(new Reply()));
            var service = new ReplyService(mock.LoggerMock.Object,
                                           mock.RepositoryMock.Object,
                                           mock.ModelValidatorMockFactory.ReplyModelValidatorMock.Object,
                                           mock.BOLMapperMockFactory.BOLReplyMapperMock,
                                           mock.DALMapperMockFactory.DALReplyMapperMock);

            UpdateResponse <ApiReplyResponseModel> response = await service.Update(default(int), model);

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.ReplyModelValidatorMock.Verify(x => x.ValidateUpdateAsync(It.IsAny <int>(), It.IsAny <ApiReplyRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Update(It.IsAny <Reply>()));
        }
Exemplo n.º 2
0
        public async Task Update_UserDoesNotOwnReply_DoesNotAttemptUpdate()
        {
            var oldReply = new Reply {
                Id = 1
            };
            var update = new UpdateReply();
            var reply  = new Reply
            {
                Id      = 1,
                Content = "hello"
            };

            A.CallTo(() => ReplyRepository.Read(1)).Returns(oldReply);
            A.CallTo(() => Mapper.Map(update, oldReply)).Returns(reply);
            A.CallTo(() => User.Is(oldReply.UserId)).Returns(false);

            await ReplyService.Update(oldReply.Id, update);

            A.CallTo(() => ReplyRepository.Update(A <Reply> .Ignored))
            .MustNotHaveHappened();
        }
Exemplo n.º 3
0
        public async void Update_NoErrorsOccurred_ShouldReturnResponse()
        {
            var mock  = new ServiceMockFacade <IReplyService, IReplyRepository>();
            var model = new ApiReplyServerRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Reply>())).Returns(Task.FromResult(new Reply()));
            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult(new Reply()));
            var service = new ReplyService(mock.LoggerMock.Object,
                                           mock.MediatorMock.Object,
                                           mock.RepositoryMock.Object,
                                           mock.ModelValidatorMockFactory.ReplyModelValidatorMock.Object,
                                           mock.DALMapperMockFactory.DALReplyMapperMock);

            UpdateResponse <ApiReplyServerResponseModel> response = await service.Update(default(int), model);

            response.Should().NotBeNull();
            response.Success.Should().BeTrue();
            mock.ModelValidatorMockFactory.ReplyModelValidatorMock.Verify(x => x.ValidateUpdateAsync(It.IsAny <int>(), It.IsAny <ApiReplyServerRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Update(It.IsAny <Reply>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <ReplyUpdatedNotification>(), It.IsAny <CancellationToken>()));
        }
Exemplo n.º 4
0
        public async Task Update_EverythingOk_UpdatesReply()
        {
            var oldReply = new Reply {
                Id = 1
            };
            var update = new UpdateReply();
            var reply  = new Reply
            {
                Id      = 1,
                Content = "hello"
            };

            A.CallTo(() => ReplyRepository.Read(1)).Returns(oldReply);
            A.CallTo(() => Mapper.Map(update, oldReply)).Returns(reply);
            A.CallTo(() => User.Is(oldReply.UserId)).Returns(true);

            await ReplyService.Update(oldReply.Id, update);

            A.CallTo(() => ReplyRepository.Update(A <Reply> .That.Matches(r =>
                                                                          r.Id == reply.Id &&
                                                                          r.Content == reply.Content
                                                                          ))).MustHaveHappenedOnceExactly();
        }