示例#1
0
        public void PersistTest()
        {
            var r = new RealSysSvc();
            var s = new MockSysSvc(r, false);

            s.CurrentDirectory          = Environment.SystemDirectory;
            s.PropertyStore["MinValue"] = 1;
            s.PropertyStore["MaxValue"] = 10;
            s.PropertyStore["IntList"]  = new List <int>()
            {
                1, 2
            };

            var bytes = new byte[4096];

            using (var mst = new MemoryStream(bytes, true))
            {
                s.PropertyStore.PersistAsync(mst).Wait();
                Assert.That(mst.Length, Is.GreaterThan(0));
                mst.Flush();
            }

            var s2 = new MockSysSvc(r, false);

            using (var mst = new MemoryStream(bytes, false))
                s2.PropertyStore.LoadAsync(mst).Wait();
            Assert.That(s2.CurrentDirectory, Is.EqualTo(s.CurrentDirectory));
            Assert.That(s2.PropertyStore["MinValue"], Is.EqualTo(s.PropertyStore["MinValue"]));
            Assert.That(s2.PropertyStore["MaxValue"], Is.EqualTo(s.PropertyStore["MaxValue"]));
            Assert.That(s2.PropertyStore["Ints"], Is.EquivalentTo((System.Collections.IEnumerable)s.PropertyStore["Ints"]));
            Assert.That(s2.PropertyStore["IntList"], Is.EquivalentTo((System.Collections.IEnumerable)s.PropertyStore["IntList"]));
        }
示例#2
0
        public void ReadOnlyTest()
        {
            var r = new RealSysSvc();
            var s = new MockSysSvc(r, false);

            Assert.That(r.Today, Is.EqualTo(s.PropertyStore["Today"]));

            Assert.That(() => s.PropertyStore["Today"] = DateTime.Now, Throws.InvalidOperationException);
        }
示例#3
0
            public MockSysSvc(RealSysSvc svc, bool passthrough)
            {
                real  = svc;
                props = new PropertyStore(PropGet, PropSet, PropReset, passthrough);

                //props.CollectionChanged += OnPropertyCollectionChanged;
                //props.PropertyChanged += OnPropertyChanged;
                //props.PropertyChanging += OnPropertyChanging;

                // Load propertyset entries (manual, but could load from json)
                (props.PropertyDescriptors as PropertyDescriptorSet)?.LoadFromType(typeof(RealSysSvc));
            }
示例#4
0
        public void DirectTest()
        {
            var r = new RealSysSvc();
            var s = new MockSysSvc(r, true);

            Assert.That(r.CurrentDirectory, Is.EqualTo(s.CurrentDirectory));

            const string newDir = "C:\\";

            Assert.That(() => s.CurrentDirectory = newDir, Throws.Nothing);
            Assert.That(s.CurrentDirectory, Is.EqualTo(newDir));
            Assert.That(r.CurrentDirectory, Is.EqualTo(newDir));
        }
示例#5
0
        public void Direct2Test()
        {
            var r = new RealSysSvc();
            var s = new MockSysSvc(r, true);

            Assert.That(r.MinValue, Is.EqualTo(s.PropertyStore["MinValue"]));

            const int newVal = 255;

            Assert.That(() => s.PropertyStore["MinValue"] = newVal, Throws.Nothing);
            Assert.That(s.PropertyStore["MinValue"], Is.EqualTo(newVal));
            Assert.That(r.MinValue, Is.EqualTo(newVal));
        }
示例#6
0
        public void StagedTest()
        {
            var r = new RealSysSvc();
            var s = new MockSysSvc(r, false);

            Assert.That(r.CurrentDirectory, Is.EqualTo(s.CurrentDirectory));

            const string newDir = "C:\\";

            Assert.That(() => s.CurrentDirectory = newDir, Throws.Nothing);
            Assert.That(s.CurrentDirectory, Is.EqualTo(newDir));
            Assert.That(r.CurrentDirectory, Is.Not.EqualTo(newDir));
            Assert.That(() => s.PropertyStore.Commit(), Throws.Nothing);
            Assert.That(r.CurrentDirectory, Is.EqualTo(newDir));
        }
示例#7
0
        public void SetPersistTest()
        {
            var r = new RealSysSvc();
            var s = new MockSysSvc(r, false);

            var bytes = new byte[4096];

            using var mst = new MemoryStream(bytes, true);
            s.PropertyStore.PropertyDescriptors.PersistAsync(mst).Wait();
            mst.Flush();

            var str = Encoding.UTF8.GetString(bytes, 0, Array.IndexOf(Encoding.UTF8.GetChars(bytes), '\u0000') + 2);

            Assert.That(str, Contains.Substring("\"canWrite\": false"));
            Assert.That(str, Contains.Substring("System.DateTime"));
            TestContext.Write(str);
        }
示例#8
0
        public void UndefinedPropTest()
        {
            var r = new RealSysSvc();
            var s = new MockSysSvc(r, false);

            object o = null;

            Assert.That(() => o = s.PropertyStore["Oggi"], Throws.TypeOf <KeyNotFoundException>());

            if (s.PropertyStore is PropertyStore ps)
            {
                ps.NoDescriptorValidation = true;
            }
            Assert.That(() => o = s.PropertyStore["Oggi"], Throws.Nothing);
            Assert.That(o, Is.Null);
            Assert.That(() => s.PropertyStore["Oggi"] = DateTime.Today, Throws.Nothing);
            Assert.That(() => o = s.PropertyStore["Oggi"], Throws.Nothing);
            Assert.That(o, Is.EqualTo(DateTime.Today));
        }