Ejemplo n.º 1
0
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <IVoteTypeRepository>();
            var model = new ApiVoteTypeRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new VoteTypeService(mock.LoggerMock.Object,
                                              mock.RepositoryMock.Object,
                                              mock.ModelValidatorMockFactory.VoteTypeModelValidatorMock.Object,
                                              mock.BOLMapperMockFactory.BOLVoteTypeMapperMock,
                                              mock.DALMapperMockFactory.DALVoteTypeMapperMock);

            ActionResponse response = await service.Delete(default(int));

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>()));
            mock.ModelValidatorMockFactory.VoteTypeModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
        }
Ejemplo n.º 2
0
        public async void Delete_NoErrorsOccurred_ShouldReturnResponse()
        {
            var mock  = new ServiceMockFacade <IVoteTypeService, IVoteTypeRepository>();
            var model = new ApiVoteTypeServerRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new VoteTypeService(mock.LoggerMock.Object,
                                              mock.MediatorMock.Object,
                                              mock.RepositoryMock.Object,
                                              mock.ModelValidatorMockFactory.VoteTypeModelValidatorMock.Object,
                                              mock.DALMapperMockFactory.DALVoteTypeMapperMock,
                                              mock.DALMapperMockFactory.DALVoteMapperMock);

            ActionResponse response = await service.Delete(default(int));

            response.Should().NotBeNull();
            response.Success.Should().BeTrue();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>()));
            mock.ModelValidatorMockFactory.VoteTypeModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <VoteTypeDeletedNotification>(), It.IsAny <CancellationToken>()));
        }
Ejemplo n.º 3
0
        public async void Delete_ErrorsOccurred_ShouldReturnErrorResponse()
        {
            var mock          = new ServiceMockFacade <IVoteTypeService, IVoteTypeRepository>();
            var model         = new ApiVoteTypeServerRequestModel();
            var validatorMock = new Mock <IApiVoteTypeServerRequestModelValidator>();

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

            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 <VoteTypeDeletedNotification>(), It.IsAny <CancellationToken>()), Times.Never());
        }