public async void Update_ErrorsOccurred_ShouldReturnErrorResponse() { var mock = new ServiceMockFacade <IEventStatusService, IEventStatusRepository>(); var model = new ApiEventStatusServerRequestModel(); var validatorMock = new Mock <IApiEventStatusServerRequestModelValidator>(); validatorMock.Setup(x => x.ValidateUpdateAsync(It.IsAny <int>(), It.IsAny <ApiEventStatusServerRequestModel>())).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 EventStatus())); var service = new EventStatusService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, validatorMock.Object, mock.DALMapperMockFactory.DALEventStatusMapperMock, mock.DALMapperMockFactory.DALEventMapperMock); UpdateResponse <ApiEventStatusServerResponseModel> response = await service.Update(default(int), model); response.Should().NotBeNull(); response.Success.Should().BeFalse(); validatorMock.Verify(x => x.ValidateUpdateAsync(It.IsAny <int>(), It.IsAny <ApiEventStatusServerRequestModel>())); mock.MediatorMock.Verify(x => x.Publish(It.IsAny <EventStatusUpdatedNotification>(), It.IsAny <CancellationToken>()), Times.Never()); }
public async void Update() { var mock = new ServiceMockFacade <IEventStatusRepository>(); var model = new ApiEventStatusRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <EventStatus>())).Returns(Task.FromResult(new EventStatus())); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult(new EventStatus())); var service = new EventStatusService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.EventStatusModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLEventStatusMapperMock, mock.DALMapperMockFactory.DALEventStatusMapperMock, mock.BOLMapperMockFactory.BOLEventMapperMock, mock.DALMapperMockFactory.DALEventMapperMock); UpdateResponse <ApiEventStatusResponseModel> response = await service.Update(default(int), model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.EventStatusModelValidatorMock.Verify(x => x.ValidateUpdateAsync(It.IsAny <int>(), It.IsAny <ApiEventStatusRequestModel>())); mock.RepositoryMock.Verify(x => x.Update(It.IsAny <EventStatus>())); }