public async Task <NOMSurveyReplyResult> UpdateSurveyAsync(NOMSurveyReply reply, Guid identityWorkId) { var middlewareManager = new MiddlewareManager <NOMSurveyReply>(new BaseRecordManager <NOMSurveyReply>(), new NOMSurveyReplyValidator()); await middlewareManager.UpdateAsync(new List <NOMSurveyReply>() { reply }, identityWorkId); return(new NOMSurveyReplyResult()); }
public async Task SalaryAdjustment_Fail_PeriodClosed() { using var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled); Guid identityWorkId = Guid.NewGuid(); Guid instanceID = Guid.NewGuid(); try { var employee = await new EmployeeManagerUT().CreateDefaultAsync <Employee>( identityWorkId, instanceID); var middlewareManagerPeriodDetail = new MiddlewareManager <PeriodDetail>(new BaseRecordManager <PeriodDetail>(), new PeriodDetailValidator()); var periodDetails = await middlewareManagerPeriodDetail.FindByExpressionAsync(p => p.InstanceID == instanceID, identityWorkId); var CotorriaPeriodDetail = periodDetails.FirstOrDefault(); CotorriaPeriodDetail.PeriodStatus = PeriodStatus.Authorized; await middlewareManagerPeriodDetail.UpdateAsync(new List <PeriodDetail> { CotorriaPeriodDetail }, identityWorkId); Guid sbcID = Guid.NewGuid(); var creationDate = DateTime.Now; EmployeeSBCAdjustment sbc = BuildEmployeeSBCAdjustment(sbcID, Guid.NewGuid(), identityWorkId, instanceID, creationDate, employee.FirstOrDefault().ID, 123.23M, 123.23M, 123.23M); EmployeeSalaryIncrease employeeSalaryIncrease = new EmployeeSalaryIncrease() { Active = true, company = identityWorkId, CreationDate = creationDate, DailySalary = 145.65M, DeleteDate = null, Description = "", EmployeeID = employee.FirstOrDefault().ID, ID = Guid.NewGuid(), user = Guid.NewGuid(), InstanceID = instanceID, ModificationDate = periodDetails.OrderBy(p => p.InitialDate).FirstOrDefault().InitialDate.AddDays(2), Name = "", StatusID = 1, Timestamp = DateTime.Now, EmployeeSBCAdjustment = sbc, EmployeeSBCAdjustmentID = sbc.ID }; var middlewareManager = new MiddlewareManager <EmployeeSalaryIncrease>(new BaseRecordManager <EmployeeSalaryIncrease>()); await middlewareManager.CreateAsync(new List <EmployeeSalaryIncrease>() { employeeSalaryIncrease }, identityWorkId); Assert.True(true, "No debió de pasar"); } catch (CotorraException ex) { Assert.True(ex.Code == "4005"); } catch { Assert.True(true, "No debió de pasar"); } }
public async Task <Employee> UpdateEmployeeDailySalary(Employee employee, decimal amount, Guid identityWorkId) { employee.DailySalary = amount; var middlewareManager = new MiddlewareManager <Employee>(new BaseRecordManager <Employee>(), new EmployeeValidator()); await middlewareManager.UpdateAsync(new List <Employee> { employee }, identityWorkId); return(employee); }
public async Task <HistoricEmployeeSalaryAdjustment> UpdateModificationDateAsync(Guid employeeID, DateTime modifiedDate, Guid identityWorkID) { var middlewareHistoricAdjustmentManager = new MiddlewareManager <HistoricEmployeeSalaryAdjustment> (new BaseRecordManager <HistoricEmployeeSalaryAdjustment>(), new HistoricEmployeeSalaryAdjustmentValidator()); var historics = await middlewareHistoricAdjustmentManager.FindByExpressionAsync(p => p.EmployeeID == employeeID, identityWorkID); historics.FirstOrDefault().ModificationDate = modifiedDate; await middlewareHistoricAdjustmentManager.UpdateAsync(historics, identityWorkID); return(historics.FirstOrDefault()); }
public async Task Authorization_Should_Authorize() { using var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled); var identityWorkId = Guid.NewGuid(); var instanceID = Guid.NewGuid(); var employee = await new EmployeeManagerUT().CreateDefaultAsync <Employee>(identityWorkId, instanceID); var middlewareManager = new MiddlewareManager <OverdraftDetail>(new BaseRecordManager <OverdraftDetail>(), new OverdraftDetailValidator()); var overdraftDetails = await middlewareManager.FindByExpressionAsync(p => p.InstanceID == instanceID && p.ConceptPayment.Name == "Sueldo", identityWorkId, new string[] { "Overdraft" }); var randomValue = new Random(15000); for (int i = 0; i < overdraftDetails.Count; i++) { overdraftDetails[i].Amount = Convert.ToDecimal(randomValue.NextDouble()); overdraftDetails[i].Taxed = Convert.ToDecimal(randomValue.NextDouble()); overdraftDetails[i].Exempt = Convert.ToDecimal(randomValue.NextDouble()); overdraftDetails[i].IMSSTaxed = Convert.ToDecimal(randomValue.NextDouble()); overdraftDetails[i].IMSSExempt = Convert.ToDecimal(randomValue.NextDouble()); } var middlewareDetailManager = new MiddlewareManager <OverdraftDetail>(new BaseRecordManager <OverdraftDetail>(), new OverdraftDetailValidator()); await middlewareDetailManager.UpdateAsync(overdraftDetails, identityWorkId); var authManager = new AuthorizationManager(); var authParams = new AuthorizationParams() { IdentityWorkID = identityWorkId, InstanceID = instanceID, PeriodDetailIDToAuthorize = overdraftDetails.FirstOrDefault().Overdraft.PeriodDetailID }; await authManager.AuthorizationAsync(authParams); var middlewareHistoricAccumulatedEmployeeManager = new MiddlewareManager <HistoricAccumulatedEmployee>(new BaseRecordManager <HistoricAccumulatedEmployee>(), new HistoricAccumulatedEmployeeValidator()); //Total de acumulados por empleado var resultHistoric = await middlewareHistoricAccumulatedEmployeeManager.GetAllAsync(identityWorkId, instanceID, new string[] { "AccumulatedType" }); Assert.True(resultHistoric.Count == 33); //Overdraft after authorization var overdraftDetailsAfter = await middlewareManager.FindByExpressionAsync(p => p.Overdraft.EmployeeID == employee.FirstOrDefault().ID, identityWorkId, new string[] { "Overdraft" }); Assert.True(overdraftDetailsAfter.FirstOrDefault().Overdraft.PeriodDetailID != overdraftDetails.FirstOrDefault().Overdraft.PeriodDetailID); }
public async Task Should_Fail_When_Payment_Periodicity_Is_BadValue() { using var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled); //Arrange var periodTypes = new List <PeriodType>(); var identityWorkId = Guid.NewGuid(); var id = Guid.NewGuid(); var originalName = "some"; var periodType = PeriodTypeBuilder.Build(id, identityWorkId, originalName); periodTypes.Add(periodType); var middlewareManager = new MiddlewareManager <PeriodType>(new BaseRecordManager <PeriodType>(), new PeriodTypeValidator()); await middlewareManager.CreateAsync(periodTypes, identityWorkId); var found = await middlewareManager.GetByIdsAsync(new List <Guid>() { id }, identityWorkId); Assert.True(found.Any()); var register = found.FirstOrDefault(x => x.ID == id); Assert.NotNull(register); Assert.Equal(register.Name, originalName); register.PaymentPeriodicity = (PaymentPeriodicity)11; try { await middlewareManager.UpdateAsync(new List <PeriodType>() { register }, identityWorkId); } catch (CotorraException ex) { //Assert var res = ex.ValidationInfo; Assert.NotEmpty(res); Assert.Equal(9003, ex.ErrorCode); } finally { await middlewareManager.DeleteAsync(new List <Guid>() { id }, identityWorkId); } }
public async Task <AreaDTO> Put(Guid instanceID, Guid userID, Guid identityWorkID, AreaValidator validator, IMapper mapper, AreaDTO AreaDTO) { var mgr = new MiddlewareManager <Area>(new BaseRecordManager <Area>(), validator); var found = (await mgr.FindByExpressionAsync(x => x.ID == AreaDTO.ID, identityWorkID)).FirstOrDefault(); if (found != null) { found.Name = AreaDTO.Name; await mgr.UpdateAsync(new List <Area>() { found }, identityWorkID); } else { return(await Post(instanceID, userID, identityWorkID, validator, mapper, AreaDTO)); } return(AreaDTO); }
public async Task Should_Create_Biweekly_UpdatePeriodDetail_Fail_FuturePeriodDetails_All() { using var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled); try { //Arrange var identityWorkId = Guid.NewGuid(); var instanceId = Guid.NewGuid(); //Act var initialDate = new DateTime(DateTime.Now.Year, 1, 1); var finalDate = new DateTime(DateTime.Now.Year, 12, 31); var paymentPeriodicity = PaymentPeriodicity.Biweekly; var period = await CreateDefaultAsync <Period>(identityWorkId, instanceId, initialDate, finalDate, paymentPeriodicity); //Assert var middlewareManager = new MiddlewareManager <Period>(new BaseRecordManager <Period>(), new PeriodValidator()); var found = await middlewareManager.GetByIdsAsync(new List <Guid>() { period.FirstOrDefault().ID }, identityWorkId, new string[] { "PeriodDetails" }); Assert.True(found.Any()); var periodDetails = found.SelectMany(p => p.PeriodDetails).OrderBy(p => p.Number); Assert.True(periodDetails.Any()); Assert.True(found.SelectMany(p => p.PeriodDetails).Count() == 24); var middlewareManagerPeriodDetails = new MiddlewareManager <PeriodDetail>(new BaseRecordManager <PeriodDetail>(), new PeriodDetailValidator()); //Update var finalDateToUpdate = periodDetails.FirstOrDefault(p => p.Number == 1).FinalDate; periodDetails.FirstOrDefault(p => p.Number == 2).InitialDate = finalDateToUpdate; await middlewareManagerPeriodDetails.UpdateAsync(periodDetails.ToList(), identityWorkId); Assert.True(false, "Se espera que no se pueda actualizar"); } catch (Exception ex) { Assert.True(ex is CotorraException); Assert.True((ex as CotorraException).ErrorCode.Equals(8008)); } }
public async Task Should_Create_NOMAnswer_And_Get_Update_Validate_Finally_do_DeleteAsync() { using var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled); //Arrange var identityWorkId = Guid.NewGuid(); var instanceId = Guid.NewGuid(); var NOMAnswers = await new NOMAnswerManagerUT().CreateDefaultAsync <NOMAnswer>(identityWorkId, instanceId); //Act var middlewareManager = new MiddlewareManager <NOMAnswer>(new BaseRecordManager <NOMAnswer>(), new NOMAnswerValidator()); //Get var result = middlewareManager .GetByIds(NOMAnswers.Select(p => p.ID).ToList(), identityWorkId); Assert.True(result.Count() > 0); result.FirstOrDefault().Value = 2; await middlewareManager.UpdateAsync(result, identityWorkId); result = middlewareManager.GetByIds(NOMAnswers.Select(p => p.ID).ToList(), identityWorkId); //Assert Assert.True(result.Count() > 0); Assert.Equal(2, result.FirstOrDefault().Value); //Delete middlewareManager.Delete(NOMAnswers.Select(p => p.ID).ToList(), identityWorkId); Assert.True(result.FirstOrDefault().ID == NOMAnswers.FirstOrDefault().ID); //Get it again to verify if the registry it was deleted var result2 = middlewareManager .GetByIds(NOMAnswers.Select(p => p.ID).ToList(), identityWorkId); Assert.True(result2.Count() == 0); }
public async Task Should_Update_Employee_And_Get_ToValidate_Finally_do_Delete() { var txOptions = new System.Transactions.TransactionOptions(); txOptions.IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted; using var scope = new TransactionScope(TransactionScopeOption.Required, txOptions, TransactionScopeAsyncFlowOption.Enabled); //Act Guid identityWorkId = Guid.NewGuid(); //Guid.Parse("7535C4E6-4712-4DD6-955D-FCA86E054D49"); Guid instanceId = Guid.NewGuid(); //Guid.Parse("33D7CA50-39E9-4B14-B482-5FCBEC07E8DB"); var employees = await new EmployeeManagerUT().CreateDefaultAsync <Employee>(identityWorkId, instanceId, randomValues: true); var middlewareManager = new MiddlewareManager <Employee>(new BaseRecordManager <Employee>(), new EmployeeValidator()); //Asserts //Get var result = await middlewareManager .GetByIdsAsync(employees.Select(p => p.ID).ToList(), identityWorkId); Assert.True(result.Any()); var middlewareManagerOverdraft = new MiddlewareManager <Overdraft>(new BaseRecordManager <Overdraft>(), new OverdraftValidator()); var resultOverdraft = await middlewareManagerOverdraft.FindByExpressionAsync(p => p.InstanceID == instanceId && p.EmployeeID == employees.FirstOrDefault().ID, identityWorkId); Assert.True(resultOverdraft.Any()); var employeeId = employees.FirstOrDefault().ID; var newAmount = employees.FirstOrDefault().DailySalary; employees.FirstOrDefault().DailySalary = 5478; await middlewareManager.UpdateAsync(employees, identityWorkId); var middlewareHistoricEmployeeSalaryAdjustmentManager = new MiddlewareManager <HistoricEmployeeSalaryAdjustment>(new BaseRecordManager <HistoricEmployeeSalaryAdjustment>(), new HistoricEmployeeSalaryAdjustmentValidator()); var historicEmployee = await middlewareHistoricEmployeeSalaryAdjustmentManager.FindByExpressionAsync(p => p.EmployeeID == employeeId, identityWorkId);; Assert.True(historicEmployee.FirstOrDefault().DailySalary == newAmount); }
public async Task UpdateAsync(List <T> lstObjects, Guid identityWorkId) { var middlewareManager = new MiddlewareManager <T>(new BaseRecordManager <T>(), Validator); await middlewareManager.UpdateAsync(lstObjects, identityWorkId); }