Ejemplo n.º 1
0
        public void AddOk()
        {
            // Act
            EmployeeRequest employee = new EmployeeRequest {
                Name = "Тест Тестович Тестовый", Position = "Специалист по тестам", Department = "Отдел тестирования", StartDate = DateTime.Now
            };
            var actionResult = _controller.Add(employee);

            // Assert
            Assert.IsType <OkResult>(actionResult);
        }
        public void EmployeeAddTEst()
        {
            EmployeeController employeecontroller = new EmployeeController();
            ActionResult       result             = employeecontroller.Add(Guid.Parse("C44830E1-92DB-41E1-ACA8-2192D4A6FC8A"));

            Assert.IsNotNull(result);
        }
        public void Test_AddNewEmployee()
        {
            EmployeeViewModel emp = new EmployeeViewModel
            {
                ID         = 8,
                First_Name = "Ankit",
                Last_Name  = "Pratap",
                Age        = 45,
                Department = "Ministry of IT",
            };

            // Arrange
            var mockRepository = new Mock <IEmployeeService>();

            mockRepository.Setup(x => x.AddEmployee(emp)).Returns(8);

            EmployeeController controller = new EmployeeController(mockRepository.Object);

            // Act
            IHttpActionResult actionResult = controller.Add(emp);
            var contentResult = actionResult as NegotiatedContentResult <string>;

            // Assert
            Assert.IsNotNull(contentResult);
            Assert.IsNotNull(contentResult.Content);
            Assert.AreEqual("New employee added successfully.", contentResult.Content);
        }
Ejemplo n.º 4
0
        public async Task SqlConnectionTest()
        {
            // Create DB Context
            var configuration = new ConfigurationBuilder()
                                .AddJsonFile("appsettings.json")
                                .AddEnvironmentVariables()
                                .Build();

            var optionsBuilder = new DbContextOptionsBuilder <DemoDbContext>();

            optionsBuilder.UseSqlServer(configuration["ConnectionStrings:DemoDbConnection"]);

            var context = new DemoDbContext(optionsBuilder.Options);

            // Just to make sure: Delete all existing data in the database
            await context.Database.EnsureDeletedAsync();

            await context.Database.EnsureCreatedAsync();

            // Create Controller
            var empController = new EmployeeController(context);

            // Add Employee
            await empController.Add(new Employee { Name = "Menaka" });

            // Check: Does GetAll returns the added Employee
            var result = (await empController.GetAll()).ToArray();

            Assert.Single(result);
            Assert.Equal("Menaka", result[0].Name);
        }
        public void TestGetAdd_InputDataSet_OkResultWithEmployeeModel()
        {
            var helperMock = new Mock <EmployeeControllerHelper>();

            helperMock.Setup(x => x.FindEmployees(It.IsAny <EmployeeModel>())).
            Returns(() => null);
            var mock = new Mock <IEmployeeDbContext>();

            mock.SetupProperty(x => x.Employees, _testEmployeeDbSet);

            var controller = new EmployeeController(mock.Object, helperMock.Object);
            var expected   = new OkNegotiatedContentResult <EmployeeModel>(_testEmployeeModel, controller);

            var actionResult = controller.Add(_testEmployeeModel.FirstName, _testEmployeeModel.LastName,
                                              _testEmployeeModel.Age.ToString(), _testEmployeeModel.Gender);
            var actual = actionResult as OkNegotiatedContentResult <EmployeeModel>;

            Assert.IsNotNull(actual);
            Assert.IsNotNull(actual.Content);

            var compareLogic      = new CompareLogic(_config);
            var comparationResult = compareLogic.Compare(expected.Content, actual.Content);

            Assert.IsTrue(comparationResult.AreEqual, comparationResult.DifferencesString);
        }
Ejemplo n.º 6
0
        public async Task Add_Employee_Collection_Should_Call_Service()
        {
            var employees = new EmployeeDTO[2];

            IActionResult response = await employeeController.Add(employees);

            response.Should().BeOfType <AcceptedResult>();
            employeeServiceMock.Verify(e => e.Add(employees), Times.Once);
            employeeServiceMock.VerifyNoOtherCalls();
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Adds the employees details and returns a string with the result
        /// </summary>
        /// <param name="emp"></param>
        /// <returns></returns>
        private string AddEmployeeResult(Employee emp)
        {
            ResultsEnum result = _empController.Add(emp);

            if (result == ResultsEnum.Success)
            {
                LoadEmployeeData(); // update the home page with the new data
                return(@"Employee details added");
            }
            return(@"Employee was not added, check the fields and try again");
        }
Ejemplo n.º 8
0
        public void GivenAEmployeeController_PerformCurdOperations_AllOperationsShouldBeSuccessful()
        {
            var controller = new EmployeeController(_employeeDataContext);

            var employee = new Employee
            {
                Name = "Dileep Bhat",

                Address = new Address
                {
                    Country = "India",
                    State   = "Karnataka",
                    City    = "Udupi"
                }
            };

            var employeeId = controller.Add(employee);

            Assert.That(employeeId > 0, "Employeed id is not valid");

            var employeeLoaded = controller.GetEmployee(employeeId);

            Assert.That(employeeLoaded.Name == employee.Name, "Name parameter does not match");

            var address       = employee.Address;
            var addressLoaded = employeeLoaded.Address;

            Assert.That(addressLoaded.Country == address.Country, "Country parameter does not match");
            Assert.That(addressLoaded.State == address.State, "State parameter does not match");
            Assert.That(addressLoaded.City == address.City, "City parameter does not match");

            employee.Name         = "Dileep";
            employee.Address.City = "Bangalore";

            controller.UpdateEmployee(employee);
            employeeLoaded = controller.GetEmployee(employeeId);
            Assert.That(employeeLoaded.Name == "Dileep", "Name parameter does not match");

            addressLoaded = employeeLoaded.Address;

            Assert.That(addressLoaded.Country == "India", "Country parameter does not match");
            Assert.That(addressLoaded.State == "Karnataka", "State parameter does not match");
            Assert.That(addressLoaded.City == "Bangalore", "City parameter does not match");

            controller.DeleteEmployee(employee.EmployeeId);

            employeeLoaded = controller.GetEmployee(employeeId);
            Assert.That(employeeLoaded == null, "Employee should be deleted");
        }
        public void Add_ReturnsBadRequestResult_WhenModelStateIsInvalid()
        {
            // Arrange
            var mockRepo   = new Mock <IDataRepository <Employee> >();
            var controller = new EmployeeController(mockRepo.Object);

            controller.ModelState.AddModelError("Name", "Required");
            var newEmployee = GetTestEmployee();
            // Act
            var result = controller.Add(newEmployee);
            // Assert
            var badRequestResult = Assert.IsType <BadRequestObjectResult>(result);

            Assert.IsType <SerializableError>(badRequestResult.Value);
        }
        public async Task EmployeeController_Add()
        {
            var result   = new Result(1);
            var employee = new Employee {
                Name = "Abc", BirthDate = DateTime.Now, MonthlySalary = 5000M
            };

            _employeeAppService.Setup(e => e.Add(employee)).Returns(result);
            _employeeController = new EmployeeController(_employeeAppService.Object);

            var objectResult = await _employeeController.Add(employee);

            Assert.NotNull(objectResult);
            Assert.Equal((int)HttpStatusCode.OK, objectResult.StatusCode);
            Assert.Equal(result.Return, ((Result)objectResult.Value).Return);
        }
        public void Add_AddsEmployeeAndReturnsARedirect_WhenModelStateIsValid()
        {
            // Arrange
            var mockRepo = new Mock <IDataRepository <Employee> >();

            mockRepo.Setup(repo => repo.Add(It.IsAny <Employee>()))
            .Verifiable();
            var controller  = new EmployeeController(mockRepo.Object);
            var newEmployee = GetTestEmployee();
            // Act
            var result = controller.Add(newEmployee);
            // Assert
            var redirectToActionResult = Assert.IsType <RedirectToActionResult>(result);

            Assert.Null(redirectToActionResult.ControllerName);
            Assert.Equal("Index", redirectToActionResult.ActionName);
            mockRepo.Verify();
        }
Ejemplo n.º 12
0
        //add employee
        #region
        private void btnAdd_Click(object sender, EventArgs e)
        {
            //validation
            if (!ValidationHelper.LettersOnly(txtFirstName.Text) &&
                !ValidationHelper.LettersOnly(txtLastName.Text))
            {
                MessageBox.Show("Please enter a valid first or last name consisting of letters only");
                return;
            }
            else if (!ValidationHelper.IsEmail(txtEmail.Text))
            {
                MessageBox.Show("Please enter valid email");
                return;
            }
            else if (!ValidationHelper.NumberWithDashOrDecimal(txtPhone.Text))
            {
                MessageBox.Show("Please enter a vaild phone number");
                return;
            }
            //read input
            Employee emp = new Employee();

            emp.FirstName = txtFirstName.Text;
            emp.LastName  = txtLastName.Text;
            emp.Email     = txtEmail.Text;
            emp.Phone     = txtPhone.Text;
            emp.DOB       = DateTime.Parse(dtpDOB.Text);

            //pass to the controller
            EmployeeController controller = new EmployeeController();
            ResultEnum         result     = controller.Add(emp);

            //show output
            switch (result)
            {
            case ResultEnum.Success:
                MessageBox.Show("Employee Added.");
                break;

            case ResultEnum.Fail:
                MessageBox.Show("Cannot add employee");
                break;
            }
        }
Ejemplo n.º 13
0
        private ResultEnum Insert()
        {
            Employee emp = new Employee();

            emp.FirstName     = txtFirst.Text;
            emp.LastName      = txtLast.Text;
            emp.EmployeeDOB   = txtDOB.Text;
            emp.EmployeeEmail = txtEmail.Text;
            emp.EmployeePhone = txtPhone.Text;

            EmployeeController controller = new EmployeeController();
            ResultEnum         result     = controller.Add(emp);

            Result refreshDB = RefreshEmployeeDB();

            DataDisplay(refreshDB);

            return(result);
        }
Ejemplo n.º 14
0
        public void AddEmployeeTest()
        {
            Employee objEmployee = new Employee
            {
                EmployeeID = 1009,
                FirstName  = "Navneet",
                LastName   = "Huggi",
                EmpCode    = "1336",
                Position   = "IAS Aspirant",
                Office     = "Bangalore"
            };
            var objmoq = new Mock <IEmployeeDAL>();

            objmoq.Setup(X => X.AddEmployee(objEmployee)).Returns(true);
            EmployeeController objEmployeeController = new EmployeeController(objmoq.Object);

            var result = (RedirectToRouteResult)objEmployeeController.Add(objEmployee);

            Assert.AreEqual("Index", result.RouteValues["Action"]);
        }
        public void TestPostAdd_Test_Methods_Invocation()
        {
            var helperMock = new Mock <EmployeeControllerHelper>();

            helperMock.Setup(x => x.FindEmployees(It.IsAny <EmployeeModel>())).
            Returns(() => null);
            var mock = new Mock <IEmployeeDbContext>();

            mock.Setup(x => x.Employees.Add(It.IsAny <EmployeeModel>()))
            .Returns(new EmployeeModel());
            mock.Setup(x => x.SaveChanges())
            .Returns(0);

            var controller   = new EmployeeController(mock.Object, helperMock.Object);
            var actionResult = controller.Add(_testEmployeeModel);

            mock.Verify(x => x.Employees.Add(It.IsAny <EmployeeModel>()));
            mock.Verify(x => x.SaveChanges());
            helperMock.Verify(x => x.FindEmployees(It.IsAny <EmployeeModel>()));
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            //Loop validation check
            bool check = true;

            for (int i = 0; i < buttonEnablingArr.Length; i++)
            {
                check = buttonEnablingArr[i] && check;
            }

            if (check)
            {
                //Read input
                Employee newEmp = new Employee();
                newEmp.FirstName = txtFN.Text;
                newEmp.LastName  = txtLN.Text;
                newEmp.Email     = txtEmail.Text;
                newEmp.DOB       = DateTime.Parse(dateTimePicker1.Text);
                newEmp.Phone     = txtPh.Text;

                //Call controller
                EmployeeController controller = new EmployeeController();
                controller.Add(newEmp);

                //Clear textboxes and show output
                MessageBox.Show("Employee successfully added");
                txtFN.Clear();
                txtLN.Clear();
                txtEmail.Clear();
                txtPh.Clear();
                epFN.SetError(txtFN, null);
                epLN.SetError(txtLN, null);
                epEmail.SetError(txtEmail, null);
                epPhone.SetError(txtPh, null);
            }
            else
            {
                ErrorMessage.InputMessage();
            }
        }
Ejemplo n.º 17
0
 public void add(List <string> list)
 {
     EmployeeController.Add(list[0], list[1], list[2], list[3], list[4], 3);
 }
Ejemplo n.º 18
0
        public void TestEmployeeAdd()
        {
            ActionResult result = employeeController.Add() as ViewResult;

            Assert.IsNotNull(result);
        }