Ejemplo n.º 1
0
        public void TestGetFullName()
        {
            MockNamespace space   = MockNamespace.GetNamespace("myspace");
            Storage       storage = new Storage(space, "storage");

            Assert.AreEqual("myspace:storage", storage.GetNamespacedName(), "GetNamespacedName with namespace returns wrong value");
        }
Ejemplo n.º 2
0
 public void TestEmptyNamespace()
 {
     Assert.AreEqual(MockNamespace.GetMinecraftNamespace(), MockNamespace.GetMinecraftNamespace(), "Getting minecraft namespace doesn't return the same object every time");
     Assert.AreEqual("minecraft", MockNamespace.GetMinecraftNamespace().Name, "Getting minecraft namespace returns wrong namespace");
     Assert.AreEqual(MockNamespace.GetNamespace("space"), MockNamespace.GetNamespace("space"), "Getting defined namespace doesn't return the same object every time");
     Assert.AreEqual("space", MockNamespace.GetNamespace("space").Name, "Getting defined namespace returns wrong namespace");
 }
Ejemplo n.º 3
0
        public void TestGetFullName()
        {
            BossBar bar1 = new BossBar("mybar");

            Assert.AreEqual("minecraft:mybar", bar1.GetFullName(), "GetFullName without namespace returns wrong value");

            MockNamespace space = MockNamespace.GetNamespace("myspace");
            BossBar       bar2  = new BossBar(space, "otherbar");

            Assert.AreEqual("myspace:otherbar", bar2.GetFullName(), "GetFullName with namespace returns wrong value");
        }
Ejemplo n.º 4
0
        public void TestStorage()
        {
            MockNamespace space   = MockNamespace.GetNamespace("myspace");
            Storage       storage = new Storage(space, "storage");

            Assert.AreEqual("storage", storage.Name, "Namespace constructor didn't set name");
            Assert.AreSame(space, storage.PackNamespace, "Namespace constructor should have set namespace to null");

            Assert.ThrowsException <ArgumentNullException>(() => new Storage(null !, "name"), "Namespace may not be null");
            Assert.ThrowsException <ArgumentException>(() => new Storage(space, "Inval:d"), "Name should be validated");
        }
Ejemplo n.º 5
0
        public void AdvancementSomeCommandTest()
        {
            using MockDatapack datapack = new MockDatapack("name");
            MockNamespace packNamespace = datapack.Namespace("space");

            Assert.AreEqual("advancement grant @a from space:adv", new AdvancementSomeCommand(ID.Selector.a, new FileMocks.MockAdvancement(packNamespace, "adv"), ID.RelativeAdvancement.from, true).GetCommandString());
            Assert.AreEqual("advancement revoke @a from space:adv", new AdvancementSomeCommand(ID.Selector.a, new FileMocks.MockAdvancement(packNamespace, "adv"), ID.RelativeAdvancement.from, false).GetCommandString());
            Assert.AreEqual("advancement grant @a through space:adv", new AdvancementSomeCommand(ID.Selector.a, new FileMocks.MockAdvancement(packNamespace, "adv"), ID.RelativeAdvancement.through, true).GetCommandString());
            Assert.AreEqual("advancement revoke @a through space:adv", new AdvancementSomeCommand(ID.Selector.a, new FileMocks.MockAdvancement(packNamespace, "adv"), ID.RelativeAdvancement.through, false).GetCommandString());
            Assert.AreEqual("advancement grant @a until space:adv", new AdvancementSomeCommand(ID.Selector.a, new FileMocks.MockAdvancement(packNamespace, "adv"), ID.RelativeAdvancement.until, true).GetCommandString());
            Assert.AreEqual("advancement revoke @a until space:adv", new AdvancementSomeCommand(ID.Selector.a, new FileMocks.MockAdvancement(packNamespace, "adv"), ID.RelativeAdvancement.until, false).GetCommandString());

            Assert.ThrowsException <ArgumentNullException>(() => new AdvancementSomeCommand(null !, new FileMocks.MockAdvancement(packNamespace, "adv"), ID.RelativeAdvancement.from, true));
            Assert.ThrowsException <ArgumentNullException>(() => new AdvancementSomeCommand(ID.Selector.a, null !, ID.RelativeAdvancement.until, true));
        }
Ejemplo n.º 6
0
        public void TestBossBar()
        {
            BossBar bar1 = new BossBar("myBAR");

            Assert.AreEqual("mybar", bar1.Name, "Constructor didn't set name");
            Assert.IsNull(bar1.Namespace, "Constructor should have set namespace to null");

            MockNamespace space = MockNamespace.GetNamespace("myspace");
            BossBar       bar2  = new BossBar(space, "otherbar");

            Assert.AreEqual("otherbar", bar2.Name, "Namespace constructor didn't set name");
            Assert.AreSame(space, bar2.Namespace, "Namespace constructor should have set namespace to null");

            Assert.ThrowsException <ArgumentException>(() => new BossBar("Inval:d"), "Name should be validated");
        }
Ejemplo n.º 7
0
        public void TestStorageDataLocation()
        {
            //test
            Storage             storage  = new Storage(MockNamespace.GetNamespace("space"), "stor");
            StorageDataLocation location = new StorageDataLocation(storage, "test1.test2");

            Assert.AreEqual("space:stor", location.Storage.GetNamespacedName(), "Constructor didn't set storage correctly");
            Assert.AreEqual("test1.test2", location.DataPath, "Constructor didn't set DataPath correctly");
            Assert.AreEqual("storage space:stor test1.test2", location.GetLocationString(), "GetLocationString returns wrong string");

            //exceptions
            Assert.ThrowsException <ArgumentNullException>(() => new StorageDataLocation(null !, "test"), "storage may not be null");
            Assert.ThrowsException <ArgumentException>(() => new StorageDataLocation(storage, ""), "Path may not be empty");
            Assert.ThrowsException <ArgumentException>(() => new StorageDataLocation(storage, null !), "Path may not be null");
        }
Ejemplo n.º 8
0
        public void AdvancementSingleCommandTest()
        {
            using MockDatapack datapack = new MockDatapack("name");
            MockNamespace packNamespace = datapack.Namespace("space");

            Assert.AreEqual("advancement grant @a only space:adv", new AdvancementSingleCommand(ID.Selector.a, new FileMocks.MockAdvancement(packNamespace, "adv"), null, true).GetCommandString());
            Assert.AreEqual("advancement revoke @a only space:adv", new AdvancementSingleCommand(ID.Selector.a, new FileMocks.MockAdvancement(packNamespace, "adv"), null, false).GetCommandString());
            Assert.AreEqual("advancement grant @a only space:adv test", new AdvancementSingleCommand(ID.Selector.a, new FileMocks.MockAdvancement(packNamespace, "adv"), new AdvancementObjects.BredAnimalsTrigger()
            {
                Name = "test"
            }, true).GetCommandString());
            Assert.AreEqual("advancement revoke @a only space:adv test", new AdvancementSingleCommand(ID.Selector.a, new FileMocks.MockAdvancement(packNamespace, "adv"), new AdvancementObjects.BredAnimalsTrigger()
            {
                Name = "test"
            }, false).GetCommandString());

            Assert.ThrowsException <ArgumentNullException>(() => new AdvancementSingleCommand(null !, new FileMocks.MockAdvancement(packNamespace, "adv"), null, true));
            Assert.ThrowsException <ArgumentNullException>(() => new AdvancementSingleCommand(ID.Selector.a, null !, null, true));
        }
Ejemplo n.º 9
0
        public void TestTexts()
        {
            //text
            Assert.AreEqual("{\"text\":\"hel\\nlo\"}", new JsonText.Text("hel\nlo").GetJsonString(), "Text doesn't return correct string");
            Assert.ThrowsException <ArgumentNullException>(() => new JsonText.Text(null !), "Text should throw exception when null");

            //translate
            Assert.AreEqual("{\"translate\":\"hel\\\"lo\",\"with\":[{\"text\":\"insert1\"},{\"text\":\"insert2\"}]}", new JsonText.Translate("hel\"lo", new BaseJsonText[] { new JsonText.Text("insert1"), new JsonText.Text("insert2") }).GetJsonString(), "Translate doesn't return correct string");
            Assert.AreEqual("{\"translate\":\"hello\"}", new JsonText.Translate("hello").GetJsonString(), "Translate doesn't return correct string when only translate is specified");
            Assert.ThrowsException <ArgumentNullException>(() => new JsonText.Translate(null !), "Translate should throw exception if translate is null");

            //names
            Assert.AreEqual("{\"selector\":\"@a[name=\\\"Name\\\"]\"}", new JsonText.Names(new Selector(ID.Selector.a)
            {
                SingleName = "Name"
            }).GetJsonString(), "Names doesn't return correct string");
            Assert.ThrowsException <ArgumentNullException>(() => new JsonText.Names(null !), "Names selector should throw exception if null");

            //keybind
            Assert.AreEqual("{\"keybind\":\"key.inventory\"}", new JsonText.KeyBind(ID.Key.inventory).GetJsonString(), "Keybind doesn't return correct string");

            //data
            Assert.AreEqual("{\"nbt\":\"test.t{a:\\\"hello\\\"}\",\"interpret\":true,\"entity\":\"@s[name=\\\"Name\\\"]\"}", new JsonText.Data(new EntityDataLocation(new Selector(ID.Selector.s)
            {
                SingleName = "Name"
            }, "test.t{a:\"hello\"}"), true).GetJsonString(), "Data entity doesn't return correct string");
            Assert.AreEqual("{\"nbt\":\"path\",\"interpret\":false,\"block\":\"~1 ~2 ~3\"}", new JsonText.Data(new BlockDataLocation(new Coords(1, 2, 3), "path"), false).GetJsonString(), "Data block doesn't return correct string");
            Assert.AreEqual("{\"nbt\":\"path\",\"interpret\":false,\"storage\":\"space:stor\"}", new JsonText.Data(new StorageDataLocation(new Storage(MockNamespace.GetNamespace("space"), "stor"), "path"), false).GetJsonString(), "Data storage doesn't return correct string");
            Assert.ThrowsException <ArgumentNullException>(() => new JsonText.Data(null !, true), "Data should throw exception if location is null");

            //score
            Assert.AreEqual("{\"score\":{\"name\":\"@s[name=\\\"Name\\\"]\",\"objective\":\"test\"}}", new JsonText.Score(new Selector(ID.Selector.s)
            {
                SingleName = "Name"
            }, new Objective("test")).GetJsonString(), "Score doesn't return correct string");
            Assert.ThrowsException <ArgumentException>(() => new JsonText.Score(ID.Selector.e, new Objective("something")), "Score should throw exception is selector selects too many things");
            _ = new JsonText.Score(AllSelector.GetSelector(), new Objective("something"));
            Assert.ThrowsException <ArgumentNullException>(() => new JsonText.Score(null !, new Objective("something")), "Score should throw exception if selector is null");
            Assert.ThrowsException <ArgumentNullException>(() => new JsonText.Score(ID.Selector.s, null !), "Score should throw exception if objective is null");
        }
Ejemplo n.º 10
0
        private BossBar GetBar()
        {
            MockNamespace space = MockNamespace.GetNamespace("boss");

            return(new BossBar(space, "name"));
        }