public async void Update_ErrorsOccurred_ShouldReturnErrorResponse()
        {
            var mock          = new ServiceMockFacade <IPostHistoryTypeService, IPostHistoryTypeRepository>();
            var model         = new ApiPostHistoryTypeServerRequestModel();
            var validatorMock = new Mock <IApiPostHistoryTypeServerRequestModelValidator>();

            validatorMock.Setup(x => x.ValidateUpdateAsync(It.IsAny <int>(), It.IsAny <ApiPostHistoryTypeServerRequestModel>())).Returns(Task.FromResult(new ValidationResult(new List <ValidationFailure>()
            {
                new ValidationFailure("text", "test")
            })));
            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult(new PostHistoryType()));
            var service = new PostHistoryTypeService(mock.LoggerMock.Object,
                                                     mock.MediatorMock.Object,
                                                     mock.RepositoryMock.Object,
                                                     validatorMock.Object,
                                                     mock.DALMapperMockFactory.DALPostHistoryTypeMapperMock,
                                                     mock.DALMapperMockFactory.DALPostHistoryMapperMock);

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

            response.Should().NotBeNull();
            response.Success.Should().BeFalse();
            validatorMock.Verify(x => x.ValidateUpdateAsync(It.IsAny <int>(), It.IsAny <ApiPostHistoryTypeServerRequestModel>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <PostHistoryTypeUpdatedNotification>(), It.IsAny <CancellationToken>()), Times.Never());
        }
Пример #2
0
        public async void Update()
        {
            var mock  = new ServiceMockFacade <IPostHistoryTypeRepository>();
            var model = new ApiPostHistoryTypeRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <PostHistoryType>())).Returns(Task.FromResult(new PostHistoryType()));
            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult(new PostHistoryType()));
            var service = new PostHistoryTypeService(mock.LoggerMock.Object,
                                                     mock.RepositoryMock.Object,
                                                     mock.ModelValidatorMockFactory.PostHistoryTypeModelValidatorMock.Object,
                                                     mock.BOLMapperMockFactory.BOLPostHistoryTypeMapperMock,
                                                     mock.DALMapperMockFactory.DALPostHistoryTypeMapperMock);

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

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.PostHistoryTypeModelValidatorMock.Verify(x => x.ValidateUpdateAsync(It.IsAny <int>(), It.IsAny <ApiPostHistoryTypeRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Update(It.IsAny <PostHistoryType>()));
        }