Exemplo n.º 1
0
    public void RefiesCaseInsensitive_Missing()
    {
        var doc  = Config.LoadDocFromString(@"---
            childintkey: 32
        ", "ConfigReifier_ReifiesCaseInsensitive_TestFilename");
        var inst = ConfigReifier.CreateInstance <ChildStruct>(doc, ConfigOptions.AllowMissingFields);

        Assert.AreEqual(inst.childIntKey, 32);
    }
Exemplo n.º 2
0
    public void RefiesExtraFields_NoException()
    {
        var doc  = Config.LoadDocFromString(@"---
            floatKey: 1.56
        ", "ConfigReifier_ReifiesExtraFields_TestFilename");
        var inst = ConfigReifier.CreateInstance <TestClass>(doc, ConfigOptions.AllowMissingFields);

        Assert.AreEqual(inst.floatKey, 1.56f);
    }
Exemplo n.º 3
0
    public void ReifierAttributes_AllowMissingClass_OverridesOptions()
    {
        var doc  = Config.LoadDocFromString(@"---
            stringField: wot
        ", "ConfigReifier_ReifierAttributes_TestFilename");
        var inst = ConfigReifier.CreateInstance <AllowMissingClass>(doc, ConfigOptions.None);

        Assert.AreEqual(inst.stringField, "wot");
        Assert.AreEqual(inst.listField, null);
    }
Exemplo n.º 4
0
    public void ReifierAttributes_MandatoryClass_AllowsMissingField()
    {
        var doc  = Config.LoadDocFromString(@"---
            intField: 99
        ", "ConfigReifier_ReifierAttributes_TestFilename");
        var inst = ConfigReifier.CreateInstance <MandatoryClass>(doc, ConfigOptions.None);

        Assert.AreEqual(inst.intField, 99);
        Assert.AreEqual(inst.stringField, "initial");
        Assert.AreEqual(inst.ignoreField, "initialignore");
    }
Exemplo n.º 5
0
    public void ReifierAttributes_AllowMissingClass_AcceptsSetting()
    {
        var doc  = Config.LoadDocFromString(@"---
            stringField: hmm
            listField: [1]
        ", "ConfigReifier_ReifierAttributes_TestFilename");
        var inst = ConfigReifier.CreateInstance <AllowMissingClass>(doc, ConfigOptions.None);

        Assert.AreEqual(inst.stringField, "hmm");
        Assert.AreEqual(inst.listField[0], "1");
    }
Exemplo n.º 6
0
    public void ReifierAttributes_AllowedMissing_ByDefaultInClassWithMandatory()
    {
        var doc  = Config.LoadDocFromString(@"---
            Mandatory: 15
        ", "ConfigReifier_ReifierAttributes_TestFilename");
        var inst = ConfigReifier.CreateInstance <AttributesClass>(doc, ConfigOptions.AllowMissingFields);

        Assert.AreEqual(inst.Mandatory, 15);
        Assert.AreEqual(inst.AllowedMissing, "initial");
        Assert.AreEqual(inst.MissingOrNotDependingOnDefault, "initial2");
    }
Exemplo n.º 7
0
    public void ReifierAttributes_Mandatory_ExceptsIfNotSet()
    {
        var doc = Config.LoadDocFromString(@"---
            AllowedMissing: derp
        ", "ConfigReifier_ReifierAttributes_TestFilename");

        Assert.Throws <ParseException>(
            () => {
            ConfigReifier.CreateInstance <AttributesClass>(doc, ConfigOptions.AllowMissingFields);
        });
    }
Exemplo n.º 8
0
    public void ReifierAttributes_AllowMissingClass_ChecksMandatoryField()
    {
        var doc = Config.LoadDocFromString(@"---
            listField: [a,b]
        ", "ConfigReifier_ReifierAttributes_TestFilename");

        Assert.Throws <ParseException>(
            () => {
            ConfigReifier.CreateInstance <AllowMissingClass>(doc, ConfigOptions.AllowMissingFields);
        });
    }
Exemplo n.º 9
0
    public void ReifiesSingle_CreateSingleFieldClass()
    {
        var doc = Config.LoadDocFromString(
            @"---
            8342
            "
            , "ConfigReifierFacts_ReifySingle_TestFilename");
        var inst = ConfigReifier.CreateInstance <SingleFieldClass>(doc);

        Assert.AreEqual(inst.SingleField, 8342);
    }
Exemplo n.º 10
0
    public void ReifierAttributes_MandatoryClass_OverridesOptions()
    {
        var doc = Config.LoadDocFromString(@"---
            stringField: uh
        ", "ConfigReifier_ReifierAttributes_TestFilename");

        Assert.Throws <ParseException>(
            () => {
            ConfigReifier.CreateInstance <MandatoryClass>(doc, ConfigOptions.AllowMissingFields);
        });
    }
Exemplo n.º 11
0
    public void ReifierAttributes_Mandatory_AllowsSetting()
    {
        var doc  = Config.LoadDocFromString(@"---
            Mandatory: 10
            AllowedMissing: derp
        ", "ConfigReifier_ReifierAttributes_TestFilename");
        var inst = ConfigReifier.CreateInstance <AttributesClass>(doc);

        Assert.AreEqual(inst.Mandatory, 10);
        Assert.AreEqual(inst.AllowedMissing, "derp");
        Assert.AreEqual(inst.Ignored, false);
    }
Exemplo n.º 12
0
    public void ReifierAttributes_MandatoryClass_AcceptsSetting()
    {
        var doc  = Config.LoadDocFromString(@"---
            intField: 10
            stringField: uh
        ", "ConfigReifier_ReifierAttributes_TestFilename");
        var inst = ConfigReifier.CreateInstance <MandatoryClass>(doc, ConfigOptions.None);

        Assert.AreEqual(inst.intField, 10);
        Assert.AreEqual(inst.stringField, "uh");
        Assert.AreEqual(inst.ignoreField, "initialignore");
    }
Exemplo n.º 13
0
    public void ReifierAttributes_AllowMissingClass_DoesCheckExtraFieldsToo()
    {
        var doc = Config.LoadDocFromString(@"---
            stringField: hi
            extra_field: 33333
        ", "ConfigReifier_ReifierAttributes_TestFilename");

        Assert.Throws <ParseException>(
            () => {
            ConfigReifier.CreateInstance <AllowMissingClass>(doc, ConfigOptions.AllowMissingFields);
        });
    }
Exemplo n.º 14
0
    public void RefiesCaseInsensitive()
    {
        var doc  = Config.LoadDocFromString(@"---
            childintkey: 32
            CHILDFLOATKEY: 11
            StaticiNtKey: 5
        ", "ConfigReifier_ReifiesCaseInsensitive_TestFilename");
        var inst = ConfigReifier.CreateInstance <ChildStruct>(doc, ConfigOptions.None);

        Assert.AreEqual(inst.childIntKey, 32);
        Assert.AreEqual(inst.childFloatKey, 11);
        Assert.AreEqual(ChildStruct.staticIntKey, 5);
    }
Exemplo n.º 15
0
    public void ReifierAttributes_AllowedMissing_NoExceptionIfMissing()
    {
        var doc  = Config.LoadDocFromString(@"---
            Mandatory: 15
            MissingOrNotDependingOnDefault: true
        ", "ConfigReifier_ReifierAttributes_TestFilename");
        var inst = ConfigReifier.CreateInstance <AttributesClass>(doc, ConfigOptions.None);

        Assert.AreEqual(inst.Mandatory, 15);
        Assert.AreEqual(inst.AllowedMissing, "initial");
        Assert.AreEqual(inst.Ignored, false);
        Assert.AreEqual(inst.MissingOrNotDependingOnDefault, "true");
    }
Exemplo n.º 16
0
    public void RefiesMissingFields_NoException()
    {
        var doc  = Config.LoadDocFromString(@"---
            childIntKey: 42
            childFloatKey: 1.25
            staticIntKey: 332
        ", "ConfigReifier_ReifiesMissingFields_TestFilename");
        var inst = ConfigReifier.CreateInstance <ChildStruct>(doc, ConfigOptions.None);

        Assert.AreEqual(inst.childIntKey, 42);
        Assert.AreEqual(inst.childFloatKey, 1.25);
        Assert.AreEqual(ChildStruct.staticIntKey, 332);
    }
Exemplo n.º 17
0
    public void ReifiesSingle_CreateSingleListClass()
    {
        var doc = Config.LoadDocFromString(
            @"---
            [a, b, c, d]
            "
            , "ConfigReifierFacts_ReifySingle_TestFilename");
        var inst = ConfigReifier.CreateInstance <SingleListClass>(doc);

        Assert.AreEqual(inst.SingleList[0], "a");
        Assert.AreEqual(inst.SingleList[1], "b");
        Assert.AreEqual(inst.SingleList[2], "c");
        Assert.AreEqual(inst.SingleList[3], "d");
    }
Exemplo n.º 18
0
    public void RefiesMissingFields_Raises()
    {
        var doc = Config.LoadDocFromString(@"---
            childIntKey: 32
        ", "ConfigReifier_ReifiesMissingFields_TestFilename");
        var ex  = Assert.Throws <ParseException>(
            () => {
            ConfigReifier.CreateInstance <ChildStruct>(doc, ConfigOptions.CaseSensitive);
        });

        // check that it found all the missing keys
        Assert.True(ex.Message.IndexOf("childFloatKey") >= 0);
        Assert.True(ex.Message.IndexOf("staticIntKey") >= 0);
    }
Exemplo n.º 19
0
    public void ReifierAttributes_Ignore_MissingIgnored()
    {
        var doc  = Config.LoadDocFromString(@"---
            Mandatory: 102
            AllowedMissing: herpe
            MissingOrNotDependingOnDefault: whip
        ", "ConfigReifier_ReifierAttributes_TestFilename");
        var inst = ConfigReifier.CreateInstance <AttributesClass>(doc, ConfigOptions.None);

        Assert.AreEqual(inst.Mandatory, 102);
        Assert.AreEqual(inst.AllowedMissing, "herpe");
        Assert.AreEqual(inst.Ignored, false);
        Assert.AreEqual(inst.MissingOrNotDependingOnDefault, "whip");
    }
Exemplo n.º 20
0
    public void RefiesExtraFields_Raises()
    {
        var doc = Config.LoadDocFromString(@"---
            floatKey: 1.56
            extraKey1: derp
            extraKey2: herp
        ", "ConfigReifier_ReifiesExtraFields_TestFilename");
        var ex  = Assert.Throws <ParseException>(
            () => {
            ConfigReifier.CreateInstance <TestClass>(doc, ConfigOptions.CaseSensitive);
        });

        // check that it found all the extra keys
        Assert.True(ex.Message.IndexOf("extraKey1") >= 0);
        Assert.True(ex.Message.IndexOf("extraKey2") >= 0);
    }