public async void Create() { var mock = new ServiceMockFacade <IMessengerRepository>(); var model = new ApiMessengerRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Messenger>())).Returns(Task.FromResult(new Messenger())); var service = new MessengerService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.MessengerModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLMessengerMapperMock, mock.DALMapperMockFactory.DALMessengerMapperMock); CreateResponse <ApiMessengerResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.MessengerModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiMessengerRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Messenger>())); }
public async void Create_NoErrorsOccurred_ShouldReturnResponse() { var mock = new ServiceMockFacade <IMessengerService, IMessengerRepository>(); var model = new ApiMessengerServerRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Messenger>())).Returns(Task.FromResult(new Messenger())); var service = new MessengerService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.MessengerModelValidatorMock.Object, mock.DALMapperMockFactory.DALMessengerMapperMock); CreateResponse <ApiMessengerServerResponseModel> response = await service.Create(model); response.Should().NotBeNull(); response.Success.Should().BeTrue(); mock.ModelValidatorMockFactory.MessengerModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiMessengerServerRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Messenger>())); mock.MediatorMock.Verify(x => x.Publish(It.IsAny <MessengerCreatedNotification>(), It.IsAny <CancellationToken>())); }
public async void Create_ErrorsOccurred_ShouldReturnErrorResponse() { var mock = new ServiceMockFacade <IMessengerService, IMessengerRepository>(); var model = new ApiMessengerServerRequestModel(); var validatorMock = new Mock <IApiMessengerServerRequestModelValidator>(); validatorMock.Setup(x => x.ValidateCreateAsync(It.IsAny <ApiMessengerServerRequestModel>())).Returns(Task.FromResult(new FluentValidation.Results.ValidationResult(new List <ValidationFailure>() { new ValidationFailure("text", "test") }))); var service = new MessengerService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, validatorMock.Object, mock.DALMapperMockFactory.DALMessengerMapperMock); CreateResponse <ApiMessengerServerResponseModel> response = await service.Create(model); response.Should().NotBeNull(); response.Success.Should().BeFalse(); validatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiMessengerServerRequestModel>())); mock.MediatorMock.Verify(x => x.Publish(It.IsAny <MessengerCreatedNotification>(), It.IsAny <CancellationToken>()), Times.Never()); }