public void Process_item_reponse_should_return_success_and_not_populate_action_tracking_references_for_an_item_reponse_with_no_triggered_actions() { var itemReference = Guid.NewGuid(); var contractReference = CreateContractTrackingReference(1, itemReference); var processor = GetRuleResponseProcessor(); var nancyResponse = new ProcessItemNancyResponse() { Item = new ItemRegistration { ItemReference = itemReference }, TriggeredActions = new List <TriggeredAction>(), State = SuccessOrFailureAPIState.Success }; var apiResponse = processor.ProcessItemResponse(nancyResponse).Result; Assert.AreEqual(SuccessOrFailureAPIState.Success, apiResponse.State); var actionReferences = PreliminaryContractRepository.GetAll <ActionTrackingReference>().ToList(); Assert.AreEqual(0, actionReferences.Count); contractReference = PreliminaryContractRepository.GetSingleOrDefaultWhere <ContractTrackingReference>(c => c.Id == contractReference.Id); Assert.AreEqual(ContractTrackingState.NoActions, contractReference.State); var contract = PreliminaryContractRepository.GetSingleOrDefaultWhere <Contract>(c => c.Id == contractReference.ContractId); Assert.AreEqual(ContractStatus.Approved, contract.ContractStatus); }
public void Process_item_reponse_should_return_success_and_populate_action_tracking_references_for_an_item_reponse_with_triggered_actions() { var itemReference = Guid.NewGuid(); var contractReference = CreateContractTrackingReference(1, itemReference); var processor = GetRuleResponseProcessor(); var actionKey1 = ActionKeyHelpers.BuildKey(itemReference, 1, 10); var actionRef1 = Guid.NewGuid(); var actionKey2 = ActionKeyHelpers.BuildKey(itemReference, 2, 20); var actionRef2 = Guid.NewGuid(); var actionKey3 = ActionKeyHelpers.BuildKey(itemReference, 3, 30); var actionRef3 = Guid.NewGuid(); var nancyResponse = new ProcessItemNancyResponse() { Item = new ItemRegistration { ItemReference = itemReference }, TriggeredActions = new List <TriggeredAction>() { new TriggeredAction() { ItemReference = itemReference, ActionKey = actionKey1, ActionReference = actionRef1, ActionState = ActionState.InProgress }, new TriggeredAction() { ItemReference = itemReference, ActionKey = actionKey2, ActionReference = actionRef2, ActionState = ActionState.InProgress }, new TriggeredAction() { ItemReference = itemReference, ActionKey = actionKey3, ActionReference = actionRef3, ActionState = ActionState.InProgress }, }, State = SuccessOrFailureAPIState.Success }; var apiResponse = processor.ProcessItemResponse(nancyResponse).Result; Assert.AreEqual(SuccessOrFailureAPIState.Success, apiResponse.State); var actionReferences = PreliminaryContractRepository.GetAll <ActionTrackingReference>().ToList(); Assert.AreEqual(3, actionReferences.Count); Assert.IsTrue(actionReferences.Exists(a => a.ActionKey == actionKey1.ToString())); Assert.IsTrue(actionReferences.Exists(a => a.ActionReference == actionRef1.ToString())); Assert.IsTrue(actionReferences.Exists(a => a.ActionKey == actionKey2.ToString())); Assert.IsTrue(actionReferences.Exists(a => a.ActionReference == actionRef2.ToString())); Assert.IsTrue(actionReferences.Exists(a => a.ActionKey == actionKey3.ToString())); Assert.IsTrue(actionReferences.Exists(a => a.ActionReference == actionRef3.ToString())); contractReference = PreliminaryContractRepository.GetSingleOrDefaultWhere <ContractTrackingReference>(c => c.Id == contractReference.Id); Assert.AreEqual(ContractTrackingState.ActionsPending, contractReference.State); var contract = PreliminaryContractRepository.GetSingleOrDefaultWhere <Contract>(c => c.Id == contractReference.ContractId); Assert.AreEqual(ContractStatus.InFlight, contract.ContractStatus); }