public void DeleteEmployee_EmployeeNotFound_ReturnNotFound()
        {
            unitOfWork.Setup(uow => uow.Employees.SingleOrDefault(e => e.Id == It.IsAny <string>()))
            .Returns <ApplicationUser>(null);

            var result = controller.DeleteEmployee(It.IsAny <string>());

            Assert.That(result, Is.InstanceOf(typeof(NotFoundResult)));
        }
Example #2
0
        public void Remove_NotExistingIdPassed_ReturnsNotFoundResponse()
        {
            // Arrange
            var notExistingId = 800;

            // Act
            var badResponse = _controller.DeleteEmployee(notExistingId);

            // Assert
            Assert.IsType <NotFoundResult>(badResponse);
        }
Example #3
0
        public async void Task3_Post_NewEmployee_FindName()
        {
            //Arrange
            _context    = new SDCContext(dbContextOptions);
            _controller = new EmployeesController(_context);
            var employee = new Employee()
            {
                UserName  = "******",
                FirstName = "Pascal",
                LastName  = "Siakam",
                Password  = "******",
                JobId     = 3
            };

            //Act
            var result = await _controller.PostEmployee(employee);

            //Assert
            var okResult  = result.Should().BeOfType <CreatedAtActionResult>().Subject;
            var resClient = okResult.Value.Should().BeAssignableTo <Employee>().Subject;

            resClient.FirstName.Should().Be("Pascal");

            //delete JayNew
            int newId        = _context.Employee.FirstOrDefault(p => p.FirstName == "Pascal").UserId;
            var resultDelete = await _controller.DeleteEmployee(newId);
        }
Example #4
0
        private async void Task5_Delete_Employee_OkResult()
        {
            //Arrange
            _context    = new SDCContext(dbContextOptions);
            _controller = new EmployeesController(_context);
            var employee = new Employee()
            {
                UserName  = "******",
                FirstName = "Kevin",
                LastName  = "Durant",
                Password  = "******",
                JobId     = 3
            };

            //Act
            var resultCreate = await _controller.PostEmployee(employee);

            var okResult  = resultCreate.Should().BeOfType <CreatedAtActionResult>().Subject;
            var resClient = okResult.Value.Should().BeAssignableTo <Employee>().Subject;
            int delId     = resClient.UserId;
            var result    = await _controller.DeleteEmployee(delId);

            //Assert
            Assert.IsType <OkObjectResult>(result);
        }
Example #5
0
        public void DeleteEmployee_ShouldDeleteAndReturnOk()
        {
            var passportsTestData = new List <Employee>()
            {
                new Employee {
                    Id = 1
                },
                new Employee {
                    Id = 2
                },
                new Employee {
                    Id = 3
                }
            };
            var passports = MockHelper.MockDbSet(passportsTestData);

            passports.Setup(d => d.Find(It.IsAny <object>())).Returns <object[]>((keyValues) => { return(passports.Object.SingleOrDefault(product => product.Id == (int)keyValues.Single())); });

            var dbContext = new Mock <IAppDbContext>();

            dbContext.Setup(m => m.Employees).Returns(passports.Object);
            dbContext.Setup(d => d.Set <Employee>()).Returns(passports.Object);


            var factory = new Mock <IDbContextFactory>();

            factory.Setup(m => m.CreateDbContext()).Returns(dbContext.Object);

            var controller = new EmployeesController(factory.Object);
            var result     = controller.DeleteEmployee(3) as OkNegotiatedContentResult <EmployeeEditDTO>;

            Assert.IsNotNull(result);
            Assert.AreEqual(3, result.Content.Id);
        }
        private void Button_delete_Click(object sender, EventArgs e)
        {
            controller.DeleteEmployee(Int32.Parse(comboBox.Text.Split(' ')[0]));

            MessageBox.Show("Employee " + currentEmployee.Name + " deleted.");

            EmployeeChanged(0);
        }
Example #7
0
        public async Task DeleteEmployee_ReturnBadRequest_ExistRelatedEntity()
        {
            //Arrange
            int id = 1;
            List <PurchaseOrder> list = new List <PurchaseOrder>();

            list.Add(new PurchaseOrder());
            _mockrepo.Setup(repo => repo.PurchaseOrder.PurchaseOrdersByEmployee(id)).ReturnsAsync(list);
            _mockrepo.Setup(repo => repo.Employee.DeleteEmployee((Employee)null));
            //Act
            var result = await _controller.DeleteEmployee(id);

            //Assert
            var badRequest = Assert.IsType <BadRequestObjectResult>(result);

            badRequest.Value.Should().Be(LogMessage.DeleteError(nameof(Employee), id, nameof(PurchaseOrder)));
        }
        public async void Task_DeleteEmployeeById_Return_OkResult()
        {
            //Arrange
            var dbContext  = DbContextMocker.GetMyDbContext(nameof(Task_DeleteEmployeeById_Return_OkResult));
            var controller = new EmployeesController(dbContext);
            var id         = 2;

            //Act
            var data = await controller.DeleteEmployee(id);

            //Assert
            Assert.Equal(id, data.Value.Id);
        }
Example #9
0
        public void Delete_Employee()
        {
            using (var context = GetContextWithData())
                using (var controller = new EmployeesController(context))
                {
                    Employee emp = context.Employees.First();

                    var result = controller.DeleteEmployee(emp.Ssn);

                    var del = context.Employees.FirstOrDefault(e => e.Ssn == emp.Ssn);
                    Assert.False(del != null);
                }
        }
Example #10
0
        public void DeleteEmployee_ForExistingId_RemovesEmployeeAndReturnsNoContentResult()
        {
            // Arrange
            var testDeleteEmployee = SeedTestData.GetTestEmployee();

            mockRepo.Setup(repo => repo.Employee.GetEmployee(testDeleteEmployee.Id, false))
            .Returns(testDeleteEmployee).Verifiable();

            var controller = new EmployeesController(mockRepo.Object, _mapper);

            // Act
            var result = controller.DeleteEmployee(testDeleteEmployee.Id);

            // Assert
            Assert.IsInstanceOf <NoContentResult>(result);
            mockRepo.Verify(repo => repo.Employee.GetEmployee(testDeleteEmployee.Id, false), Times.Once);
        }
Example #11
0
        public void DeleteEmployee_ForUnExistingId_ReturnsNotFoundResult()
        {
            // Arrange
            var      unExistingEmployeeId = Guid.NewGuid();
            Employee testInvalidEmployee  = null;

            mockRepo.Setup(repo => repo.Employee.GetEmployee(unExistingEmployeeId, false))
            .Returns(testInvalidEmployee).Verifiable();

            var controller = new EmployeesController(mockRepo.Object, _mapper);

            // Act
            var result = controller.DeleteEmployee(unExistingEmployeeId);

            // Assert
            Assert.IsInstanceOf <NotFoundResult>(result);
            mockRepo.Verify(repo => repo.Employee.GetEmployee(unExistingEmployeeId, false), Times.Once);
        }
Example #12
0
 private void btn_delete_Click(object sender, EventArgs e)
 {
     employeesController.DeleteEmployee(selectedEmployee.EmployeeId);
     ReloadForm();
 }
Example #13
0
        public async Task DeleteEmployee_InvalidIdPassed_ReturnNotFound()
        {
            var badResponse = await _controller.DeleteEmployee(34);

            Assert.That(badResponse, Is.TypeOf(typeof(NotFoundResult)));
        }