Exemple #1
0
 public void Delete(string id)
 {
     try
     {
         LoggerUtils.WriteLog("MachinesController : DELETE - request received");
         machineService.Delete(id);
     }
     catch (Exception ex)
     {
         LoggerUtils.WriteLog("ERROR : MachinesController : " + ex.Message + "\r" + "InnerException : " + ex.InnerException);
     }
 }
Exemple #2
0
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <IMachineRepository>();
            var model = new ApiMachineRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <string>())).Returns(Task.CompletedTask);
            var service = new MachineService(mock.LoggerMock.Object,
                                             mock.RepositoryMock.Object,
                                             mock.ModelValidatorMockFactory.MachineModelValidatorMock.Object,
                                             mock.BOLMapperMockFactory.BOLMachineMapperMock,
                                             mock.DALMapperMockFactory.DALMachineMapperMock);

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

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <string>()));
            mock.ModelValidatorMockFactory.MachineModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <string>()));
        }
        public async void Delete_NoErrorsOccurred_ShouldReturnResponse()
        {
            var mock  = new ServiceMockFacade <IMachineService, IMachineRepository>();
            var model = new ApiMachineServerRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new MachineService(mock.LoggerMock.Object,
                                             mock.MediatorMock.Object,
                                             mock.RepositoryMock.Object,
                                             mock.ModelValidatorMockFactory.MachineModelValidatorMock.Object,
                                             mock.DALMapperMockFactory.DALMachineMapperMock,
                                             mock.DALMapperMockFactory.DALLinkMapperMock);

            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.MachineModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <MachineDeletedNotification>(), It.IsAny <CancellationToken>()));
        }
        public async void Delete_ErrorsOccurred_ShouldReturnErrorResponse()
        {
            var mock          = new ServiceMockFacade <IMachineService, IMachineRepository>();
            var model         = new ApiMachineServerRequestModel();
            var validatorMock = new Mock <IApiMachineServerRequestModelValidator>();

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

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