public async void Update() { var mock = new ServiceMockFacade <IClaspRepository>(); var model = new ApiClaspRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Clasp>())).Returns(Task.FromResult(new Clasp())); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult(new Clasp())); var service = new ClaspService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.ClaspModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLClaspMapperMock, mock.DALMapperMockFactory.DALClaspMapperMock); UpdateResponse <ApiClaspResponseModel> response = await service.Update(default(int), model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.ClaspModelValidatorMock.Verify(x => x.ValidateUpdateAsync(It.IsAny <int>(), It.IsAny <ApiClaspRequestModel>())); mock.RepositoryMock.Verify(x => x.Update(It.IsAny <Clasp>())); }
public async void Update_NoErrorsOccurred_ShouldReturnResponse() { var mock = new ServiceMockFacade <IClaspService, IClaspRepository>(); var model = new ApiClaspServerRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Clasp>())).Returns(Task.FromResult(new Clasp())); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult(new Clasp())); var service = new ClaspService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.ClaspModelValidatorMock.Object, mock.DALMapperMockFactory.DALClaspMapperMock); UpdateResponse <ApiClaspServerResponseModel> response = await service.Update(default(int), model); response.Should().NotBeNull(); response.Success.Should().BeTrue(); mock.ModelValidatorMockFactory.ClaspModelValidatorMock.Verify(x => x.ValidateUpdateAsync(It.IsAny <int>(), It.IsAny <ApiClaspServerRequestModel>())); mock.RepositoryMock.Verify(x => x.Update(It.IsAny <Clasp>())); mock.MediatorMock.Verify(x => x.Publish(It.IsAny <ClaspUpdatedNotification>(), It.IsAny <CancellationToken>())); }
public async void Update_ErrorsOccurred_ShouldReturnErrorResponse() { var mock = new ServiceMockFacade <IClaspService, IClaspRepository>(); var model = new ApiClaspServerRequestModel(); var validatorMock = new Mock <IApiClaspServerRequestModelValidator>(); validatorMock.Setup(x => x.ValidateUpdateAsync(It.IsAny <int>(), It.IsAny <ApiClaspServerRequestModel>())).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 Clasp())); var service = new ClaspService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, validatorMock.Object, mock.DALMapperMockFactory.DALClaspMapperMock); UpdateResponse <ApiClaspServerResponseModel> response = await service.Update(default(int), model); response.Should().NotBeNull(); response.Success.Should().BeFalse(); validatorMock.Verify(x => x.ValidateUpdateAsync(It.IsAny <int>(), It.IsAny <ApiClaspServerRequestModel>())); mock.MediatorMock.Verify(x => x.Publish(It.IsAny <ClaspUpdatedNotification>(), It.IsAny <CancellationToken>()), Times.Never()); }