public async void BySourceTweetId_Not_Exists() { var mock = new ServiceMockFacade <IQuoteTweetService, IQuoteTweetRepository>(); mock.RepositoryMock.Setup(x => x.BySourceTweetId(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult <List <QuoteTweet> >(new List <QuoteTweet>())); var service = new QuoteTweetService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.QuoteTweetModelValidatorMock.Object, mock.DALMapperMockFactory.DALQuoteTweetMapperMock); List <ApiQuoteTweetServerResponseModel> response = await service.BySourceTweetId(default(int)); response.Should().BeEmpty(); mock.RepositoryMock.Verify(x => x.BySourceTweetId(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>())); }
public async void Get_ShouldReturnNullBecauseRecordNotFound() { var mock = new ServiceMockFacade <IQuoteTweetService, IQuoteTweetRepository>(); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <QuoteTweet>(null)); var service = new QuoteTweetService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.QuoteTweetModelValidatorMock.Object, mock.DALMapperMockFactory.DALQuoteTweetMapperMock); ApiQuoteTweetServerResponseModel response = await service.Get(default(int)); response.Should().BeNull(); mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>())); }
public async void Get() { var mock = new ServiceMockFacade <IQuoteTweetRepository>(); var record = new QuoteTweet(); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult(record)); var service = new QuoteTweetService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.QuoteTweetModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLQuoteTweetMapperMock, mock.DALMapperMockFactory.DALQuoteTweetMapperMock); ApiQuoteTweetResponseModel response = await service.Get(default(int)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>())); }
public async void All_ShouldReturnRecords() { var mock = new ServiceMockFacade <IQuoteTweetService, IQuoteTweetRepository>(); var records = new List <QuoteTweet>(); records.Add(new QuoteTweet()); mock.RepositoryMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>())).Returns(Task.FromResult(records)); var service = new QuoteTweetService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.QuoteTweetModelValidatorMock.Object, mock.DALMapperMockFactory.DALQuoteTweetMapperMock); List <ApiQuoteTweetServerResponseModel> response = await service.All(); response.Should().HaveCount(1); mock.RepositoryMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>())); }
public async void Create() { var mock = new ServiceMockFacade <IQuoteTweetRepository>(); var model = new ApiQuoteTweetRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <QuoteTweet>())).Returns(Task.FromResult(new QuoteTweet())); var service = new QuoteTweetService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.QuoteTweetModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLQuoteTweetMapperMock, mock.DALMapperMockFactory.DALQuoteTweetMapperMock); CreateResponse <ApiQuoteTweetResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.QuoteTweetModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiQuoteTweetRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <QuoteTweet>())); }
public async void ByRetweeterUserId_Exists() { var mock = new ServiceMockFacade <IQuoteTweetRepository>(); var records = new List <QuoteTweet>(); records.Add(new QuoteTweet()); mock.RepositoryMock.Setup(x => x.ByRetweeterUserId(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult(records)); var service = new QuoteTweetService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.QuoteTweetModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLQuoteTweetMapperMock, mock.DALMapperMockFactory.DALQuoteTweetMapperMock); List <ApiQuoteTweetResponseModel> response = await service.ByRetweeterUserId(default(int)); response.Should().NotBeEmpty(); mock.RepositoryMock.Verify(x => x.ByRetweeterUserId(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>())); }
public async void Delete() { var mock = new ServiceMockFacade <IQuoteTweetRepository>(); var model = new ApiQuoteTweetRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); var service = new QuoteTweetService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.QuoteTweetModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLQuoteTweetMapperMock, mock.DALMapperMockFactory.DALQuoteTweetMapperMock); ActionResponse response = await service.Delete(default(int)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>())); mock.ModelValidatorMockFactory.QuoteTweetModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); }
public async void Delete_NoErrorsOccurred_ShouldReturnResponse() { var mock = new ServiceMockFacade <IQuoteTweetService, IQuoteTweetRepository>(); var model = new ApiQuoteTweetServerRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); var service = new QuoteTweetService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.QuoteTweetModelValidatorMock.Object, mock.DALMapperMockFactory.DALQuoteTweetMapperMock); ActionResponse response = await service.Delete(default(int)); response.Should().NotBeNull(); response.Success.Should().BeTrue(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>())); mock.ModelValidatorMockFactory.QuoteTweetModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); mock.MediatorMock.Verify(x => x.Publish(It.IsAny <QuoteTweetDeletedNotification>(), It.IsAny <CancellationToken>())); }
public async void Delete_ErrorsOccurred_ShouldReturnErrorResponse() { var mock = new ServiceMockFacade <IQuoteTweetService, IQuoteTweetRepository>(); var model = new ApiQuoteTweetServerRequestModel(); var validatorMock = new Mock <IApiQuoteTweetServerRequestModelValidator>(); validatorMock.Setup(x => x.ValidateDeleteAsync(It.IsAny <int>())).Returns(Task.FromResult(new FluentValidation.Results.ValidationResult(new List <ValidationFailure>() { new ValidationFailure("text", "test") }))); var service = new QuoteTweetService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, validatorMock.Object, mock.DALMapperMockFactory.DALQuoteTweetMapperMock); ActionResponse response = await service.Delete(default(int)); response.Should().NotBeNull(); response.Success.Should().BeFalse(); validatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); mock.MediatorMock.Verify(x => x.Publish(It.IsAny <QuoteTweetDeletedNotification>(), It.IsAny <CancellationToken>()), Times.Never()); }