コード例 #1
0
ファイル: BeanTests.cs プロジェクト: KateHowland/flip
        public void CapturesSpecificFieldsOnly()
        {
            int    a = 330;
            float  b = 12.784f;
            string c = "paradigm";

            TestClass captive = new TestClass(a, b, c);

            List <string> captureFields = new List <string> {
                "A", "C"
            };

            Bean bean = new Bean(captive, captureFields);

            Assert.IsTrue(bean.HasValue("A"));
            Assert.IsFalse(bean.HasValue("B"));
            Assert.IsTrue(bean.HasValue("C"));

            bean          = new Bean();
            captureFields = new List <string> {
                "B", "C"
            };
            bean.Capture(captive, false, captureFields);

            Assert.IsFalse(bean.HasValue("A"));
            Assert.IsTrue(bean.HasValue("B"));
            Assert.IsTrue(bean.HasValue("C"));
        }
コード例 #2
0
ファイル: BeanTests.cs プロジェクト: KateHowland/flip
        public void CapturesMultipleObjectsAsBean()
        {
            int    a = 330;
            float  b = 12.784f;
            string c = "paradigm";

            TestClass captive = new TestClass(a, b, c);

            string c2 = "porcupine";
            int    d  = 990;
            object e  = new OperatingSystem(PlatformID.Unix, new Version());

            AnotherTestClass captive2 = new AnotherTestClass(c2, d, e);

            Bean bean = new Bean(captive);

            bool overwrite = false;

            bean.Capture(captive2, overwrite);

            Assert.IsTrue(bean.HasValue("A"));
            Assert.IsTrue(bean.HasValue("B"));
            Assert.IsTrue(bean.HasValue("C"));
            Assert.IsTrue(bean.HasValue("D"));
            Assert.IsTrue(bean.HasValue("E"));
            Assert.AreEqual(a.ToString(), bean.GetValue("A"));
            Assert.AreEqual(b.ToString(), bean.GetValue("B"));
            Assert.AreEqual(c, bean.GetValue("C"));
            Assert.AreEqual(d.ToString(), bean.GetValue("D"));
            Assert.AreEqual(e.ToString(), bean.GetValue("E"));

            overwrite = true;

            bean.Capture(captive2, overwrite);

            Assert.IsTrue(bean.HasValue("A"));
            Assert.IsTrue(bean.HasValue("B"));
            Assert.IsTrue(bean.HasValue("C"));
            Assert.IsTrue(bean.HasValue("D"));
            Assert.IsTrue(bean.HasValue("E"));
            Assert.AreEqual(a.ToString(), bean.GetValue("A"));
            Assert.AreEqual(b.ToString(), bean.GetValue("B"));
            Assert.AreEqual(c2, bean.GetValue("C"));
            Assert.AreEqual(d.ToString(), bean.GetValue("D"));
            Assert.AreEqual(e.ToString(), bean.GetValue("E"));
        }