private static void AssertState(ServiceAttendance expectedState, ServiceAttendanceModel actual) { Assert.AreEqual(expectedState.Id, actual.Id); Assert.AreEqual(expectedState.Notes, actual.Notes); Assert.AreEqual(expectedState.StudentAssignedOfferingId, actual.StudentAssignedOfferingId); Assert.AreEqual(expectedState.SubjectId, actual.SelectedSubjectId); }
private void btnOK_Click(object sender, EventArgs e) { TBL_MP_HR_ManualAttendance_Master model = null; ServiceAttendance serviceAttendance = new ServiceAttendance(); try { if (!this.ValidateChildren()) { return; } if (this.AttendanceID == 0) { model = new TBL_MP_HR_ManualAttendance_Master(); } else { model = serviceAttendance.GetAttendanceInfoDbRecordByID(this.AttendanceID); } #region GATHER DATA INTO MODEL FROM VIEW model.AttendDate = dtAttendanceDate.Value; model.FK_EmployeeID = this.EmployeeID; if (IsOnSiteEmployee) { model.FK_CostCenterId = ((SelectListItem)cboProject.SelectedItem).ID; } else { model.FK_CostCenterId = null; } model.AttendInTime = dtIntime.Value; model.AttendOutTime = dtOutTime.Value; model.Duration = txtDuration.Text; model.IsActive = true; #endregion if (this.AttendanceID == 0) { this.AttendanceID = serviceAttendance.AddNewManualAttendance(model); } else { serviceAttendance.UpdateMannualAttendance(model); } this.DialogResult = DialogResult.OK; } catch (Exception ex) { string errMessage = ex.Message; if (ex.InnerException != null) { errMessage += string.Format("\n{0}", ex.InnerException.Message); } MessageBox.Show(errMessage, "frmAddEditMannualAttendanceEntry::btnOK_Click", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void GivenValidViewModel_WhenDelete_ThenServiceAttendanceHistoryKeptIntact() { ServiceAttendance expected = EducationContext.ServiceAttendances.Where(s => s.Id == 1).FirstOrDefault(); Target.Delete(User, 1); Assert.IsTrue(EducationContext.ServiceAttendances.Any(s => s.Id == expected.Id)); }
private static bool MatchProperties(ServiceAttendance actualState, StudentAssignedOffering expectedStudentAssignedOffering, DateTime expectedDateAttended, Subject expectedSubject, decimal expectedDuration, string expectedNotes) { Assert.AreEqual(expectedStudentAssignedOffering, actualState.StudentAssignedOffering); Assert.AreEqual(expectedDateAttended, actualState.DateAttended); Assert.AreEqual(expectedSubject.Id, actualState.Subject.Id); Assert.AreEqual(expectedDuration, actualState.Duration); Assert.AreEqual(expectedNotes, actualState.Notes); return(true); }
public void GivenValidServiceAttendanceId_WhenGenerateEditViewModel_ThenViewModelStateMatchesEntity() { ServiceAttendance expectedState = Data.ServiceAttendances.Single(a => a.Id == 1); PermissionFactory.Current.Expect(m => m.Create("EditServiceAttendance", Data.ServiceAttendances[0].StudentAssignedOffering)).Return(MockRepository.GenerateMock <IPermission>()); ServiceAttendanceModel actual = Target.GenerateEditViewModel(User, 1); AssertState(expectedState, actual); }
public void GivenAServiceAttendance_WhenAdd_ThenAddToContext() { var expected = new ServiceAttendance { Id = 1 }; Target.Add(expected); MockDbSet.AssertWasCalled(m => m.Add(expected)); }
public void GivenAServiceAttendance_WhenRemove_ThenRemoveFromContext() { var expected = new ServiceAttendance { Id = 1 }; Target.Remove(expected); MockDbSet.AssertWasCalled(m => m.Remove(expected)); }
public void GivenAServiceAttendance_ThenUpdate_ThenContextSetsModified() { var expected = new ServiceAttendance { Id = 1 }; Target.Update(expected); MockContext.AssertWasCalled(m => m.SetModified(expected)); }
public void GivenModifiedServiceAttendanceId_WhenGenerateEditViewModel_ThenViewModelContainsAuditData() { ServiceAttendance toEdit = EducationContext.ServiceAttendances.Single(a => a.LastModifyingUser != null); ServiceAttendanceModel actual = Target.GenerateEditViewModel(User, toEdit.Id); Assert.IsNotNull(actual.Audit.CreatedBy); Assert.AreNotEqual(DateTime.MinValue, actual.Audit.CreateTime); Assert.IsNotNull(actual.Audit.LastModifiedBy); Assert.IsTrue(actual.Audit.LastModifyTime.HasValue); }
public void GivenIdRequestParameter_AndServiceAttendanceDoesNotMatchStudentAssignedOfferingId_WhenInvokeFilterPredicate_ThenReturnFalse() { ServiceAttendance attendance = new ServiceAttendance { StudentAssignedOfferingId = 40 }; MockRequest.Expect(m => m["id"]).Return("1"); Target = new ServiceAttendanceClientDataTable(MockRequest); Assert.IsFalse(Target.FilterPredicate.Compile().Invoke(attendance)); }
private void Create(StudentAssignedOffering studentAssignedOffering, DateTime dateAttended, Subject subject, decimal duration, string notes, EducationSecurityPrincipal user) { var newAttendance = new ServiceAttendance(); newAttendance.StudentAssignedOffering = studentAssignedOffering; newAttendance.DateAttended = dateAttended; newAttendance.Subject = subject; newAttendance.Duration = duration; newAttendance.Notes = notes; newAttendance.CreatingUser = user.Identity.User; ServiceAttendanceRepository.Add(newAttendance); }
public void GivenValidViewModel_WhenEdit_ThenServiceAttendanceEdited_AndSaved() { ServiceAttendance expected = Repositories.MockServiceAttendanceRepository.Items.Where(s => s.Id == 1).Single(); var viewModel = new ServiceAttendanceModel { Id = 1, StudentAssignedOfferingId = 1, SelectedSubjectId = 1 }; PermissionFactory.Current.Expect(m => m.Create("EditServiceAttendance", Data.ServiceAttendances[0].StudentAssignedOffering)).Return(MockRepository.GenerateMock <IPermission>()); Target.Edit(viewModel, User); Repositories.MockServiceAttendanceRepository.AssertWasCalled(m => m.Update(expected)); Repositories.MockRepositoryContainer.AssertWasCalled(m => m.Save()); }
public void GivenValidViewModel_WhenEdit_ThenModifyAuditPropertiesSet() { ServiceAttendance toEdit = Repositories.MockServiceAttendanceRepository.Items.Where(s => s.Id == 1).Single(); var viewModel = new ServiceAttendanceModel { Id = 1, StudentAssignedOfferingId = 1, SelectedSubjectId = 1 }; PermissionFactory.Current.Expect(m => m.Create("EditServiceAttendance", Data.ServiceAttendances[0].StudentAssignedOffering)).Return(MockRepository.GenerateMock <IPermission>()); Target.Edit(viewModel, User); Assert.AreEqual(User.Identity.User, toEdit.LastModifyingUser); Assert.IsTrue(toEdit.LastModifyTime.Value.WithinTimeSpanOf(TimeSpan.FromSeconds(1), DateTime.Now)); }
public void GivenValidModel_WhenCopyTo_ThenAllFieldsAreCopied() { var actual = new ServiceAttendance(); Target.CopyFrom(TestData.ServiceAttendances[0]); Target.CopyTo(actual); Assert.AreEqual(actual.StudentAssignedOfferingId, Target.StudentAssignedOfferingId); Assert.AreEqual(actual.DateAttended, Target.DateAttended); Assert.AreEqual(actual.SubjectId, Target.SelectedSubjectId); Assert.AreEqual(actual.Duration, Target.Duration); Assert.AreEqual(actual.Notes, Target.Notes); }
public void GivenValidViewModel_WhenEdit_ThenServiceAttendanceHasStateFromViewModel() { ServiceAttendance actualState = Repositories.MockServiceAttendanceRepository.Items.Where(s => s.Id == 1).Single(); var expectedState = new ServiceAttendanceModel { Id = 1, StudentAssignedOfferingId = 1, SelectedSubjectId = 1, DateAttended = DateTime.Now.AddDays(1), Duration = 100, Notes = "Unit Test Notes" }; PermissionFactory.Current.Expect(m => m.Create("EditServiceAttendance", Data.ServiceAttendances[0].StudentAssignedOffering)).Return(MockRepository.GenerateMock <IPermission>()); Target.Edit(expectedState, User); Assert.AreEqual(expectedState.SelectedSubjectId, actualState.SubjectId); Assert.AreEqual(expectedState.DateAttended, actualState.DateAttended); Assert.AreEqual(expectedState.Duration, actualState.Duration); Assert.AreEqual(expectedState.Notes, actualState.Notes); }
public void GivenModelNotModified_WhenCopyFrom_ThenModelStatelastModifyValuesNull() { ServiceAttendance expectedState = new ServiceAttendance { CreateTime = new DateTime(2005, 4, 30), CreatingUser = new User { DisplayName = "fredBob" } }; ServiceAttendanceModel target = new ServiceAttendanceModel(); target.CopyFrom(expectedState); Assert.IsNull(target.Audit.LastModifiedBy); Assert.IsFalse(target.Audit.LastModifyTime.HasValue); }
private void PageImportAttendance_Load(object sender, EventArgs e) { try { _serviceAttendance = new ServiceAttendance(); _serviceAttendance.OnImportRecordProcessStart += _serviceAttendance_OnImportRecordProcessStart1; } catch (Exception ex) { string errMessage = ex.Message; if (ex.InnerException != null) { errMessage += string.Format("\n\n{0}", ex.InnerException.Message); } MessageBox.Show(errMessage, "PageImportAttendance::PageImportAttendance_Load", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void PageDailyAttendance_Load(object sender, EventArgs e) { try { this.Text = "EXCEL Gas & Equipments Pvt. Ltd. [Sync. Attendance Data]"; btnRemoveOnsiteemployeeFromSheet.Visible = false; PopulateProjects(); _serviceAttendance = new ServiceAttendance(); _serviceAttendance.OnImportRecordProcessStart += _serviceAttendance_OnImportRecordProcessStart1; } catch (Exception ex) { string errMessage = ex.Message; if (ex.InnerException != null) { errMessage += string.Format("\n\n{0}", ex.InnerException.Message); } MessageBox.Show(errMessage, "pageDailyAttendance::PageDailyAttendance_Load", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnPrepareMonthlySheet_Click(object sender, EventArgs e) { this.Cursor = Cursors.WaitCursor; ServiceAttendance serviceAttendance = new ServiceAttendance(); try { gridAttendance.DataSource = null; headerGridView.Values.Heading = string.Format("Fetching list of Distinct Employees for month ({0})", dtAttendanceMonth.Value.ToString("MMMM")); Application.DoEvents(); _EmployeesList = AppCommon.ConvertToBindingList <SelectListItem>(serviceAttendance.GetDistinctEmployeesListForMonthInAttendance(dtAttendanceMonth.Value)); gridActiveEmployees.DataSource = _EmployeesList; FormatEmployeeGrid(); Application.DoEvents(); headerGridView.Values.Heading = string.Format("Fetching list of Distinct Employees Completed....", dtAttendanceMonth.Value.ToString("MMMM")); Application.DoEvents(); headerGridView.Values.Heading = string.Format("Preparing Attendance Sheet for month ({0})", dtAttendanceMonth.Value.ToString("MMMM")); Application.DoEvents(); //_AttendanceList = AppCommon.ConvertToBindingList<vAttendanceRegister>((new ServiceAttendance()).GetAttendanceRecordsForMonth(dtAttendanceMonth.Value)); headerGridView.Values.Heading = string.Format("Fetched {0} Attendance Records. Now Binding to Grid", _AttendanceList.Count()); Application.DoEvents(); gridAttendance.DataSource = _AttendanceList; FormatAttendanceGrid(); Application.DoEvents(); SetAttendanceRowColor(); headerGridView.Values.Heading = string.Format("Attendance Sheet for month ({0}) generated successfully", dtAttendanceMonth.Value.ToString("MMMM")); Application.DoEvents(); } catch (Exception ex) { string errMessage = ex.Message; if (ex.InnerException != null) { errMessage += string.Format("\n{0}", ex.InnerException.Message); } MessageBox.Show(errMessage, "PageMonthlyAttendanceManager::btnPrepareAttendance_Click", MessageBoxButtons.OK, MessageBoxIcon.Error); } this.Cursor = Cursors.Default; }
public void Create(ServiceAttendanceModel viewModel, EducationSecurityPrincipal user) { if (viewModel == null) { throw new ArgumentNullException("viewModel"); } if (user == null) { throw new ArgumentNullException("user"); } var studentAssignedOffering = StudentAssignedOfferingRepository.Items.Single(s => s.Id == viewModel.StudentAssignedOfferingId); IPermission permission = PermissionFactory.Current.Create("CreateServiceAttendance", studentAssignedOffering); permission.GrantAccess(user); ServiceAttendance serviceAttendance = new ServiceAttendance { CreatingUser = user.Identity.User }; viewModel.CopyTo(serviceAttendance); ServiceAttendanceRepository.Add(serviceAttendance); RepositoryContainer.Save(); }
public void GivenServiceAttendance_WhenInvokeDataSelector_ThenPropertiesMatch() { ServiceAttendance expectedState = new ServiceAttendance { DateAttended = new DateTime(2003, 4, 5), Duration = 45, Id = 35, Notes = "blkah", Subject = new Subject { Name = "disojfw" } }; MockRequest.Expect(m => m["id"]).Return("1"); Target = new ServiceAttendanceClientDataTable(MockRequest); dynamic actual = Target.DataSelector.Compile().Invoke(expectedState); Assert.AreEqual(expectedState.DateAttended, actual.DateAttended); Assert.AreEqual(expectedState.Duration, actual.Duration); Assert.AreEqual(expectedState.Id, actual.Id); Assert.AreEqual(expectedState.Notes, actual.Notes); Assert.AreEqual(expectedState.Subject.Name, actual.Subject); }
public void GivenModelHasAuditData_WhenCopyFrom_ThenModelStateSet() { ServiceAttendance expectedState = new ServiceAttendance { CreateTime = new DateTime(2005, 4, 30), CreatingUser = new User { DisplayName = "fredBob" }, LastModifyTime = new DateTime(2010, 5, 13), LastModifyingUser = new User { DisplayName = "jimGeorge" } }; ServiceAttendanceModel target = new ServiceAttendanceModel(); target.CopyFrom(expectedState); AuditModel actualState = target.Audit; Assert.AreEqual(expectedState.CreateTime, actualState.CreateTime); Assert.AreEqual(expectedState.CreatingUser.DisplayName, actualState.CreatedBy); Assert.AreEqual(expectedState.LastModifyTime, actualState.LastModifyTime); Assert.AreEqual(expectedState.LastModifyingUser.DisplayName, actualState.LastModifiedBy); }
public void GivenSort_AndOneServiceAttendanceIsVeryLarge_WhenGenerateDataTableResultViewModel_ThenSucceed() { DataTableRequestModel model = new DataTableRequestModel(); model.iDisplayLength = 10; var request = MockHttpContextFactory.CreateRequest(); request.Expect(r => r["id"]).Return("1"); request.Expect(r => r["iSortCol_0"]).Return("0"); request.Expect(r => r["sSortDir_0"]).Return("asc"); ServiceAttendanceClientDataTable dataTable = new ServiceAttendanceClientDataTable(request); ServiceAttendance attendance = new ServiceAttendance { DateAttended = DateTime.Now.AddYears(100), StudentAssignedOffering = EducationContext.StudentAssignedOfferings.Where(s => s.Id == 1).Single(), Subject = EducationContext.Subjects.First(), CreatingUser = User.Identity.User }; EducationContext.ServiceAttendances.Add(attendance); EducationContext.SaveChanges(); var actual = Target.GenerateDataTableResultViewModel(model, dataTable); }
public void Update(ServiceAttendance item) { Context.SetModified(item); }
public void Remove(ServiceAttendance item) { Context.ServiceAttendances.Remove(item); }
public void Add(ServiceAttendance item) { Context.ServiceAttendances.Add(item); }
private void btnPreareAttendanceGrid_Click(object sender, EventArgs e) { this.Cursor = Cursors.WaitCursor; ServiceAttendance serviceAttendance = new ServiceAttendance(); string empCategoryIDs = string.Empty; string projectIDs = string.Empty; string departmentIDs = string.Empty; string employeeIDs = string.Empty; try { // get all selected CATEGORY IDs in a string foreach (DataGridViewRow mRow in gridEmployeeCategories.Rows) { if ((bool)mRow.Cells["IsActive"].Value == true) { empCategoryIDs += string.Format("{0},", mRow.Cells["ID"].Value); } } if (empCategoryIDs != string.Empty) { empCategoryIDs = empCategoryIDs.TrimEnd(','); } // do the same for PROJECTS, DEPAQRTMENTS & EMPLOYEES..THIS WAY WE GET ALL SELECTED IDs //for projects foreach (DataGridViewRow mRow in gridProjects.Rows) { if ((bool)mRow.Cells["IsActive"].Value == true) { projectIDs += string.Format("{0},", mRow.Cells["ID"].Value); } } if (projectIDs != string.Empty) { projectIDs = projectIDs.TrimEnd(','); } //for departments foreach (DataGridViewRow mRow in gridDepartments.Rows) { if ((bool)mRow.Cells["IsActive"].Value == true) { departmentIDs += string.Format("{0},", mRow.Cells["ID"].Value); } } if (departmentIDs != string.Empty) { departmentIDs = departmentIDs.TrimEnd(','); } //for employee foreach (DataGridViewRow mRow in gridEmployees.Rows) { if ((bool)mRow.Cells["IsActive"].Value == true) { employeeIDs += string.Format("{0},", mRow.Cells["ID"].Value); } } if (employeeIDs != string.Empty) { employeeIDs = employeeIDs.TrimEnd(','); } gridAttendance.DataSource = null; headerGroupOptions.ValuesSecondary.Heading = string.Format("Fetching list of Distinct Employees for month ({0})", dtToDate.Value.ToString("MMMM")); Application.DoEvents(); _AttendanceList = AppCommon.ConvertToBindingList <AttendanceGridViewModel>((new ServiceAttendance()).GetAttendanceRecordsForFilter( dtFromDate.Value, dtToDate.Value, empCategoryIDs, projectIDs, departmentIDs, employeeIDs)); headerGroupOptions.ValuesSecondary.Heading = string.Format("Fetched {0} Attendance Records. Now Binding to Grid", _AttendanceList.Count()); Application.DoEvents(); gridAttendance.DataSource = _AttendanceList; FormatAttendanceGrid(); Application.DoEvents(); SetAttendanceRowColor(); headerGroupOptions.ValuesSecondary.Heading = string.Format("Attendance Sheet for month ({0}) generated successfully", dtToDate.Value.ToString("MMMM")); Application.DoEvents(); } catch (Exception ex) { string errMessage = ex.Message; if (ex.InnerException != null) { errMessage += string.Format("\n{0}", ex.InnerException.Message); } MessageBox.Show(errMessage, "PageAttendanceGridView::btnPreareAttendanceGrid_Click", MessageBoxButtons.OK, MessageBoxIcon.Error); } this.Cursor = Cursors.Default; }
private static bool AssertPropertiesMatch(ServiceAttendanceModel expectedState, ServiceAttendance actualState) { Assert.IsNotNull(actualState); Assert.AreEqual(expectedState.DateAttended, actualState.DateAttended); Assert.AreEqual(expectedState.SelectedSubjectId, actualState.SubjectId); Assert.AreEqual(expectedState.Duration, actualState.Duration); Assert.AreEqual(expectedState.Notes, actualState.Notes); return(true); }