Exemplo n.º 1
0
    public void IsOtherSelectionPossibleCases()
    {
        var selection = new LabelSelectionViewModel(Money.Parse("0.5"));
        var pockets   = new List <Pocket>();

        var privatePocket     = LabelTestExtensions.CreateSingleCoinPocket(1.0m, CoinPocketHelper.PrivateFundsText, anonSet: 999);
        var semiPrivatePocket = LabelTestExtensions.CreateSingleCoinPocket(1.0m, CoinPocketHelper.SemiPrivateFundsText, anonSet: 2);

        pockets.Add(LabelTestExtensions.CreateSingleCoinPocket(1.0m, "Dan"));
        pockets.Add(LabelTestExtensions.CreateSingleCoinPocket(1.0m, "Dan, Lucas"));
        selection.Reset(pockets.ToArray());

        // Other pocket can be used case.
        var recipient = "Lucas";
        var output    = selection.AutoSelectPockets(recipient);

        Assert.True(selection.IsOtherSelectionPossible(output.SelectMany(x => x.Coins), recipient));

        // Exact match. Recipient == pocket, no better selection.
        recipient = "Dan";
        output    = selection.AutoSelectPockets(recipient);
        Assert.False(selection.IsOtherSelectionPossible(output.SelectMany(x => x.Coins), recipient));

        pockets.Add(privatePocket);
        selection.Reset(pockets.ToArray());

        // Private funds are enough for the payment, no better selection.
        recipient = "Doesn't matter, it will use private coins";
        output    = selection.AutoSelectPockets(recipient);
        Assert.False(selection.IsOtherSelectionPossible(output.SelectMany(x => x.Coins), recipient));

        pockets.Remove(privatePocket);
        pockets.Add(semiPrivatePocket);
        selection = new LabelSelectionViewModel(Money.Parse("0.5"));
        selection.Reset(pockets.ToArray());

        // Semi funds are enough for the payment, no better selection.
        recipient = "Doesn't matter, it will use semi private coins";
        output    = selection.AutoSelectPockets(recipient);
        Assert.False(selection.IsOtherSelectionPossible(output.SelectMany(x => x.Coins), recipient));

        pockets.Add(privatePocket);
        selection = new LabelSelectionViewModel(Money.Parse("1.5"));
        selection.Reset(pockets.ToArray());

        // Private and semi funds are enough for the payment, no better selection.
        recipient = "Doesn't matter, it will use semi private coins";
        output    = selection.AutoSelectPockets(recipient);
        Assert.False(selection.IsOtherSelectionPossible(output.SelectMany(x => x.Coins), recipient));
    }