public async void Update() { var mock = new ServiceMockFacade<IStudioRepository>(); var model = new ApiStudioRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny<Studio>())).Returns(Task.FromResult(new Studio())); mock.RepositoryMock.Setup(x => x.Get(It.IsAny<int>())).Returns(Task.FromResult(new Studio())); var service = new StudioService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.StudioModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLStudioMapperMock, mock.DALMapperMockFactory.DALStudioMapperMock); UpdateResponse<ApiStudioResponseModel> response = await service.Update(default(int), model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.StudioModelValidatorMock.Verify(x => x.ValidateUpdateAsync(It.IsAny<int>(), It.IsAny<ApiStudioRequestModel>())); mock.RepositoryMock.Verify(x => x.Update(It.IsAny<Studio>())); }
public async void Update_NoErrorsOccurred_ShouldReturnResponse() { var mock = new ServiceMockFacade <IStudioService, IStudioRepository>(); var model = new ApiStudioServerRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Studio>())).Returns(Task.FromResult(new Studio())); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult(new Studio())); var service = new StudioService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.StudioModelValidatorMock.Object, mock.DALMapperMockFactory.DALStudioMapperMock); UpdateResponse <ApiStudioServerResponseModel> response = await service.Update(default(int), model); response.Should().NotBeNull(); response.Success.Should().BeTrue(); mock.ModelValidatorMockFactory.StudioModelValidatorMock.Verify(x => x.ValidateUpdateAsync(It.IsAny <int>(), It.IsAny <ApiStudioServerRequestModel>())); mock.RepositoryMock.Verify(x => x.Update(It.IsAny <Studio>())); mock.MediatorMock.Verify(x => x.Publish(It.IsAny <StudioUpdatedNotification>(), It.IsAny <CancellationToken>())); }
public async void Update_ErrorsOccurred_ShouldReturnErrorResponse() { var mock = new ServiceMockFacade <IStudioService, IStudioRepository>(); var model = new ApiStudioServerRequestModel(); var validatorMock = new Mock <IApiStudioServerRequestModelValidator>(); validatorMock.Setup(x => x.ValidateUpdateAsync(It.IsAny <int>(), It.IsAny <ApiStudioServerRequestModel>())).Returns(Task.FromResult(new ValidationResult(new List <ValidationFailure>() { new ValidationFailure("text", "test") }))); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult(new Studio())); var service = new StudioService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, validatorMock.Object, mock.DALMapperMockFactory.DALStudioMapperMock); UpdateResponse <ApiStudioServerResponseModel> response = await service.Update(default(int), model); response.Should().NotBeNull(); response.Success.Should().BeFalse(); validatorMock.Verify(x => x.ValidateUpdateAsync(It.IsAny <int>(), It.IsAny <ApiStudioServerRequestModel>())); mock.MediatorMock.Verify(x => x.Publish(It.IsAny <StudioUpdatedNotification>(), It.IsAny <CancellationToken>()), Times.Never()); }