public async void Create() { var mock = new ServiceMockFacade <IDirectTweetRepository>(); var model = new ApiDirectTweetRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <DirectTweet>())).Returns(Task.FromResult(new DirectTweet())); var service = new DirectTweetService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.DirectTweetModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLDirectTweetMapperMock, mock.DALMapperMockFactory.DALDirectTweetMapperMock); CreateResponse <ApiDirectTweetResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.DirectTweetModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiDirectTweetRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <DirectTweet>())); }
public async void Create_NoErrorsOccurred_ShouldReturnResponse() { var mock = new ServiceMockFacade <IDirectTweetService, IDirectTweetRepository>(); var model = new ApiDirectTweetServerRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <DirectTweet>())).Returns(Task.FromResult(new DirectTweet())); var service = new DirectTweetService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.DirectTweetModelValidatorMock.Object, mock.DALMapperMockFactory.DALDirectTweetMapperMock); CreateResponse <ApiDirectTweetServerResponseModel> response = await service.Create(model); response.Should().NotBeNull(); response.Success.Should().BeTrue(); mock.ModelValidatorMockFactory.DirectTweetModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiDirectTweetServerRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <DirectTweet>())); mock.MediatorMock.Verify(x => x.Publish(It.IsAny <DirectTweetCreatedNotification>(), It.IsAny <CancellationToken>())); }
public async void Create_ErrorsOccurred_ShouldReturnErrorResponse() { var mock = new ServiceMockFacade <IDirectTweetService, IDirectTweetRepository>(); var model = new ApiDirectTweetServerRequestModel(); var validatorMock = new Mock <IApiDirectTweetServerRequestModelValidator>(); validatorMock.Setup(x => x.ValidateCreateAsync(It.IsAny <ApiDirectTweetServerRequestModel>())).Returns(Task.FromResult(new FluentValidation.Results.ValidationResult(new List <ValidationFailure>() { new ValidationFailure("text", "test") }))); var service = new DirectTweetService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, validatorMock.Object, mock.DALMapperMockFactory.DALDirectTweetMapperMock); CreateResponse <ApiDirectTweetServerResponseModel> response = await service.Create(model); response.Should().NotBeNull(); response.Success.Should().BeFalse(); validatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiDirectTweetServerRequestModel>())); mock.MediatorMock.Verify(x => x.Publish(It.IsAny <DirectTweetCreatedNotification>(), It.IsAny <CancellationToken>()), Times.Never()); }