public FluentRecordBase AddWorkerSignin( Worker worker = null //DateTime? datecreated = null, //DateTime? dateupdated = null ) { // // DEPENDENCIES if (_servWSI == null) { AddServWorkerSignin(); } if (worker != null) { _w = worker; } if (_w == null) { AddWorker(); } // // ARRANGE // // ACT _wsi = _servWSI.CreateSignin(_w.dwccardnum, DateTime.Now, _user); return(this); }
/// <summary> /// /// </summary> /// <param name="waid"></param> /// <param name="wsiid"></param> /// <returns></returns> public bool Assign(WorkAssignment asmt, WorkerSignin signin, string user) { int wid; //Assignments must be explicitly unassigned first; throws exception if either record is in assigned state if (signin == null) { throw new NullReferenceException("WorkerSignin is null"); } if (asmt == null) { throw new NullReferenceException("WorkAssignment is null"); } // // validate state of WSI and WA records assignCheckWSI_WAID_must_be_null(signin); assignCheckWSI_WID_cannot_be_null(signin); assignCheckWA_WSIID_must_be_null(asmt); assignCheckWA_legitimate_orphan(asmt, signin); wid = assignCheckWSI_cardnumber_match(signin); // // Link signin with work assignment signin.WorkAssignmentID = asmt.ID; asmt.workerSigninID = signin.ID; asmt.workerAssignedID = wid; // // update timestamps and save asmt.updatedByUser(user); signin.updatedByUser(user); unitOfWork.SaveChanges(); log(asmt.ID, user, "WSIID:" + signin.ID + " Assign successful"); return(true); }
public void Create_WSI_with_worker_match_succeeds() { // //Arrange const int fakeid = 66666; var tenantService = new Mock <ITenantService>(); tenantService.Setup(service => service.GetCurrentTenant()).Returns(UnitTestExtensions.TestingTenant); var _signin = new WorkerSignin { dwccardnum = fakeid, dateforsignin = DateTime.Today }; var _serv = new WorkerSigninService(_wsiRepo.Object, _wServ.Object, _iServ.Object, _wrServ.Object, _uow.Object, _map.Object, _cServ.Object, tenantService.Object); var _cbsignin = new WorkerSignin(); _wsiRepo.Setup(s => s.Add(It.IsAny <WorkerSignin>())).Callback((WorkerSignin s) => { _cbsignin = s; }); // //Act _serv.CreateSignin(fakeid, DateTime.Today, "UnitTest"); // //Assert Assert.AreEqual(_signin.dwccardnum, _cbsignin.dwccardnum); Assert.AreEqual(_signin.dateforsignin, _cbsignin.dateforsignin); }
/// <summary> /// WorkerSignin's WAID must be null for an assignment /// </summary> /// <param name="wsi"></param> private static void assignCheckWSI_WAID_must_be_null(WorkerSignin wsi) { if (wsi.WorkAssignmentID != null) { throw new MacheteDispatchException( "WorkerSignin already associated with WorkAssignment ID" + wsi.WorkAssignmentID); } }
/// <summary> /// WorkerSignin's WID must not be null for an assignment /// </summary> /// <param name="wsi"></param> private static void assignCheckWSI_WID_cannot_be_null(WorkerSignin wsi) { if (wsi.WorkerID == null) { throw new MacheteIntegrityException( "WorkerSignin key " + wsi.dwccardnum.ToString() + "is not associated with a Worker record. " + "Machete cannot assign a worker when no Worker record exists."); } }
public FluentRecordBase AddWorkerSignin(Worker worker = null) { // ARRANGE _servWSI = container.GetRequiredService <IWorkerSigninService>(); var _w = worker ?? AddWorker(); // // ACT _wsi = _servWSI.CreateSignin(_w.dwccardnum, DateTime.Now, _user); return(this); }
private void unassignBoth(int waid, int wsiid, string user) { WorkAssignment wa = waRepo.GetById(waid); WorkerSignin wsi = wsiRepo.GetById(wsiid); if (matchWAWSI(wa, wsi)) { unassignBoth(wa, wsi, user); } else { throw new Exception("The Worker and the Assignment do not match"); } }
/// <summary> /// Check that WorkerSignin's Worker ID matches Worker's ID returned from cardnumber get /// </summary> /// <param name="wsi"></param> /// <returns></returns> private int assignCheckWSI_cardnumber_match(WorkerSignin wsi) { Worker worker = wRepo.GetByMemberID(wsi.dwccardnum); if (worker == null) { throw new NullReferenceException("Worker for key " + wsi.dwccardnum.ToString() + " is null"); } if (worker.ID != wsi.WorkerID) { throw new MacheteIntegrityException("WorkerSignin's internal WorkerID and public worker ID don't match"); } return(worker.ID); }
/// <summary> /// /// </summary> /// <param name="wa"></param> /// <param name="wsi"></param> private static void assignCheckWA_legitimate_orphan(WorkAssignment wa, WorkerSignin wsi) { if (wa.workerSigninID == null && //WA.WSIID == NULL wa.workerAssignedID != null && //WA.WID != NULL // Orphan Assignment if first two tests pass // If orphan, can only assign to a WSI with the same WID. Otherwise, // user needs to unassign first wa.workerAssignedID != wsi.WorkerID) //WA.WID != WSI.WID { throw new MacheteDispatchException( "Orphaned WorkAssignment, associated with Worker ID " + wa.workerAssignedID + "; Unassign first, the assign to new Worker"); } }
/// <summary> /// Check that WorkerSignin's Worker ID matches Worker's ID returned from cardnumber get /// </summary> /// <param name="wsi"></param> /// <returns></returns> private int assignCheckWSI_cardnumber_match(WorkerSignin wsi) { Worker worker = db.Workers.FirstOrDefault(w => w.dwccardnum.Equals(wsi.dwccardnum)); if (worker == null) { throw new NullReferenceException("Worker for key " + wsi.dwccardnum.ToString() + " is null"); } if (worker.ID != wsi.WorkerID) { throw new MacheteIntegrityException("WorkerSignin's internal WorkerID and public worker ID don't match"); } return(worker.ID); }
private void unassignBoth(WorkAssignment asmt, WorkerSignin signin, string user) { //Have both assignment and signin. if (signin == null || asmt == null) { throw new NullReferenceException("Signin and WorkAssignment are both null"); } //Try unassign with WorkerSignin only signin.WorkAssignmentID = null; asmt.workerSigninID = null; asmt.workerAssignedID = null; asmt.updatedByUser(user); signin.updatedByUser(user); unitOfWork.SaveChanges(); log(asmt.ID, user, "WSIID:" + signin.ID + " Unassign successful"); }
public FluentRecordBase AddWorkerSignin(Worker worker = null) { // ARRANGE _servWSI = container.GetRequiredService <IWorkerSigninService>(); var _w = worker ?? AddWorker(); // // ACT (convert to UTC, as the client would) _wsi = _servWSI.CreateSignin( _w.dwccardnum, TimeZoneInfo .ConvertTimeToUtc(DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Unspecified), ClientTimeZoneInfo), _user ); return(this); }
private bool matchWAWSI(WorkAssignment wa, WorkerSignin wsi) { if (wa == null && wsi == null) { throw new NullReferenceException("WorkAssignment and WorkerSignin objects both null."); } if (wa == null) { // only have WSI and wsi.WAID is null. no match. if (wsi.WorkAssignmentID == null) { return(false); } wa = waRepo.GetById((int)wsi.WorkAssignmentID); if (wa == null) { throw new NullReferenceException("WorkAssignment GetById returned null"); } } if (wsi == null) { // only have WA and wa.WSIID is null. no match if (wa.workerSigninID == null) { return(false); } wsi = wsiRepo.GetById((int)wa.workerSigninID); if (wsi == null) { throw new NullReferenceException("WorkerSignin GetById returned null"); } } if (wa.workerSigninID == wsi.ID && wsi.WorkAssignmentID == wa.ID && wa.workerAssignedID == wsi.WorkerID) { return(true); } else { return(false); } }
private void unassignWorkAssignmentOnly(int waid, string user) { // Get assignment WorkAssignment wa = waRepo.GetById((int)waid); if (wa == null) { throw new NullReferenceException("WAID " + waid.ToString() + "returned a null Work Assignment record"); } // // Starting with WA: // 1. Does WA.WSIID point to anything? if (wa.workerSigninID == null) // No { // clear any orphan assignment wa.workerAssignedID = null; unitOfWork.SaveChanges(); return; } // // 2. WA.WSIID points to something. Does it link back? if (matchWAWSI(wa, null)) { // Unassign both WorkerSignin wsi = wsiRepo.GetById((int)wa.workerSigninID); unassignBoth(wa, wsi, user); return; } // // 3. If points to something, but doesn't link bach, does something // match it's link? WorkerSignin linkedWSI = wsiRepo.GetById((int)wa.workerSigninID); if (linkedWSI.WorkAssignmentID == null || matchWAWSI(null, linkedWSI)) { //Something matches its link. My link to something assumed bad. wa.workerSigninID = null; unitOfWork.SaveChanges(); return; } else { throw new MacheteIntegrityException("Unassign found chain of mislinked records, starting with WAID " + wa.ID.ToString()); } }
public void Integration_Queryable_test() { // Arrange - load test records var worker = frb.AddWorkerSignin().ToWorker(); var signin = frb.ToWorkerSignin(); // Act var q = frb.ToFactory().Get().WorkerSignins.AsQueryable(); q = q.Where(r => r.dwccardnum == signin.dwccardnum && DbFunctions.DiffDays(r.dateforsignin, signin.dateforsignin) == 0 ? true : false); WorkerSignin result = q.FirstOrDefault(); // Assert Assert.IsNotNull(result.ID); Assert.AreEqual(result.WorkerID, worker.ID); Assert.AreEqual(result.dwccardnum, worker.dwccardnum); }
public void Create_WSI_without_worker_match_succeeds() { // //Arrange var _serv = new WorkerSigninService(_wsiRepo.Object, _wServ.Object, _iServ.Object, _wrServ.Object, _uow.Object, _map.Object, _cServ.Object); var _signin = new WorkerSignin { dwccardnum = 66666, dateforsignin = DateTime.Today }; WorkerSignin _cbsignin = new WorkerSignin(); _wsiRepo.Setup(s => s.Add(It.IsAny <WorkerSignin>())).Callback((WorkerSignin s) => { _cbsignin = s; }); // //Act _serv.CreateSignin(66666, DateTime.Today, "UnitTest"); // //Assert Assert.AreEqual(_signin, _cbsignin); }
private void unassignWorkerSigninOnly(int wsiid, string user) { // get workersignin WorkerSignin wsi = wsiRepo.GetById(wsiid); if (wsi == null) { throw new NullReferenceException("WSIID " + wsiid.ToString() + "returned a null Worker Signin record"); } // // Starting with WSI // 1. Does WSI.WAID point to anything? if (wsi.WorkAssignmentID == null) // No { return; //nothing to clear } // // 2. WSI.WAID points to something. Does something link back? if (matchWAWSI(null, wsi)) // yes { //Unassign both WorkAssignment wa = waRepo.GetById((int)wsi.WorkAssignmentID); unassignBoth(wa, wsi, user); return; } // // 3. If points to something, but something doesn't link back, // does something match it's link? //if (wsi.WorkAssignmentID == null) throw new MacheteIntegrityException("Unassign called on non-assigned WorkerSignin"); WorkAssignment linkedWA = waRepo.GetById((int)wsi.WorkAssignmentID); if (matchWAWSI(linkedWA, null)) { //Something matches its link. My link to something assumed bad. wsi.WorkAssignmentID = null; unitOfWork.SaveChanges(); return; } else { throw new MacheteIntegrityException("Unassign found chain of mislinked records, starting with WSIID " + wsi.ID.ToString()); } }