public async void Update_ErrorsOccurred_ShouldReturnErrorResponse() { var mock = new ServiceMockFacade <IVoteTypeService, IVoteTypeRepository>(); var model = new ApiVoteTypeServerRequestModel(); var validatorMock = new Mock <IApiVoteTypeServerRequestModelValidator>(); validatorMock.Setup(x => x.ValidateUpdateAsync(It.IsAny <int>(), It.IsAny <ApiVoteTypeServerRequestModel>())).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 VoteType())); var service = new VoteTypeService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, validatorMock.Object, mock.DALMapperMockFactory.DALVoteTypeMapperMock, mock.DALMapperMockFactory.DALVoteMapperMock); UpdateResponse <ApiVoteTypeServerResponseModel> response = await service.Update(default(int), model); response.Should().NotBeNull(); response.Success.Should().BeFalse(); validatorMock.Verify(x => x.ValidateUpdateAsync(It.IsAny <int>(), It.IsAny <ApiVoteTypeServerRequestModel>())); mock.MediatorMock.Verify(x => x.Publish(It.IsAny <VoteTypeUpdatedNotification>(), It.IsAny <CancellationToken>()), Times.Never()); }
public async void Update() { var mock = new ServiceMockFacade <IVoteTypeRepository>(); var model = new ApiVoteTypeRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <VoteType>())).Returns(Task.FromResult(new VoteType())); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult(new VoteType())); var service = new VoteTypeService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.VoteTypeModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLVoteTypeMapperMock, mock.DALMapperMockFactory.DALVoteTypeMapperMock); UpdateResponse <ApiVoteTypeResponseModel> response = await service.Update(default(int), model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.VoteTypeModelValidatorMock.Verify(x => x.ValidateUpdateAsync(It.IsAny <int>(), It.IsAny <ApiVoteTypeRequestModel>())); mock.RepositoryMock.Verify(x => x.Update(It.IsAny <VoteType>())); }