Ejemplo n.º 1
0
        public void TestItems()
        {
            //setup
            using DatapackTestClass pack = new DatapackTestClass("path", "pack");
            NamespaceTestClass packNamespace = new NamespaceTestClass(pack, "namespace");

            //test
            TestGroupClass.WriterToUse = new StringWriter();
            TestGroupClass group = new TestGroupClass(packNamespace, "name1", new List <GroupItemClass> {
                new GroupItemClass("test")
            }, false, BaseFile.WriteSetting.LockedOnDispose);

            Assert.ThrowsException <ArgumentNullException>(() => group.Items = null !, "Items should not be able to be null");
            group.Items = new List <GroupItemClass>()
            {
            };
            group.Dispose();

            TestGroupClass.WriterToUse = new StringWriter();
            group = new TestGroupClass(packNamespace, "name2", new List <GroupItemClass> {
                new GroupItemClass("test")
            }, false, BaseFile.WriteSetting.LockedAuto);
            Assert.ThrowsException <InvalidOperationException>(() => group.Items = new List <GroupItemClass>()
            {
            }, "Items should not be changeable because the file is auto");
        }
Ejemplo n.º 2
0
        public void TestWriting()
        {
            //setup
            using DatapackTestClass pack = new DatapackTestClass("path", "pack");
            NamespaceTestClass packNamespace = new NamespaceTestClass(pack, "namespace");

            //test
            TestGroupClass.WriterToUse = new StringWriter();
            TestGroupClass group = new TestGroupClass(packNamespace, "name1", new List <GroupItemClass> {
                new GroupItemClass("test")
            }, true, BaseFile.WriteSetting.LockedOnDispose);

            group.Items.Add(new GroupItemClass("test2"));
            group.Items.Add(new GroupItemClass("test3"));
            Assert.AreEqual("", ((StringWriter)TestGroupClass.WriterToUse).GetStringBuilder().ToString(), "Group shouldn't have been written yet");
            group.Dispose();
            Assert.AreEqual("{\"values\":[\"test\",\"test2\",\"test3\"]}", ((StringWriter)TestGroupClass.WriterToUse).GetStringBuilder().ToString(), "Group wasn't written correctly");

            TestGroupClass.WriterToUse = new StringWriter();
            group = new TestGroupClass(packNamespace, "name2", new List <GroupItemClass> {
                new GroupItemClass("test")
            }, false, BaseFile.WriteSetting.LockedAuto);
            group.Dispose();
            Assert.IsTrue(group.Disposed);
            Assert.AreEqual("{\"replace\":true,\"values\":[\"test\"]}", ((StringWriter)TestGroupClass.WriterToUse).GetStringBuilder().ToString(), "Group didn't write AppendFile correctly");
            Assert.IsNull(group.Items, "Items wasn't cleared");
        }