public void DeleteCorrectIdTest()
        {
            var mockRepository            = new Mock <IJobService>();
            var mockIMapper               = new Mock <IMapper>();
            var categoryServiceRepository = new Mock <ICategoryService>();
            var cityServiceCategory       = new Mock <ICityService>();
            var ITypeJobService           = new Mock <ITypeJobService>();
            var IRepositoryService        = new Mock <IRepositoryImage>();
            var controller = new JobController(mockRepository.Object,
                                               categoryServiceRepository.Object, cityServiceCategory.Object,
                                               ITypeJobService.Object, mockIMapper.Object, IRepositoryService.Object);

            int id = 10000;


            Task <IActionResult> ActionResult = controller.Delete(id);

            try
            {
                NotFoundResult contentResult = (NotFoundResult)ActionResult.Result;
                mockRepository.Setup(x => x.Remove(id)).Returns(Task.CompletedTask);
                Assert.NotNull(contentResult);
                Assert.Equal(404, contentResult.StatusCode);
            }
            catch (Exception ex)
            {
                OkObjectResult contentResult = (OkObjectResult)ActionResult.Result;
                mockRepository.Setup(x => x.Remove(id)).Returns(Task.CompletedTask);
                Assert.NotNull(contentResult);
                Assert.Equal(200, contentResult.StatusCode);
            }
        }
Exemplo n.º 2
0
 private void DataGridView_ButtonClick(object sender, DataGridViewCellEventArgs e)
 {
     if (e.ColumnIndex == dataGridView1.Columns["delete_btn_column"].Index)
     {
         var           row           = dataGridView1.Rows[e.RowIndex];
         int           id            = Convert.ToInt32(row.Cells[3].Value);
         JobController jobController = new JobController();
         jobController.Delete(id);
     }
 }
Exemplo n.º 3
0
        public void Delete_Success_Test()
        {
            var jobqueServiceMock = new Mock <IJobManager>();

            jobqueServiceMock.Setup(x => x.RemoveJobFromQueue(It.IsAny <long>()));

            var mockLogger = new Mock <ILogger>();
            var controller = new JobController(jobqueServiceMock.Object, mockLogger.Object, new Mock <IDateTimeProvider>().Object, null);

            var result = controller.Delete(100);

            result.Should().BeAssignableTo <OkResult>();
            ((OkResult)result).StatusCode.Should().Be(200);
        }
        public void DeleteUncorrectIdTest()
        {
            var mockRepository            = new Mock <IJobService>();
            var mockIMapper               = new Mock <IMapper>();
            var categoryServiceRepository = new Mock <ICategoryService>();
            var cityServiceCategory       = new Mock <ICityService>();
            var ITypeJobService           = new Mock <ITypeJobService>();
            var IRepositoryService        = new Mock <IRepositoryImage>();
            var controller = new JobController(mockRepository.Object,
                                               categoryServiceRepository.Object, cityServiceCategory.Object,
                                               ITypeJobService.Object, mockIMapper.Object, IRepositoryService.Object);

            int id = -5;


            mockRepository.Setup(x => x.Remove(id));

            Task <IActionResult> ActionResult  = controller.Delete(id);
            NotFoundResult       contentResult = (NotFoundResult)ActionResult.Result;

            Assert.NotNull(contentResult);
            Assert.Equal(404, contentResult.StatusCode);
            mockRepository.Verify(x => x.Remove(id), Times.Never());
        }