Exemple #1
0
        public void ShouldCreateLeaveForCurrentlyLoggedInEmployee()
        {
            var leave = new CreateLeaveViewModel
            {
                FromDate = DateTime.Now.Date,
                ToDate   = DateTime.Now.AddDays(2).Date,
                Reason   = "No Reason"
            };

            employeeManagerMock.Setup(x => x.GetEmployeeByUserNameAsync(It.IsAny <string>()))
            .Returns(Task.FromResult(new Employee()
            {
                Id = Guid.NewGuid().ToString()
            }));

            leaveManagerMock.Setup(x => x.AddLeave(It.IsAny <Leave>()))
            .Returns(1);
            var controller = new LeaveController(leaveManagerMock.Object, employeeManagerMock.Object);

            controller.ControllerContext.HttpContext = _contextMock.Object;
            var results = controller.AddLeave(leave);
            var redirectToActionResult = results as RedirectToActionResult;

            Assert.AreEqual("Index", redirectToActionResult.ActionName);
        }
        public void DuplicateApplyTest()
        {
            _leave = CreateLeave("Unit Test: Apply with overlapping date.");

            LeaveController upc = new LeaveController();

            // 1. Apply a new leave.
            _leave = upc.Apply(_leave);

            Assert.AreEqual(_leave.Status, LeaveStatuses.Pending, "Failed to apply new leave.");

            // Keep the previous workflow instance.
            Guid correlationId = _leave.CorrelationID;

            try
            {
                // 2. This will cause exception to occur.
                upc.Apply(_leave);
            }
            catch (ApplicationException ex)
            {
                if (ex.Message != "Date range is overlapping with another leave.")
                {
                    throw ex;
                }
            }

            // 3. Cancel it.
            // Need to do this, otherwise, there will be an orphaned workflow instance.
            _leave.CorrelationID = correlationId;
            upc.Cancel(_leave);

            _leave = upc.GetLeaveById(_leave.LeaveID);
            Assert.AreEqual(_leave.Status, LeaveStatuses.Cancelled, "Failed to cancel leave.");
        }
Exemple #3
0
        public void ShouldEditTheLeaveTest()
        {
            var leave = new UpdateLeaveViewModel
            {
                FromDate = DateTime.Now.Date,
                ToDate   = DateTime.Now.AddDays(2).Date,
                Reason   = "No Reason",
                StatusId = (int)LeaveStatusEnum.Pending
            };

            employeeManagerMock.Setup(x => x.GetEmployeeByUserNameAsync(It.IsAny <string>()))
            .Returns(Task.FromResult(new Employee()
            {
                Id = Guid.NewGuid().ToString()
            }));

            leaveManagerMock.Setup(x => x.UpdateLeave(It.IsAny <Leave>()))
            .Returns(1);

            var controller = new LeaveController(leaveManagerMock.Object, employeeManagerMock.Object);

            controller.ControllerContext.HttpContext = _contextMock.Object;
            var results = controller.EditLeave(leave);
            var redirectToActionResult = results as RedirectToActionResult;

            Assert.AreEqual("Index", redirectToActionResult.ActionName);
        }
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            user = e.Parameter as User;
            LeaveController controller = new LeaveController();

            all_leaves_list.ItemsSource = controller.allUserLeaves(user.NIC);
        }
Exemple #5
0
        private async void apply_btn_Click(object sender, RoutedEventArgs e)
        {
            Leave leave = new Leave();

            //Add date validation to the if block
            if (!string.IsNullOrWhiteSpace(reason_textBox.Text) && !string.IsNullOrWhiteSpace(userNIC))
            {
                leave.Reason   = reason_textBox.Text;
                leave.FromDate = from_date_picker.Date.ToString();
                leave.ToDate   = to_date_picker.Date.ToString();
                leave.Status   = 2;
                leave.UserID   = userNIC;
                leave.LeaveID  = "TestingID123";

                LeaveController controller = new LeaveController();
                int             status     = controller.newLeave(leave);

                if (status == 1)
                {
                    MessageDialog msg = new MessageDialog("Successfully Applied!");
                    await msg.ShowAsync();
                }
                else
                {
                    MessageDialog msg = new MessageDialog("Failed to Apply!");
                    await msg.ShowAsync();
                }

                Frame.Navigate(typeof(WelcomPage), user);
            }
            else
            {
                warning_message.Text = "Please fill all the fields!";
            }
        }
Exemple #6
0
        // The id parameter name should match the DataKeyNames value set on the control
        public void leaveGrid_UpdateItem(int leaveID)
        {
            var upc   = new LeaveController();
            var leave = upc.GetLeaveById(leaveID);

            if (leave == null)
            {
                // The item wasn't found
                ModelState.AddModelError("", String.Format("Item with id {0} was not found", leaveID));
                return;
            }

            TryUpdateModel(leave);
            if (ModelState.IsValid)
            {
                if (_isApproved)
                {
                    upc.Approve(leave);
                }
                else
                {
                    upc.Reject(leave);
                }
            }
        }
Exemple #7
0
        public void ShouldReturnAddLeaveView()
        {
            var controller = new LeaveController(leaveManagerMock.Object, employeeManagerMock.Object);

            controller.ControllerContext.HttpContext = _contextMock.Object;
            var results = controller.AddLeave();

            Assert.IsInstanceOf <IActionResult>(results);
        }
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            user             = e.Parameter as User;
            fname_block.Text = user.FirstName;
            lname_block.Text = user.LastName;

            LeaveController controller = new LeaveController();

            leave_approval_listView.ItemsSource = controller.hrLeaveRequests();
        }
Exemple #9
0
        public void ApplyLeaveTest()
        {
            leaveController = new LeaveController(_leaveBO);
            var leave        = new Leave();
            var actionResult = leaveController.ApplyLeave(leave);
            var status       = (((ObjectResult)actionResult.Result).Value as LeaveResponse).Status;

            Assert.Equal(status.ToString(), LeaveStatus.Applied.ToString());
            Assert.Equal((actionResult.Result as OkObjectResult).StatusCode, (int)System.Net.HttpStatusCode.OK);
        }
Exemple #10
0
        private void LoadLeaveRecords()
        {
            // NOTE: Since this is WinForms, we can actually keep a cache of the
            // Leave records in memory and do not need to keep querying the back-end.

            LeaveCategories?category = LeaveController.GetEnumValue <LeaveCategories>(categoryFilter.Text);
            LeaveStatuses?  status   = LeaveController.GetEnumValue <LeaveStatuses>(statusFilter.Text);

            BindGrid(leaveRecordsGrid, _leaves);
            RefreshGrid(leaveRecordsGrid, _leaves, _sortColumn, categoryFilter.Text,
                        statusFilter.Text, Environment.UserName);
        }
Exemple #11
0
        public List <Leave> leaveGrid_GetData(
            [Control] LeaveCategories?category,
            [Control] LeaveStatuses?status,
            int maximumRows,
            int startRowIndex, out int totalRowCount, string sortByExpression
            )
        {
            var upc = new LeaveController();

            return(upc.ListLeavesByEmployee(maximumRows, startRowIndex, sortByExpression,
                                            Environment.UserName, category, status, out totalRowCount));
        }
        public void DeleteLeave()
        {
            // Arrange
            LeaveController controller = new LeaveController();

            var actResult = controller.Delete(1);
            // Act
            var result = actResult as OkNegotiatedContentResult <bool>;

            // Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Content == true);
        }
Exemple #13
0
        private void LoadLeaves()
        {
            // NOTE: Since this is WinForms, we can actually keep a cache of the
            // Leave records in memory and do not need to keep querying the back-end.

            int totalRowCount = 0;
            var upc           = new LeaveController();

            // For simplicity, we are only querying back 1000 records and paging is
            // not implemented because it is not necessary in Windows Forms.
            _leaves = upc.ListLeavesByEmployee(1000, 0, null,
                                               null, null, null, out totalRowCount);
        }
        public void getLeave()
        {
            // Arrange
            LeaveController controller = new LeaveController();

            var actResult = controller.Get(1);
            // Act
            var result = actResult as OkNegotiatedContentResult <Espl.Linkup.Domain.Leaves.Leave>;

            // Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Content.ID > 0);
        }
Exemple #15
0
        public void ShouldReturnLeaveViewWithLeavesOfTheCurrentUser()
        {
            leaveManagerMock.Setup(x => x.GetLeaveByEmployeeId(It.IsAny <string>()))
            .Returns(value: new List <Leave>());
            employeeManagerMock.Setup(x => x.GetEmployeeByUserNameAsync(It.IsAny <string>()))
            .Returns(Task.FromResult(new Employee()
            {
                Id = Guid.NewGuid().ToString()
            }));
            var controller = new LeaveController(leaveManagerMock.Object, employeeManagerMock.Object);

            controller.ControllerContext.HttpContext = _contextMock.Object;
            var results = controller.Index();

            Assert.IsInstanceOf <IActionResult>(results);
        }
        public void ApplyThenCancelTest()
        {
            _leave = CreateLeave("Unit Test: Apply Then Cancel");

            LeaveController upc = new LeaveController();

            // 1. Apply a new leave.
            _leave = upc.Apply(_leave);

            Assert.AreEqual(_leave.Status, LeaveStatuses.Pending, "Failed to apply new leave.");

            // 2. Cancel it.
            upc.Cancel(_leave);

            _leave = upc.GetLeaveById(_leave.LeaveID);
            Assert.AreEqual(_leave.Status, LeaveStatuses.Cancelled, "Failed to cancel leave.");
        }
        public void ApplyThenRejectTest()
        {
            _leave = CreateLeave("Unit Test: Apply Then Reject");

            LeaveController upc = new LeaveController();

            // 1. Apply a new leave.
            _leave = upc.Apply(_leave);

            Assert.AreEqual(_leave.Status, LeaveStatuses.Pending, "Failed to apply new leave.");

            // 2. Reject it.
            upc.Reject(_leave);

            _leave = upc.GetLeaveById(_leave.LeaveID);
            Assert.AreEqual(_leave.Status, LeaveStatuses.Rejected, "Failed to reject leave.");
        }
Exemple #18
0
        public List <Leave> leaveGrid_GetData(
            [Control] LeaveCategories?category,
            [Control] LeaveStatuses?status,
            int maximumRows,
            int startRowIndex, out int totalRowCount, string sortByExpression
            )
        {
            if (!Page.IsPostBack && status == null)
            {
                status = LeaveStatuses.Pending;
            }

            var upc = new LeaveController();

            return(upc.ListLeavesByEmployee(maximumRows, startRowIndex, sortByExpression,
                                            null, category, status, out totalRowCount));
        }
        private async void edit_btn_Click(object sender, RoutedEventArgs e)
        {
            LeaveController controller = new LeaveController();
            int             status     = controller.updateLeave(leave);

            if (status == 1)
            {
                MessageDialog msg = new MessageDialog("Successfully Edited!");
                await msg.ShowAsync();
            }
            else
            {
                MessageDialog msg = new MessageDialog("Failed to Edit!");
                await msg.ShowAsync();
            }

            Frame.Navigate(typeof(UserViewAllLeaves), user);
        }
        private async void approve_btn_Click(object sender, RoutedEventArgs e)
        {
            leave.Status = 0;
            LeaveController controller = new LeaveController();
            int             status     = controller.acceptLeave(leave);

            if (status == 1)
            {
                MessageDialog msg = new MessageDialog("Successfully Approved!");
                await msg.ShowAsync();
            }
            else
            {
                MessageDialog msg = new MessageDialog("Failed to Approve!");
                await msg.ShowAsync();
            }

            Frame.Navigate(typeof(HRWelcomPage), user);
        }
Exemple #21
0
        public void leaveGrid_UpdateItem(long leaveID)
        {
            var upc   = new LeaveController();
            var leave = upc.GetLeaveById(leaveID);

            if (leave == null)
            {
                // The item wasn't found
                ModelState.AddModelError("", String.Format("Item with id {0} was not found", leaveID));
                return;
            }

            TryUpdateModel(leave);
            if (ModelState.IsValid)
            {
                // Save changes here, e.g. MyDataLayer.SaveChanges();
                upc.Cancel(leave);
            }
        }
Exemple #22
0
        public void ShouldReturnLeaveDetailsViewWithSpecificLeaveTest()
        {
            var leave = new Leave
            {
                FromDate = DateTime.Now.Date,
                ToDate   = DateTime.Now.AddDays(2).Date,
                Reason   = "No Reason",
                StatusId = (int)LeaveStatusEnum.Pending
            };

            leaveManagerMock.Setup(x => x.GetLeaveById(It.IsAny <int>()))
            .Returns(leave);

            var controller = new LeaveController(leaveManagerMock.Object, employeeManagerMock.Object);

            controller.ControllerContext.HttpContext = _contextMock.Object;
            var results = controller.LeaveDetails(2);

            Assert.IsInstanceOf <IActionResult>(results);
        }
        /// <summary>
        /// Initializes the class.
        /// </summary>
        public LeaveViewModelBase()
        {
            _upc = new LeaveController();

            // Load enums values that can be used by filter controls.
            _categories = LoadEnumFilter(typeof(LeaveCategories));
            _statuses   = LoadEnumFilter(typeof(LeaveStatuses));

            // Set default selection.
            this.CategoryFilter = "- All -";
            this.StatusFilter   = "- All -";

            // Initialize commands.
            _filterCommand = new RelayCommand(p => this.FilterLeaves(), null);
            _reloadCommand = new RelayCommand(p => this.ReloadLeaves(), null);

            // Load the cache.
            this.SortExpression = "DateSubmitted DESC";
            LoadLeaves();
        }
        public void PostLeave()
        {
            // Arrange
            LeaveController controller = new LeaveController();

            Espl.Linkup.Domain.Leaves.Leave leaveObj = new Espl.Linkup.Domain.Leaves.Leave
            {
                NumberOfLeave = 12,
                Reason        = "Sample",
                Status        = "Approved",
                StartDate     = new DateTime(2016, 12, 12),
                EndDate       = new DateTime(2016, 12, 18)
            };
            var actResult = controller.Post(leaveObj);
            // Act
            var result = actResult as OkNegotiatedContentResult <Espl.Linkup.Domain.Leaves.Leave>;

            // Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Content.ID > 0);
        }
        public void PutLeave()
        {
            // Arrange
            LeaveController controller = new LeaveController();

            Espl.Linkup.Domain.Leaves.Leave leaveObj = new Espl.Linkup.Domain.Leaves.Leave
            {
                ID            = 1,
                NumberOfLeave = 12,
                Reason        = "Put request sucessfull",
                Status        = "Approved",
                StartDate     = new DateTime(2016, 12, 12),
                EndDate       = new DateTime(2016, 12, 18)
            };
            var actResult = controller.Put(1, leaveObj);
            // Act
            var result = actResult as OkNegotiatedContentResult <Espl.Linkup.Domain.Leaves.Leave>;

            // Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Content.Reason.Equals("Put request sucessfull"));
        }
Exemple #26
0
        /// <summary>
        /// Inserts a new leave.
        /// </summary>
        public void leaveForm_InsertItem()
        {
            var leave = new Leave();

            TryUpdateModel(leave);

            if (ModelState.IsValid)
            {
                var upc = new LeaveController();

                try
                {
                    upc.Apply(leave);
                }
                catch (ApplicationException ex)
                {
                    ModelState.AddModelError(string.Empty, ex.Message);
                    return;
                }

                leaveGrid.DataBind();
            }
        }
Exemple #27
0
        private void cancelButton_Click(object sender, EventArgs e)
        {
            // Exit when no row is selected.
            if (leaveRecordsGrid.SelectedRows.Count == 0)
            {
                return;
            }

            var upc = new LeaveController();

            try
            {
                // Get the Leave object.
                Leave leave = leaveRecordsGrid.SelectedRows[0].DataBoundItem as Leave;

                // Get the Leave index position in the list.
                int i = _leaves.IndexOf(leave);

                leave = upc.Cancel(leave);

                // Update the Leave in the list.
                _leaves[i] = leave;

                RefreshGrid(leaveRecordsGrid, _leaves, _sortColumn, categoryFilter.Text,
                            statusFilter.Text, Environment.UserName);
            }
            catch (ApplicationException ex)
            {
                MessageBox.Show(this, ex.Message, "Error Applying New Leave", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message, "An Unexpected Error Occurred", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
Exemple #28
0
        private void approvalsButton_Click(object sender, EventArgs e)
        {
            // Exit when no row is selected.
            if (approvalsGrid.SelectedRows.Count == 0)
            {
                return;
            }

            var upc = new LeaveController();

            try
            {
                // Get the Leave object.
                Leave leave = approvalsGrid.SelectedRows[0].DataBoundItem as Leave;

                // Get the Leave index position in the list.
                int i = _leaves.IndexOf(leave);

                if (sender == approveButton)
                {
                    leave = upc.Approve(leave);
                }
                else
                {
                    leave = upc.Reject(leave);
                }

                // Update the Leave in the approval list.
                _leaves[i] = leave;
                RefreshGrid(approvalsGrid, _leaves, _apSortColumn, apCategoryFilter.Text, apStatusFilter.Text);
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message, "An Unexpected Error Occurred", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
Exemple #29
0
        private void InitializeApply()
        {
            employeeLabel.Text     = Environment.UserName;
            categoryBox.DataSource = LeaveController.GetCategories();
            durationBox.Value      = 1;

            startDateBox.MinDate = DateTime.Today.AddDays(-7);
            endDateBox.MinDate   = startDateBox.Value;

            _sortColumn = "DateSubmitted DESC";

            // Load all the filters with enum values.
            _isLoading = true;
            LoadEnumFilter(categoryFilter, typeof(LeaveCategories));
            LoadEnumFilter(statusFilter, typeof(LeaveStatuses));
            _isLoading = false;

            leaveRecordsGrid.AutoGenerateColumns = false;

            // Default to sort DateSubmitted descending.
            _sortColumn = submitDateColumn.DataPropertyName + " DESC";

            LoadLeaveRecords();
        }
Exemple #30
0
        private void applyButton_Click(object sender, EventArgs e)
        {
            var upc = new LeaveController();

            // Create new Leave.
            var leave = new Leave()
            {
                Employee    = Environment.UserName,
                Category    = (LeaveCategories)categoryBox.SelectedIndex,
                StartDate   = startDateBox.Value.Date,
                EndDate     = endDateBox.Value.Date,
                Duration    = Convert.ToByte(durationBox.Value),
                Description = descriptionBox.Text
            };

            try
            {
                leave = upc.Apply(leave);

                // Add new leave to list of records.
                _leaves.Add(leave);

                RefreshGrid(leaveRecordsGrid, _leaves, _sortColumn, categoryFilter.Text,
                            statusFilter.Text, Environment.UserName);
            }
            catch (ApplicationException ex)
            {
                MessageBox.Show(this, ex.Message, "Error Applying New Leave", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message, "An Unexpected Error Occurred", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }