public async void Update_ErrorsOccurred_ShouldReturnErrorResponse() { var mock = new ServiceMockFacade <IFileTypeService, IFileTypeRepository>(); var model = new ApiFileTypeServerRequestModel(); var validatorMock = new Mock <IApiFileTypeServerRequestModelValidator>(); validatorMock.Setup(x => x.ValidateUpdateAsync(It.IsAny <int>(), It.IsAny <ApiFileTypeServerRequestModel>())).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 FileType())); var service = new FileTypeService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, validatorMock.Object, mock.DALMapperMockFactory.DALFileTypeMapperMock, mock.DALMapperMockFactory.DALFileMapperMock); UpdateResponse <ApiFileTypeServerResponseModel> response = await service.Update(default(int), model); response.Should().NotBeNull(); response.Success.Should().BeFalse(); validatorMock.Verify(x => x.ValidateUpdateAsync(It.IsAny <int>(), It.IsAny <ApiFileTypeServerRequestModel>())); mock.MediatorMock.Verify(x => x.Publish(It.IsAny <FileTypeUpdatedNotification>(), It.IsAny <CancellationToken>()), Times.Never()); }
public async void Update() { var mock = new ServiceMockFacade <IFileTypeRepository>(); var model = new ApiFileTypeRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <FileType>())).Returns(Task.FromResult(new FileType())); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult(new FileType())); var service = new FileTypeService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.FileTypeModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLFileTypeMapperMock, mock.DALMapperMockFactory.DALFileTypeMapperMock, mock.BOLMapperMockFactory.BOLFileMapperMock, mock.DALMapperMockFactory.DALFileMapperMock); UpdateResponse <ApiFileTypeResponseModel> response = await service.Update(default(int), model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.FileTypeModelValidatorMock.Verify(x => x.ValidateUpdateAsync(It.IsAny <int>(), It.IsAny <ApiFileTypeRequestModel>())); mock.RepositoryMock.Verify(x => x.Update(It.IsAny <FileType>())); }