public async Task Should_NotCreate_Employee_ForegignKey_JobPosition() { using var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled); try { //Act Guid identityWorkId = Guid.NewGuid(); Guid instanceId = Guid.NewGuid(); var employees = await new EmployeeManagerUT().CreateDefaultAsync <Employee>(identityWorkId, instanceId, randomValues: true); employees.FirstOrDefault().JobPositionID = Guid.NewGuid(); employees.FirstOrDefault().Code = "7"; employees.FirstOrDefault().Name = "Nombre"; employees.FirstOrDefault().NSS = "833541869"; employees.FirstOrDefault().CURP = "AASDASDBASDATY"; employees.FirstOrDefault().RFC = "CCC020202CCC"; var middlewareManager = new MiddlewareManager <Employee>(new BaseRecordManager <Employee>(), new EmployeeValidator()); middlewareManager.Create(employees, identityWorkId); Assert.False(true, "No se permite posiciĆ³n no existe"); } catch (Exception ex) { Assert.True(ex is CotorraException); Assert.True((ex as CotorraException).ErrorCode.Equals(4009)); } }
public async Task Should_NotCreate_Employee_Duplicate_CURP() { using var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled); try { //Act Guid identityWorkId = Guid.NewGuid(); Guid instanceId = Guid.NewGuid(); var employees = await new EmployeeManagerUT().CreateDefaultAsync <Employee>(identityWorkId, instanceId, curp: "BBSDASDBASDASR", randomValues: true); //Modify ToDuplicate employees.FirstOrDefault().ID = Guid.NewGuid(); employees.FirstOrDefault().RFC = "CCC010101CCC"; employees.FirstOrDefault().NSS = "084521754"; employees.FirstOrDefault().Code = "2"; employees.FirstOrDefault().Name = "Oscar"; var middlewareManager = new MiddlewareManager <Employee>(new BaseRecordManager <Employee>(), new EmployeeValidator()); middlewareManager.Create(employees, identityWorkId); Assert.False(true, "No se permite CURP duplicado"); } catch (Exception ex) { Assert.True(ex is CotorraException); Assert.True((ex as CotorraException).ErrorCode.Equals(4007)); } }
public async Task Should_NotCreate_Employee_Duplicate_NSS() { using var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled); try { //Act Guid identityWorkId = Guid.NewGuid(); Guid instanceId = Guid.NewGuid(); var employees = await new EmployeeManagerUT().CreateDefaultAsync <Employee>(identityWorkId, instanceId, nss: "833531877", randomValues: false); //Modify ToDuplicate employees.FirstOrDefault().ID = Guid.NewGuid(); employees.FirstOrDefault().RFC = "CCC010201CAB"; employees.FirstOrDefault().Code = "2025"; employees.FirstOrDefault().CURP = "asdasdas2"; employees.FirstOrDefault().Name = "Oscar23"; var middlewareManager = new MiddlewareManager <Employee>(new BaseRecordManager <Employee>(), new EmployeeValidator()); middlewareManager.Create(employees, identityWorkId); Assert.False(true, "No se permite NSS duplicado"); } catch (Exception ex) { Assert.True(ex is CotorraException); Assert.True((ex as CotorraException).ErrorCode.Equals(4006)); } }
public async Task <List <T> > CreateDefaultAsync <T>(Guid identityWorkId, Guid instanceId) where T : BaseEntity { var nOMSurveyReplyResult = (await new NOMSurveyReplyManagerUT().CreateDefaultAsync <NOMSurveyReplyResult>(identityWorkId, instanceId)).FirstOrDefault(); var NOMAnswers = BuildAnswers(identityWorkId, instanceId, nOMSurveyReplyResult.NOMSurveyReply.ID); var middlewareManager = new MiddlewareManager <NOMAnswer>(new BaseRecordManager <NOMAnswer>(), new NOMAnswerValidator()); middlewareManager.Create(NOMAnswers, identityWorkId); return(NOMAnswers as List <T>); }
public async Task <List <T> > CreateDefaultAsync <T>(Guid identityWorkId, Guid instanceId) where T : class { //EvaluationPeriod var nomEvaluationPeriod = new NOMEvaluationPeriod() { ID = Guid.NewGuid(), Active = true, Timestamp = DateTime.UtcNow, Description = "Soy una surveyreply", CreationDate = DateTime.Now, company = identityWorkId, user = Guid.NewGuid(), InstanceID = instanceId, Name = "g1", StatusID = 1, InitialDate = DateTime.Now, FinalDate = DateTime.Now.AddDays(1), Period = "2019", State = true, }; var lstNomEvaluationPeriods = new List <NOMEvaluationPeriod>(); lstNomEvaluationPeriods.Add(nomEvaluationPeriod); var middlewareManagerEvaluationPeriod = new MiddlewareManager <NOMEvaluationPeriod>(new BaseRecordManager <NOMEvaluationPeriod>(), new NOMEvaluationPeriodValidator()); middlewareManagerEvaluationPeriod.Create(lstNomEvaluationPeriods, identityWorkId); //Employee var lstEmployees = await new EmployeeManagerUT().CreateDefaultAsync <Employee>(identityWorkId, instanceId, randomValues: true); var nomSurveyReply = new NOMSurveyReplyParams() { EmployeeId = lstEmployees.FirstOrDefault().ID, NOMEvaluationPeriodId = nomEvaluationPeriod.ID, NOMEvaluationSurveyId = Guid.Parse("612A7938-1D11-4400-8BB7-AD29191AC33C"), IdentityWorkId = identityWorkId, InstanceId = instanceId }; var manager = new NOMSurveyManager(); var res = await manager.CreateAsync(nomSurveyReply); return(new List <T>() { res as T }); }
public void AfterCreate(List <Period> lstObjectsToValidate) { var lstPeriodDetails = new List <PeriodDetail>(); var company = lstObjectsToValidate.FirstOrDefault().company; var user = lstObjectsToValidate.FirstOrDefault().user; var instance = lstObjectsToValidate.FirstOrDefault().InstanceID; lstObjectsToValidate.ForEach(p => { if (!p.ExtraordinaryPeriod) { lstPeriodDetails.AddRange(CreatePeriodDetailsByPeriodType(p, company, instance, user)); } }); var middlewareManager = new MiddlewareManager <PeriodDetail>(new BaseRecordManager <PeriodDetail>(), new PeriodDetailValidator()); middlewareManager.Create(lstPeriodDetails, company); }