Beispiel #1
0
    public void FromDoc_CalledWhenReifyingEmptyList()
    {
        List <TestClass> lst = new List <TestClass>();
        var doc = Config.LoadDocFromString("[[\"Base\", 451]]", c_filename);

        ConfigReifier.Reify(ref lst, doc);
        Assert.AreEqual(1, lst.Count);
        Assert.AreEqual(lst[0].baseKey, 451);
    }
Beispiel #2
0
    public void FromDoc_CalledWhenReifyingNullClass()
    {
        TestClass tc  = null;
        var       doc = Config.LoadDocFromString("[\"Base\", 451]", c_filename);

        ConfigReifier.Reify(ref tc, doc);
        Assert.IsNotNull(tc);
        Assert.AreEqual(tc.baseKey, 451);
    }
Beispiel #3
0
    public void PostDoc_CanReplaceWithReturnValue()
    {
        var           doc = Config.LoadDocFromString("baseKey: 10", c_filename);
        PostDocClass3 tc  = null;

        ConfigReifier.Reify(ref tc, doc);
        Assert.NotNull(tc);
        Assert.AreEqual(tc.baseKey, 99);
    }
Beispiel #4
0
    public void PostDoc_DoesntExist()
    {
        var           doc = Config.LoadDocFromString("baseKey: 10", c_filename);
        PostDocClass2 tc  = null;

        ConfigReifier.Reify(ref tc, doc);
        Assert.NotNull(tc);
        Assert.AreEqual(tc.baseKey, 10);
    }
Beispiel #5
0
    public void Reify_DocNode()
    {
        var doc = Config.LoadDocFromString(@"---
            ugh: bugh
        ", "ConfigReifier_DocNode_TestFilename");

        DocNode d = null;

        ConfigReifier.Reify(ref d, doc);
        Assert.True(d.ContainsKey("ugh"));
        Assert.AreEqual(d["ugh"].AsString(), "bugh");
    }
Beispiel #6
0
    public void FromDoc_UpdatesTestClass()
    {
        var tc = new TestClass {
            baseKey = 15
        };
        var saved = tc;
        var doc   = Config.LoadDocFromString("[\"Base\", 99]", c_filename);

        ConfigReifier.Reify(ref tc, doc);
        Assert.AreSame(tc, saved);
        Assert.AreEqual(tc.baseKey, 99);
    }
Beispiel #7
0
    public void FromDoc_UpdatesDerived()
    {
        TestClass tc = new TestClassDerived {
            baseKey = 1, derivedKey = 2
        };
        var saved = tc;
        var doc   = Config.LoadDocFromString("[\"Derived\", 66]", c_filename);

        ConfigReifier.Reify(ref tc, doc);
        Assert.AreSame(tc, saved);
        Assert.AreEqual(tc.baseKey, 1);
        Assert.AreEqual(((TestClassDerived)tc).derivedKey, 66);
    }
Beispiel #8
0
    public void FromDoc_OverwritesBase_WithDerived()
    {
        TestClass tc = new TestClass {
            baseKey = 19
        };
        var saved = tc;
        var doc   = Config.LoadDocFromString("[\"Derived\", 321]", c_filename);

        ConfigReifier.Reify(ref tc, doc);
        Assert.IsFalse(object.ReferenceEquals(tc, saved));
        Assert.IsTrue(tc is TestClassDerived);
        Assert.AreEqual(((TestClassDerived)tc).derivedKey, 321);
    }
Beispiel #9
0
    public void FromDoc_UpdatesDerived_AsBase()
    {
        TestClass tc = new TestClassDerived {
            baseKey = 4, derivedKey = 5
        };
        var saved = tc;
        var doc   = Config.LoadDocFromString("[\"Base\", 123]", c_filename);

        ConfigReifier.Reify(ref tc, doc);
        Assert.AreSame(tc, saved);
        Assert.AreEqual(tc.baseKey, 123);
        Assert.AreEqual(((TestClassDerived)tc).derivedKey, 5);
    }
Beispiel #10
0
    public void ReifierAttributes_MonoBehaviour_ForcesAllowMissing()
    {
        var doc = Config.LoadDocFromString(@"---
            field1: 1
        ", "ConfigReifier_ReifierAttributes_TestFilename");

        var obj = new GameObject("Test_ReifierAttributes");
        var mb  = obj.AddComponent <MonoBehaviourSubclass>();

        ConfigReifier.Reify(ref mb, doc, ConfigOptions.None);
        Assert.AreEqual(mb.field1, 1);

        Object.DestroyImmediate(obj);
    }
Beispiel #11
0
    public void PostDoc_MultipleCalled()
    {
        bool secondCalled = false;
        var  tc           = ReifyString <PostDocClass>("baseKey: 10");

        tc.PostDoc += (x) => {
            secondCalled = true;
            return(x);
        };
        var doc = Config.LoadDocFromString("baseKey: 10", c_filename);

        ConfigReifier.Reify(ref tc, doc);
        Assert.AreEqual(tc.PostDoc.GetInvocationList().Length, 2);
        Assert.True(secondCalled);
        Assert.AreEqual(tc.baseKey, 11);
    }