public void Registering_a_valid_contract_should_succeed() { var contract = FluentContract .Create() .ApplyDefaults() .Save(this); var expectedResponse = new RegistrationAPIResponse(Guid.NewGuid()); var ruleProcessor = GetRuleProcessor(_ruleProcessorUrl, expectedResponse); var response = ruleProcessor.RegisterContractItem(contract); Assert.AreEqual(RegistrationAPIState.Registered, response.State); Assert.AreEqual(expectedResponse.RegistrationReference, response.RegistrationReference); var trackingReferences = PreliminaryContractRepository.GetAll <ContractTrackingReference>().ToList(); Assert.AreEqual(1, trackingReferences.Count); Assert.AreEqual(expectedResponse.RegistrationReference.ToString(), trackingReferences[0].ItemReference); Assert.AreEqual(ContractTrackingState.EvaluationPending, trackingReferences[0].State); Assert.AreNotEqual(0, trackingReferences[0].Id); Assert.AreNotEqual(default(DateTime), trackingReferences[0].CreatedAt); Assert.AreNotEqual(default(DateTime), trackingReferences[0].UpdatedAt); }
public void Process_action_response_should_return_success_and_update_the_action_tracking_reference_and_contract_tracking_reference_when_contract_tracking_reference_is_actions_complete_and_an_action_is_rejected() { var itemReference = Guid.NewGuid(); var contractReference = CreateContractTrackingReference(1, itemReference, ContractTrackingState.ActionsComplete, ContractStatus.Approved); var trackingReferences = CreateActionTrackingReferences(contractReference, ActionTrackingState.Approved); var processor = GetRuleResponseProcessor(); var nancyResponse = new ProcessActionNancyResponse() { ItemReference = Guid.Parse(trackingReferences[0].ItemReference), ActionKey = trackingReferences[0].ActionKey, ActionReference = Guid.Parse(trackingReferences[0].ActionReference), ActionState = ActionState.Rejected }; var apiResponse = processor.ProcessActionResponse(nancyResponse).Result; Assert.AreEqual(SuccessOrFailureAPIState.Success, apiResponse.State); var updatedActionReferences = PreliminaryContractRepository.GetAll <ActionTrackingReference>().ToList(); Assert.AreEqual(3, updatedActionReferences.Count); Assert.AreEqual(ActionTrackingState.Rejected, updatedActionReferences.Single(a => a.Id == trackingReferences[0].Id).State); Assert.AreEqual(ActionTrackingState.Approved, updatedActionReferences.Single(a => a.Id == trackingReferences[1].Id).State); Assert.AreEqual(ActionTrackingState.Approved, updatedActionReferences.Single(a => a.Id == trackingReferences[2].Id).State); contractReference = PreliminaryContractRepository.GetSingleOrDefaultWhere <ContractTrackingReference>(c => c.Id == contractReference.Id); Assert.AreEqual(ContractTrackingState.ActionsComplete, contractReference.State); var contract = PreliminaryContractRepository.GetSingleOrDefaultWhere <Contract>(c => c.Id == contractReference.ContractId); Assert.AreEqual(ContractStatus.Rejected, contract.ContractStatus); }
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); }