public async void Create() { var mock = new ServiceMockFacade <IVoteTypeRepository>(); var model = new ApiVoteTypeRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <VoteType>())).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); CreateResponse <ApiVoteTypeResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.VoteTypeModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiVoteTypeRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <VoteType>())); }
public async void Create_NoErrorsOccurred_ShouldReturnResponse() { var mock = new ServiceMockFacade <IVoteTypeService, IVoteTypeRepository>(); var model = new ApiVoteTypeServerRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <VoteType>())).Returns(Task.FromResult(new VoteType())); var service = new VoteTypeService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.VoteTypeModelValidatorMock.Object, mock.DALMapperMockFactory.DALVoteTypeMapperMock, mock.DALMapperMockFactory.DALVoteMapperMock); CreateResponse <ApiVoteTypeServerResponseModel> response = await service.Create(model); response.Should().NotBeNull(); response.Success.Should().BeTrue(); mock.ModelValidatorMockFactory.VoteTypeModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiVoteTypeServerRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <VoteType>())); mock.MediatorMock.Verify(x => x.Publish(It.IsAny <VoteTypeCreatedNotification>(), It.IsAny <CancellationToken>())); }
public async void Create_ErrorsOccurred_ShouldReturnErrorResponse() { var mock = new ServiceMockFacade <IVoteTypeService, IVoteTypeRepository>(); var model = new ApiVoteTypeServerRequestModel(); var validatorMock = new Mock <IApiVoteTypeServerRequestModelValidator>(); validatorMock.Setup(x => x.ValidateCreateAsync(It.IsAny <ApiVoteTypeServerRequestModel>())).Returns(Task.FromResult(new FluentValidation.Results.ValidationResult(new List <ValidationFailure>() { new ValidationFailure("text", "test") }))); var service = new VoteTypeService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, validatorMock.Object, mock.DALMapperMockFactory.DALVoteTypeMapperMock, mock.DALMapperMockFactory.DALVoteMapperMock); CreateResponse <ApiVoteTypeServerResponseModel> response = await service.Create(model); response.Should().NotBeNull(); response.Success.Should().BeFalse(); validatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiVoteTypeServerRequestModel>())); mock.MediatorMock.Verify(x => x.Publish(It.IsAny <VoteTypeCreatedNotification>(), It.IsAny <CancellationToken>()), Times.Never()); }