Пример #1
0
    // MARK: Flush

    public void doFlush(Objectives.FlushRequest request)
    {
        const int FLUSH_COST = 100;

        LocalMoneyWorker.Instance.Buy(FLUSH_COST, delegate(int amount)
        {
            var response = new Objectives.FlushResponse();
            if (amount >= 0)
            {
                //since we are flushing, we should reset progress dans status
                for (int obj = 0; obj < numberOfObjectives; obj++)
                {
                    ObjectivesWorker.Update(obj, fetchedSet, 0);
                    ObjectivesWorker.UpdateStatus(obj, fetchedSet, false);
                }

                response.objectives = ObjectivesWorker.Flush(numberOfObjectives);

                //since we flushed data we fetch objectives again
                var fetchRequest = new Objectives.FetchRequest();
                fetchRequest.numberOfObjectives = numberOfObjectives;
                fetchRequest.set = fetchedSet;
                doFetch(fetchRequest);
            }
            else //Flush failed
            {
                response.objectives = new Objectives.ObjectivesModel[] { };
            }
            this.presenter.presentFlush(response);
        });
    }
    public void test_givenDefaultParameters_whenFlushCalled_thenDifferentObjectivesListIsReturned()
    {
        var request = new Objectives.FlushRequest();

        sut.doFlush(request);

        Assert.IsTrue(spy.presentFlushCalled);
    }
Пример #3
0
    // MARK: Claim

    public void doClaim(Objectives.ClaimRequest request)
    {
        var response = new Objectives.ClaimResponse();

        //invalid index
        if (request.id >= this.fetchedObjectives.Length)
        {
            response.isRewardGranted = false;
            this.presenter.presentClaim(response);
            return;
        }
        //max step not reached
        if (this.fetchedObjectives[request.id].currentStep != this.fetchedObjectives[request.id].numberOfSteps)
        {
            response.isRewardGranted = false;
            this.presenter.presentClaim(response);
            return;
        }

        var reward = this.fetchedObjectives[request.id].reward;

        LocalMoneyWorker.Instance.Sell(reward, delegate(int amount) {
            //everything is fine, we can update claim status
            //fetchedObjectives[request.id].isRewardClaimed = true;
            ObjectivesWorker.UpdateStatus(request.id, fetchedSet, true);

            //since we flushed data we fetch objectives again
            var fetchRequest = new Objectives.FetchRequest();
            fetchRequest.numberOfObjectives = numberOfObjectives;
            fetchRequest.set = fetchedSet;
            doFetch(fetchRequest);

            //if all Game Objectives are complete and claimed, we should autoflush
            if (fetchedSet == Objectives.ObjectiveSet.Game)
            {
                bool shouldAutoFlush = true;
                foreach (var objective in fetchedObjectives)
                {
                    if (false == objective.isRewardClaimed)
                    {
                        shouldAutoFlush = false;
                    }
                }

                if (shouldAutoFlush)
                {
                    var flushRequest = new Objectives.FlushRequest();
                    doFlush(flushRequest);
                }
            }

            response.isRewardGranted = true;
            this.presenter.presentClaim(response);
        });
    }
    public void test_givenDefaultParameters_when_SCENARIO_1_ReadFlushUntilLoop_thenCorrectListObjectivesAreDisplayed()
    {
        var request       = new Objectives.FlushRequest();
        var numberOfItems = 3;

        buildFetchRequest(numberOfItems, Objectives.ObjectiveSet.Game);

        Assert.IsTrue(spy.presentFetchCalled);
        Assert.AreEqual(spy.lastFetchResponse.objectives.Length, numberOfItems);
        Assert.AreEqual(spy.lastFetchResponse.objectives[0].id, 0);
        Assert.AreEqual(spy.lastFetchResponse.objectives[1].id, 1);
        Assert.AreEqual(spy.lastFetchResponse.objectives[2].id, 2);

        sut.doFlush(request);

        Assert.AreEqual(spy.lastFlushResponse.objectives.Length, numberOfItems);
        Assert.AreEqual(spy.lastFlushResponse.objectives[0].id, 3);
        Assert.AreEqual(spy.lastFlushResponse.objectives[1].id, 4);
        Assert.AreEqual(spy.lastFlushResponse.objectives[2].id, 5);

        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);

        sut.doFlush(request);

        //here we reach an objective overflow, looping to root objectives ...
        Assert.AreEqual(spy.lastFlushResponse.objectives.Length, numberOfItems);
        Assert.AreEqual(spy.lastFlushResponse.objectives[0].id, 0);
        Assert.AreEqual(spy.lastFlushResponse.objectives[1].id, 1);
        Assert.AreEqual(spy.lastFlushResponse.objectives[2].id, 2);

        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);
    }
Пример #5
0
    // MARK: Flush

    public void flushObjectives()
    {
        var request = new Objectives.FlushRequest();

        interactor.doFlush(request);
    }