// MARK: Step public void step(int id) { Debug.Log("Stepping objective " + id); var request = new Objectives.StepRequest(); request.id = id; interactor.doStep(request); }
public void test_givenDefaultParameters_whenStepCalled_thenObjectiveIsUpdated() { buildFetchRequest(3, Objectives.ObjectiveSet.Game); var request = new Objectives.StepRequest(); request.id = 0; sut.doStep(request); Assert.IsTrue(spy.presentStepCalled); }
public void test_givenDefaultParameters_when_SCENARIO_3_ReadStepUntilMaxStepClaim_thenAllObjectiveSetIsFlushed() { var request = new Objectives.StepRequest(); var numberOfItems = 3; //READ buildFetchRequest(numberOfItems, Objectives.ObjectiveSet.Game); Assert.AreEqual(spy.lastFetchResponse.objectives[0].id, 0); Assert.AreEqual(spy.lastFetchResponse.objectives[1].id, 1); Assert.AreEqual(spy.lastFetchResponse.objectives[2].id, 2); //STEP ALL TO MAX for (int index = 0; index < numberOfItems; index++) { request.id = index; sut.doStep(request); int MAX = spy.lastStepResponse.objective.numberOfSteps; Assert.AreEqual(Mathf.Min(1, MAX), spy.lastStepResponse.objective.currentStep); for (int i = 2; i < MAX + 5; i++) { sut.doStep(request); Assert.AreEqual(Mathf.Min(i, MAX), spy.lastStepResponse.objective.currentStep); } Assert.IsTrue(spy.presentStepCalled); Assert.IsTrue(spy.lastStepResponse.objective.numberOfSteps == spy.lastStepResponse.objective.currentStep); } //CLAIM ALL SHOULD TRIGGER FLUSH FOR GAME var claimRequest = new Objectives.ClaimRequest(); for (int index = 0; index < numberOfItems; index++) { claimRequest.id = index; sut.doClaim(claimRequest); Assert.IsTrue(spy.lastClaimResponse.isRewardGranted); } Assert.IsTrue(spy.presentFlushCalled); //READ 2 buildFetchRequest(numberOfItems, Objectives.ObjectiveSet.Game); Assert.AreEqual(spy.lastFetchResponse.objectives[0].id, 3); Assert.AreEqual(spy.lastFetchResponse.objectives[1].id, 4); Assert.AreEqual(spy.lastFetchResponse.objectives[2].id, 5); }
// MARK: Step public void doStep(Objectives.StepRequest request) { var response = new Objectives.StepResponse(); if (fetchedObjectives[request.id].currentStep < fetchedObjectives[request.id].numberOfSteps) { fetchedObjectives[request.id].currentStep = fetchedObjectives[request.id].currentStep + 1; } ObjectivesWorker.Update(request.id, fetchedSet, fetchedObjectives[request.id].currentStep); response.objective = fetchedObjectives[request.id]; //since we stepped data we fetch objectives again var fetchRequest = new Objectives.FetchRequest(); fetchRequest.numberOfObjectives = numberOfObjectives; fetchRequest.set = fetchedSet; doFetch(fetchRequest); presenter.presentStep(response); }
public void test_givenDefaultParameters_when_SCENARIO_2_ReadStepUntilMaxStep_thenAllObjectivesProgressesAreFull() { var request = new Objectives.StepRequest(); var numberOfItems = 3; //READ buildFetchRequest(numberOfItems, Objectives.ObjectiveSet.Game); Assert.AreEqual(spy.lastFetchResponse.objectives[0].id, 0); Assert.AreEqual(spy.lastFetchResponse.objectives[1].id, 1); Assert.AreEqual(spy.lastFetchResponse.objectives[2].id, 2); //STEP 0 request.id = 0; sut.doStep(request); //we should prevent stepping as we already reached max value int MAX = spy.lastStepResponse.objective.numberOfSteps; Assert.AreEqual(Mathf.Min(1, MAX), spy.lastStepResponse.objective.currentStep); sut.doStep(request); Assert.AreEqual(Mathf.Min(2, MAX), spy.lastStepResponse.objective.currentStep); sut.doStep(request); Assert.AreEqual(Mathf.Min(3, MAX), spy.lastStepResponse.objective.currentStep); sut.doStep(request); Assert.AreEqual(Mathf.Min(4, MAX), spy.lastStepResponse.objective.currentStep); sut.doStep(request); Assert.AreEqual(Mathf.Min(5, MAX), spy.lastStepResponse.objective.currentStep); Assert.IsTrue(spy.presentStepCalled); //READ //indexes are not flushed buildFetchRequest(numberOfItems, Objectives.ObjectiveSet.Game); Assert.AreEqual(spy.lastFetchResponse.objectives[0].id, 0); Assert.AreEqual(spy.lastFetchResponse.objectives[1].id, 1); Assert.AreEqual(spy.lastFetchResponse.objectives[2].id, 2); //STEP 1 request.id = 1; sut.doStep(request); //we should prevent stepping as we already reached max value MAX = spy.lastStepResponse.objective.numberOfSteps; Assert.AreEqual(Mathf.Min(1, MAX), spy.lastStepResponse.objective.currentStep); sut.doStep(request); Assert.AreEqual(Mathf.Min(2, MAX), spy.lastStepResponse.objective.currentStep); sut.doStep(request); Assert.AreEqual(Mathf.Min(3, MAX), spy.lastStepResponse.objective.currentStep); sut.doStep(request); Assert.AreEqual(Mathf.Min(4, MAX), spy.lastStepResponse.objective.currentStep); sut.doStep(request); Assert.AreEqual(Mathf.Min(5, MAX), spy.lastStepResponse.objective.currentStep); Assert.IsTrue(spy.presentStepCalled); //STEP 2 request.id = 2; sut.doStep(request); //we should prevent stepping as we already reached max value MAX = spy.lastStepResponse.objective.numberOfSteps; Assert.AreEqual(Mathf.Min(1, MAX), spy.lastStepResponse.objective.currentStep); sut.doStep(request); Assert.AreEqual(Mathf.Min(2, MAX), spy.lastStepResponse.objective.currentStep); sut.doStep(request); Assert.AreEqual(Mathf.Min(3, MAX), spy.lastStepResponse.objective.currentStep); sut.doStep(request); Assert.AreEqual(Mathf.Min(4, MAX), spy.lastStepResponse.objective.currentStep); sut.doStep(request); Assert.AreEqual(Mathf.Min(5, MAX), spy.lastStepResponse.objective.currentStep); Assert.IsTrue(spy.presentStepCalled); //READ buildFetchRequest(numberOfItems, Objectives.ObjectiveSet.Game); Assert.AreEqual(spy.lastFetchResponse.objectives[0].id, 0); Assert.AreEqual(spy.lastFetchResponse.objectives[1].id, 1); Assert.AreEqual(spy.lastFetchResponse.objectives[2].id, 2); }