public async void Delete_ErrorsOccurred_ShouldReturnErrorResponse()
        {
            var mock          = new ServiceMockFacade <ISubscriptionService, ISubscriptionRepository>();
            var model         = new ApiSubscriptionServerRequestModel();
            var validatorMock = new Mock <IApiSubscriptionServerRequestModelValidator>();

            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 SubscriptionService(mock.LoggerMock.Object,
                                                  mock.MediatorMock.Object,
                                                  mock.RepositoryMock.Object,
                                                  validatorMock.Object,
                                                  mock.DALMapperMockFactory.DALSubscriptionMapperMock);

            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 <SubscriptionDeletedNotification>(), It.IsAny <CancellationToken>()), Times.Never());
        }
Exemple #2
0
        public async void Update_ErrorsOccurred_ShouldReturnErrorResponse()
        {
            var mock          = new ServiceMockFacade <IVideoService, IVideoRepository>();
            var model         = new ApiVideoServerRequestModel();
            var validatorMock = new Mock <IApiVideoServerRequestModelValidator>();

            validatorMock.Setup(x => x.ValidateUpdateAsync(It.IsAny <int>(), It.IsAny <ApiVideoServerRequestModel>())).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 Video()));
            var service = new VideoService(mock.LoggerMock.Object,
                                           mock.MediatorMock.Object,
                                           mock.RepositoryMock.Object,
                                           validatorMock.Object,
                                           mock.DALMapperMockFactory.DALVideoMapperMock);

            UpdateResponse <ApiVideoServerResponseModel> response = await service.Update(default(int), model);

            response.Should().NotBeNull();
            response.Success.Should().BeFalse();
            validatorMock.Verify(x => x.ValidateUpdateAsync(It.IsAny <int>(), It.IsAny <ApiVideoServerRequestModel>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <VideoUpdatedNotification>(), It.IsAny <CancellationToken>()), Times.Never());
        }