public async void Create_ErrorsOccurred_ShouldReturnErrorResponse() { var mock = new ServiceMockFacade <ITweetService, ITweetRepository>(); var model = new ApiTweetServerRequestModel(); var validatorMock = new Mock <IApiTweetServerRequestModelValidator>(); validatorMock.Setup(x => x.ValidateCreateAsync(It.IsAny <ApiTweetServerRequestModel>())).Returns(Task.FromResult(new FluentValidation.Results.ValidationResult(new List <ValidationFailure>() { new ValidationFailure("text", "test") }))); var service = new TweetService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, validatorMock.Object, mock.DALMapperMockFactory.DALTweetMapperMock, mock.DALMapperMockFactory.DALQuoteTweetMapperMock, mock.DALMapperMockFactory.DALRetweetMapperMock); CreateResponse <ApiTweetServerResponseModel> response = await service.Create(model); response.Should().NotBeNull(); response.Success.Should().BeFalse(); validatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiTweetServerRequestModel>())); mock.MediatorMock.Verify(x => x.Publish(It.IsAny <TweetCreatedNotification>(), It.IsAny <CancellationToken>()), Times.Never()); }
public IActionResult Create(TweetViewModel tweet) { var userId = userManager.GetUserId(User); tweet.AuthorId = userId; tweetService.Create(tweet); return(RedirectToAction("Index")); }
public async void Create() { var mock = new ServiceMockFacade <ITweetRepository>(); var model = new ApiTweetRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Tweet>())).Returns(Task.FromResult(new Tweet())); var service = new TweetService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.TweetModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLTweetMapperMock, mock.DALMapperMockFactory.DALTweetMapperMock, mock.BOLMapperMockFactory.BOLQuoteTweetMapperMock, mock.DALMapperMockFactory.DALQuoteTweetMapperMock, mock.BOLMapperMockFactory.BOLRetweetMapperMock, mock.DALMapperMockFactory.DALRetweetMapperMock); CreateResponse <ApiTweetResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.TweetModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiTweetRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Tweet>())); }
public async void Create_NoErrorsOccurred_ShouldReturnResponse() { var mock = new ServiceMockFacade <ITweetService, ITweetRepository>(); var model = new ApiTweetServerRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Tweet>())).Returns(Task.FromResult(new Tweet())); var service = new TweetService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.TweetModelValidatorMock.Object, mock.DALMapperMockFactory.DALTweetMapperMock, mock.DALMapperMockFactory.DALQuoteTweetMapperMock, mock.DALMapperMockFactory.DALRetweetMapperMock); CreateResponse <ApiTweetServerResponseModel> response = await service.Create(model); response.Should().NotBeNull(); response.Success.Should().BeTrue(); mock.ModelValidatorMockFactory.TweetModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiTweetServerRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Tweet>())); mock.MediatorMock.Verify(x => x.Publish(It.IsAny <TweetCreatedNotification>(), It.IsAny <CancellationToken>())); }