コード例 #1
0
        public void ShouldCallEnableOnResourcesWhenConstructed()
        {
            SceneLayer        testLayer    = new SceneLayer("Test Layer");
            TestLayerResource testResource = testLayer.GetResource <TestLayerResource>();

            Assert.IsTrue(testResource.IsEnabled);
            testLayer.Dispose();
        }
コード例 #2
0
        public void TestGetSetProperties()
        {
            // Define variables and constants
            const int    PROP1     = 34;
            const string PROP2     = "Hello";
            const bool   PROP3     = false;
            const object PROP4     = null;
            SceneLayer   testLayer = new SceneLayer("Test Layer");

            // Set up context
            object prop3Added = null;

            testLayer.PropertySet += (layer, s, arg3) => {
                if (s == "prop3")
                {
                    prop3Added = arg3;
                }
            };

            testLayer.SetProperty("prop1", PROP1);
            testLayer["prop2"] = PROP2;
            testLayer.SetProperty("prop3", PROP3);
            testLayer["prop4"] = PROP4;

            // Execute
            Assert.AreEqual(PROP1, testLayer["prop1"]);
            Assert.AreEqual(PROP2, testLayer["prop2"]);
            Assert.AreEqual(PROP3, testLayer.GetProperty("prop3"));
            Assert.AreEqual(PROP4, testLayer.GetProperty("prop4"));
            Assert.AreEqual(PROP3, prop3Added);

            object prop1Removed = null;

            testLayer.PropertyRemoved += (layer, s, arg3) => {
                if (s == "prop1")
                {
                    prop1Removed = arg3;
                }
            };

            testLayer.RemoveProperty("prop1");
            testLayer.RemoveProperty("prop3");

            // Assert outcome
            Assert.AreEqual(PROP1, prop1Removed);
            Assert.IsFalse(testLayer.ContainsProperty("prop1"));
            Assert.AreEqual(PROP2, testLayer["prop2"]);
            Assert.AreEqual(PROP4, testLayer.GetProperty("prop4"));

            try {
                var obj = testLayer["prop3"];
                Console.WriteLine(obj);
                Assert.Fail();
            }
            catch (KeyNotFoundException) { }

            testLayer.Dispose();
        }
コード例 #3
0
        public void TestEnableDisableDispose()
        {
            // Define variables and constants
            SceneLayer testLayer = new SceneLayer("Test Layer");
            bool       wasEnabled = false, wasDisabled = false, wasDisposed = false;

            // Set up context
            testLayer.LayerEnabled  += layer => wasEnabled = true;
            testLayer.LayerDisabled += layer => wasDisabled = true;
            testLayer.LayerDisposed += layer => wasDisposed = true;

            // Execute
            testLayer.IsEnabled = false;
            testLayer.IsEnabled = true;
            testLayer.Dispose();

            // Assert outcome
            Assert.IsTrue(wasEnabled);
            Assert.IsTrue(wasDisabled);
            Assert.IsTrue(wasDisposed);
        }
コード例 #4
0
        public void TestResources()
        {
            // Define variables and constants
            SceneLayer testLayer = new SceneLayer("Test Layer");

            // Set up context
            TestLayerResource testResource = testLayer.GetResource <TestLayerResource>();

            // Execute
            Assert.IsFalse(testResource.IsDisabled);
            testLayer.IsEnabled = false;
            Assert.IsTrue(testResource.IsDisabled);
            testLayer.IsEnabled = true;
            Assert.IsTrue(testResource.IsEnabled);
            Assert.AreEqual(testLayer.GetResource <TestLayerResource>(), testResource);
            Assert.IsFalse(testResource.IsDisposed);
            testLayer.Dispose();
            Assert.IsTrue(testResource.IsDisposed);

            // Assert outcome
        }