summaryrefslogtreecommitdiff
path: root/src/tests/efl_mono/Model.cs
blob: a43d9da51ca72f074763144385169acf99c90204 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#define CODE_ANALYSIS

using System;
using System.Threading.Tasks;
using System.Diagnostics.CodeAnalysis;

#if EFL_BETA

namespace TestSuite {

[SuppressMessage("Gendarme.Rules.Portability", "DoNotHardcodePathsRule")]
public class TestModel {

    public class VeggieViewModel
    {
        public string Name { get; set; }
        public string Type { get; set; }
        public string Image { get; set; }
    }

    private static Efl.UserModel<VeggieViewModel> CreateModel(Efl.Loop loop)
    {
        Efl.UserModel<VeggieViewModel> veggies = new Efl.UserModel<VeggieViewModel>(loop);
        veggies.Add (new VeggieViewModel{ Name="Tomato", Type="Fruit", Image="tomato.png"});
        veggies.Add (new VeggieViewModel{ Name="Romaine Lettuce", Type="Vegetable", Image="lettuce.png"});
        veggies.Add (new VeggieViewModel{ Name="Zucchini", Type="Vegetable", Image="zucchini.png"});

        return veggies;
    }

    public static void reflection_test ()
    {
        Efl.Loop loop = Efl.App.AppMain;

        var veggies = CreateModel(loop);
    }

    internal static async Task EasyModelExtractionAsync (Efl.Loop loop)
    {
        var veggies = CreateModel(loop);

        var model = new Efl.GenericModel<VeggieViewModel>(veggies, loop);
        Test.AssertEquals(3, (int)model.GetChildrenCount());

        VeggieViewModel r2 = await model.GetAtAsync(1);
        Test.AssertEquals(r2.Name, "Romaine Lettuce");

        VeggieViewModel r = await model.GetAtAsync(0);
        Test.AssertEquals(r.Name, "Tomato");

        loop.End();
    }

    public static void easy_model_extraction ()
    {
        Efl.Loop loop = Efl.App.AppMain;
        Task task = EasyModelExtractionAsync(loop);

        loop.Begin();

        task.Wait();
    }

    public static void factory_test ()
    {
        string propertyBound = null;
        bool callbackCalled = false;
        var factory = new Efl.Ui.ItemFactory<Efl.Ui.Button>();
        factory.PropertyBoundEvt += (object sender, Efl.Ui.IPropertyBindPropertyBoundEvt_Args args) => {
            propertyBound = args.arg;
            callbackCalled = true;
        };

        factory.Style().Bind("first name");

        Test.Assert(callbackCalled, "Property bound callback must have been called.");
        Test.AssertEquals(propertyBound, "style");
    }
}

}

#endif