Ejemplo n.º 1
0
        public void TestGetDeleteReturnsView()
        {
            mockUnitOfWork.Setup(m => m.EmployeeRepository.GetByID(0)).Returns(employees[0]);
            var result = controller.Delete(0) as ViewResult;

            Assert.IsNotNull(result);
            Assert.AreEqual("Delete", result.ViewName);
        }
Ejemplo n.º 2
0
        public async Task DeleteGetActionWithId2_ReturnsModelFromService()
        {
            // Arrange

            // Act
            var result = await validController.Delete(entity.Id) as ViewResult;

            // Assert
            Assert.Equal(entity, result.Model);
        }
Ejemplo n.º 3
0
        public void DeleteEmployee_WithValidID_ReturnsCreateRequest()
        {
            mock.Setup(p => p.Delete(It.IsAny <int>())).Returns(true);
            var actionResult  = employees.Delete(It.IsAny <int>());
            var contentResult = actionResult as CreatedResult;

            Assert.IsNotNull(actionResult);
            Assert.IsNotNull(contentResult);
            Assert.AreEqual(contentResult.StatusCode, Convert.ToInt32(HttpStatusCode.Created));
            Assert.IsInstanceOfType(contentResult, typeof(CreatedResult));
        }
Ejemplo n.º 4
0
        public async Task DeleteWhenEmailNull()
        {
            // ARRANGE
            string email = null;

            // ACT
            var result = await _controller.Delete(email) as HttpStatusCodeResult;

            // ASSERT
            Assert.AreEqual((int)HttpStatusCode.BadRequest, result.StatusCode);

            // verify that the method was not called
            _userManager.Verify(x => x.FindByEmailAsync(It.IsAny <string>()), Times.Never);
        }
Ejemplo n.º 5
0
        public void Employee_Controller_Delete_ShouldBeOk()
        {
            // Arrange
            var isUpdated = true;

            _mockEmployeeService.Setup(c => c.Remove(_employeeRemove.Object)).Returns(isUpdated);
            _employeeRemove.Setup(c => c.Validate()).Returns(new FluentValidation.Results.ValidationResult());

            // Action
            IHttpActionResult callback = _employeesController.Delete(_employeeRemove.Object);
            // Assert
            var httpResponse = callback.Should().BeOfType <OkNegotiatedContentResult <bool> >().Subject;

            _mockEmployeeService.Verify(s => s.Remove(_employeeRemove.Object), Times.Once);
            httpResponse.Content.Should().BeTrue();
        }
        public void RemoveEmployee_ForPackagesInDelivery_ShouldSetPackagesStatusBackToNew()
        {
            var package = new Package
            {
                Id     = 1,
                Status = PackageStatus.InDelivery
            };
            var employee = new Employee {
                Id = 1, FirstName = "Ted", LastName = "Mosby"
            };

            employee.Packages.Add(package);

            var mockContext = new Mock <InstantDeliveryContext>();

            mockContext.Setup(c => c.Packages).ReturnsDbSet(package);
            mockContext.Setup(c => c.Employees).ReturnsDbSet(employee);

            var userStore   = new Mock <UserStore <User> >(mockContext.Object);
            var userManager = new Mock <UserManager <User> >(userStore.Object);
            var controller  = new EmployeesController(mockContext.Object, userManager.Object);

            controller.Delete(employee.Id);

            Assert.Equal(PackageStatus.InWarehouse, package.Status);
        }
Ejemplo n.º 7
0
        public void DeleteEmployeeByWrongId(int id)
        {
            var controller = new EmployeesController(context);
            var response   = controller.Delete(id) as StatusCodeResult;

            Assert.AreEqual(404, response.StatusCode);
        }
        public void EmployeeDeleteTest()
        {
            EmployeesController controller    = new EmployeesController(EmployeeInfo);
            HttpConfiguration   configuration = new HttpConfiguration();

            int employeeIdToBeDeleted = 10;

            // Prepare request.
            HttpRequestMessage req = new HttpRequestMessage(HttpMethod.Delete,
                                                            $"http://fakehost/api/Employees/{employeeIdToBeDeleted}");

            req.Properties[HttpPropertyKeys.HttpConfigurationKey] = configuration;
            req.Headers.Add("Accept", "application/json");
            controller.Request = req;

            // Invoke the URI.
            HttpResponseMessage response = controller.Delete(employeeIdToBeDeleted);

            string responseMessage = response.Content.ReadAsStringAsync().Result;

            // Assert.
            Assert.AreEqual(responseMessage,
                            $"\"The user with user id {employeeIdToBeDeleted} has been deleted successfully\"");
            Assert.IsNotNull(response);
            Assert.IsTrue(response.StatusCode == System.Net.HttpStatusCode.NoContent);
            Assert.IsNotNull(response.Content);
            Assert.IsTrue(response.IsSuccessStatusCode);
        }
        public void ReturnExceptionDeleteTest()
        {
            // Arrange.
            int employeeId = 10;
            var empInfo    = new Mock <IEmployeeInfoReceiver>();

            empInfo.Setup(task => task.GetEmployeeDetails(employeeId)).Throws(new Exception("An error occurred"));

            EmployeesController controller    = new EmployeesController(empInfo.Object);
            HttpConfiguration   configuration = new HttpConfiguration();

            // Prepare request.
            HttpRequestMessage req = new HttpRequestMessage(HttpMethod.Delete,
                                                            "http://fakehost/api/Employees");

            req.Properties[HttpPropertyKeys.HttpConfigurationKey] = configuration;
            req.Headers.Add("Accept", "application/json");
            controller.Request = req;

            // Invoke the URI.
            HttpResponseMessage response = controller.Delete(employeeId);

            // Assert.
            Assert.IsNotNull(response);
            Assert.IsTrue(response.StatusCode == System.Net.HttpStatusCode.InternalServerError);
            Assert.IsNotNull(response.Content);
            Assert.IsFalse(response.IsSuccessStatusCode);
        }
        public void TestDeleteView()
        {
            var employeesCorntorller = new EmployeesController();
            var result = employeesCorntorller.Delete(1) as ViewResult;

            Assert.AreEqual("Delete", result.ViewName);
        }
Ejemplo n.º 11
0
        public void ReturnHttpNotFoundResult_WhenEmployeeIsNull()
        {
            // Arrange
            var mockedMappService = new Mock <IMapService>();
            var employeeService   = new Mock <IEmployeeService>();
            EmployeesController emplController = new EmployeesController(mockedMappService.Object, employeeService.Object);
            var      employeeId = 5;
            Employee employee   = null;

            employeeService.Setup(x => x.GetById(employeeId)).Returns(employee);

            // Act
            emplController.Delete(employeeId);

            // Assert
            Assert.IsInstanceOf <HttpNotFoundResult>(emplController.Delete(employeeId));
        }
Ejemplo n.º 12
0
        public void ControllerDeleteEmployeeWithValidId()
        {
            var controller = new EmployeesController();
            var response   = controller.Delete(2);
            var result     = (OkResult)response;

            Assert.IsNotNull(result);
        }
Ejemplo n.º 13
0
        public async void DeleteNonExisting()
        {
            var response = await _controller.Delete(99);

            var responseResult = Assert.IsAssignableFrom <StatusCodeResult>(response.Result);

            Assert.Equal(responseResult.StatusCode, (int)HttpStatusCode.NotFound);
        }
Ejemplo n.º 14
0
        public void TestDeleteFound()
        {
            _repository.Setup(repo => repo.DeleteEmployee(It.IsAny <int>())).Returns(true);
            var employeeController = new EmployeesController(_repository.Object, _mapper);

            var result = employeeController.Delete(3);

            Assert.IsInstanceOfType(result, typeof(OkResult));
        }
Ejemplo n.º 15
0
        public void ReturnViewResult_WhenIdIsCorrect()
        {
            // Arrange
            var mockedMappService = new Mock <IMapService>();
            var employeeService   = new Mock <IEmployeeService>();
            EmployeesController emplController = new EmployeesController(mockedMappService.Object, employeeService.Object);
            var employeeId = 5;

            employeeService.Setup(x => x.GetById(employeeId)).Returns(new Employee()
            {
                Id = employeeId
            });
            // Act
            emplController.Delete(employeeId);

            // Assert
            Assert.IsInstanceOf <ViewResult>(emplController.Delete(employeeId));
        }
        public async Task Delete_Employee()
        {
            var mockRepository = new Mock <IEmployeeRepository>();
            var controller     = new EmployeesController(mockRepository.Object);
            int id             = 99;
            await controller.Delete(id);

            mockRepository.Verify(repo => repo.DeleteAsync(id), Times.Once);
        }
        public async Task DeleteEmployeeWithWrongId()
        {
            var controller = new EmployeesController(unit.Context);
            int id         = 40;//Try to delete the employee with id (doesn't exist)

            var response = await controller.Delete(id) as ObjectResult;

            Assert.AreEqual(404, response.StatusCode);
        }
Ejemplo n.º 18
0
        public void EmployeeControllerDelete()
        {
            var controller = new EmployeesController();

            var response = controller.Delete(1);
            var result   = (OkResult)response;

            Assert.IsNotNull(result);
        }
Ejemplo n.º 19
0
        public void ControllerDeleteEmployeeWithInvalidID()
        {
            var controller = new EmployeesController();

            var response = controller.Delete(1337);
            var result   = (NotFoundResult)response;

            Assert.IsNotNull(result);
        }
        public async Task DeleteEmployee()
        {
            var controller = new EmployeesController(unit.Context);
            int id         = 3;//Try to delete the employee with id 3

            var response = await controller.Delete(id) as StatusCodeResult;

            Assert.AreEqual(204, response.StatusCode);
        }
        public async void Delete_IdIsNull_ReturnsNotFound()
        {
            var employeeRepositroy = new Mock <IEmpoyeeRepository>();
            var employeeController = new EmployeesController(employeeRepositroy.Object);

            var result = await employeeController.Delete(null) as NotFoundResult;

            Assert.NotNull(result);

            employeeController.Dispose();
        }
Ejemplo n.º 22
0
        public void DeleteView()
        {
            // Arrange
            EmployeesController controller = new EmployeesController();

            // Act
            ViewResult result = controller.Delete(1) as ViewResult;

            // Assert
            Assert.IsNotNull(result);
        }
Ejemplo n.º 23
0
        public void CanDeleteValidEmployee()
        {
            var employee = new Employee {
                EmployeeId = 1, Name = "Test"
            };

            _mock.Setup(e => e.DeleteEmployee(employee));
            var employeesController = new EmployeesController(_mock.Object);
            var viewResult          = employeesController.Delete(employee.EmployeeId) as RedirectToRouteResult;

            Assert.AreEqual("Index", viewResult.RouteValues["action"]);
        }
        public void Task_Delete_Return_OkResult()
        {
            //Arrange
            var controller = new EmployeesController(repo);
            int employeeId = 2;

            //Act
            IActionResult actionResult = controller.Delete(employeeId);
            OkResult      okResult     = Assert.IsType <OkResult>(actionResult);

            Assert.IsType <OkResult>(okResult);
        }
        public void Task_Delete_Return_NotFoundResult()
        {
            //Arrange
            var controller = new EmployeesController(repo);
            int employeeId = 100;

            //Act
            IActionResult  actionResult         = controller.Delete(employeeId);
            NotFoundResult notFoundObjectResult = Assert.IsType <NotFoundResult>(actionResult);

            Assert.IsType <NotFoundResult>(notFoundObjectResult);
        }
Ejemplo n.º 26
0
        public void CannotDeleteNonExistingEmployee()
        {
            var employee = new Employee {
                EmployeeId = 100, Name = "Test"
            };

            _mock.Setup(e => e.DeleteEmployee(employee));
            var employeesController = new EmployeesController(_mock.Object);
            var viewResult          = employeesController.Delete(employee.EmployeeId) as HttpNotFoundResult;

            Assert.IsInstanceOf(typeof(HttpNotFoundResult), viewResult);
        }
Ejemplo n.º 27
0
        public void Delete_Ok()
        {
            //Arrange
            var employee   = _dataAccess.GetByLastId();
            var controller = new EmployeesController(_dataAccess);
            //Act
            var result     = controller.Delete(employee.EmpId);
            var goofResult = result as OkNegotiatedContentResult <string>;

            //Assert
            Assert.IsNotNull(goofResult.Content);
            Assert.AreEqual(goofResult.Content, "Your Data is Delted");
        }
        public async Task ShouldDeleteEmployee()
        {
            var employeeId = Guid.NewGuid();
            var request    = new EmployeeDeleteRequest()
            {
                EmployeeId = employeeId,
            };

            await _controller.Delete(request);

            _mock.Mock <IEmployeesService>()
            .Verify(service => service.DeleteAsync(employeeId));
        }
Ejemplo n.º 29
0
        public async Task Delete_Employee_Return_NoContent_Test()
        {
            EmployeesController target = new EmployeesController(this.employeesRepository.Object, this.mapper.Object);

            IActionResult result = await target.Delete(1);

            var noContentResult = result as NoContentResult;

            Assert.IsNotNull(noContentResult);

            this.employeesRepository.Verify(m => m.Delete(It.IsAny <EmployeeModel>()), Times.Once);
            this.employeesRepository.Verify(m => m.Save(), Times.Once);
        }
Ejemplo n.º 30
0
        public void testEmployeesControllerDelete()
        {
            //Arrange
            DbContextOptions <ProjectContext> context = new DbContextOptions <ProjectContext>();
            ProjectContext      projectContext        = new ProjectContext(context);
            EmployeesController controller            = new EmployeesController(projectContext);

            //Act
            var result = controller.Delete(1);

            //Assert
            Assert.NotNull(result);
        }