public async Task CreateVersion_Stages_Reopen(string testCase, string strCostAction, string shouldClearExchangeRateDate) { // Arrange var costHasExchangeRateDate = string.IsNullOrWhiteSpace(shouldClearExchangeRateDate) ? true : false; var cost = await SetupCostStageData(testCase); CostAction action = (CostAction)Enum.Parse(typeof(CostAction), strCostAction); var newRevision = new CostStageRevision { Name = cost.LatestCostStageRevision.Name }; _costStageRevisionServiceMock.Setup(crs => crs.CreateVersion(It.IsAny <CostStageRevision>(), It.IsAny <Guid>(), It.IsAny <BuType>(), action)) .ReturnsAsync(newRevision); CostStatusServiceMock.Setup(b => b.UpdateCostStatus(It.IsAny <BuType>(), cost.Id, action)) .ReturnsAsync(new OperationResponse { }); CostApprovalServiceMock.Setup(b => b.UpdateApprovals(It.IsAny <Guid>(), User.Id, It.IsAny <BuType>())) .Returns(Task.FromResult(default(object))); _activityLogServiceMock.Setup(b => b.Log(It.IsAny <CostReopened>())) .Returns(Task.FromResult(default(object))); // Act var response = await CostActionService.CreateVersion(cost.Id, User, action); // Assert var updatedCost = await _eFContext.Cost.FindAsync(cost.Id); updatedCost.ExchangeRateDate.HasValue.Should().Be(costHasExchangeRateDate); updatedCost.ExchangeRate.HasValue.Should().Be(costHasExchangeRateDate); }
protected Task <BrowserResponse> ExecuteAction(Guid costId, CostAction action, CostUser user) { var url = $"{CostWorkflowUrl(costId)}/actions"; return(Browser.Post(url, w => { w.User(user); w.JsonBody(new ExecuteActionModel { Action = action }); })); }
protected async Task ExecuteActionAndValidateResponse(Guid costId, CostAction action, CostUser user) { var url = $"{CostWorkflowUrl(costId)}/actions"; var browserResponse = await Browser.Post(url, w => { w.User(user); w.JsonBody(new ExecuteActionModel { Action = action }); }); Deserialize <object>(browserResponse, HttpStatusCode.OK); }
public async Task <CostStageRevisionStatus> GetNextStatus(Guid costId, CostAction action) { var cost = await _efContext.Cost .Include(c => c.LatestCostStageRevision) .ThenInclude(csr => csr.Approvals) .ThenInclude(a => a.ApprovalMembers) .Include(c => c.Project) .Include(c => c.Parent) .ThenInclude(p => p.Agency) .FirstOrDefaultAsync(c => c.Id == costId); _logger.Information($"Working out next status for the cost {cost.CostNumber} {cost.Id}. Current status: {cost.Status} Action: {action}"); var stageDetails = await _costStageRevisionService.GetStageDetails <PgStageDetailsForm>(cost.LatestCostStageRevision.Id); var rules = await _ruleService.GetCompiledByRuleType <PgStatusRule>(RuleType.Status); var testRule = new PgStatusRule { Status = cost.LatestCostStageRevision.Status.ToString(), BudgetRegion = stageDetails.BudgetRegion?.Key, Action = action.ToString(), CostType = cost.CostType.ToString(), IsCyclone = cost.Parent.Agency.IsCyclone(), HasTechnicalApproval = cost.LatestCostStageRevision.Approvals.Any(a => a.Type == ApprovalType.IPM), HasBrandApproval = cost.LatestCostStageRevision.Approvals.Any(a => a.Type == ApprovalType.Brand), CostStage = cost.LatestCostStageRevision.Name }; if (_ruleService.TryMatchRule(rules, testRule, (r, dr) => JsonConvert.DeserializeObject <PgStatusRuleDefinition>(dr.Definition).Status, out var status)) { _logger.Information($"Next cost status for cost {cost.CostNumber} is {status}. Previous status {cost.Status}"); return(status); } throw new Exception($"Couldn't find status transition for cost {cost.CostNumber} rule: {JsonConvert.SerializeObject(testRule)}"); }