Ejemplo n.º 1
0
        public void TestInherit()
        {
            Serializer ser = new Regulus.Serialization.Dynamic.Serializer();


            TestGrandson test = new TestGrandson();

            test.Data = 100;
            TestChild testChild = test as TestChild;

            testChild.Data = 1;
            TestParent testParent = test as TestParent;

            testParent.Data = 33;

            byte[]       buf       = ser.ObjectToBuffer(test);
            TestGrandson val       = (TestGrandson)ser.BufferToObject(buf);
            TestParent   valParent = val as TestParent;
            TestChild    child     = val as TestChild;


            Assert.AreEqual(100, val.Data);
            Assert.AreEqual(1, child.Data);
            Assert.AreEqual(33, valParent.Data);
        }
Ejemplo n.º 2
0
        public void Test_CanExecute(bool expected, bool[] values)
        {
            // Arrange.
            var parent = new TestParent();

            foreach (var value in values)
            {
                var child = new TestItem {
                    BoolValue = value
                };
                parent.Items.Add(child);
            }

            var command = Command.For(parent)
                          .DependsOnCollection(p => p.Items)
                          .Where(p => p.DependentBoolValue)
                          .DependsOn(c => c.BoolValue)
                          .Executes(() => { });

            // Act.
            bool actual = command.CanExecute(null);

            // Assert.
            Assert.Equal(expected, actual);
        }
Ejemplo n.º 3
0
        public void Test_CanExecuteChanged_CollectionCleared()
        {
            // Arrange.
            var parent = new TestParent();
            var child1 = new TestItem();
            var child2 = new TestItem();

            var command = Command.For(parent)
                          .DependsOnCollection(p => p.Items)
                          .Where(p => p.DependentBoolValue)
                          .DependsOn(c => c.BoolValue)
                          .Executes(() => { });

            parent.Items.Add(child1);
            parent.Items.Add(child2);

            // Act/Assert.
            parent.Items.Clear();

            foreach (var child in new [] { child1, child2 })
            {
                var localChild = child;
                AssertThat.DoesNotRaise(command, c => c.CanExecuteChanged += null, () => localChild.BoolValue = true);
            }
        }
Ejemplo n.º 4
0
        public void Test_Tojson()
        {
            var tp = new TestParent();

            tp.num = 5;
            var json = JsonConverter.ToJson(tp);
            var data = JsonConverter.FromJson <TestParent>(json);

            Assert.AreEqual(5, data.num);
        }
Ejemplo n.º 5
0
        public void Test_TojsonFull2()
        {
            var tp = new TestParent();

            tp.num = 5;
            var json = JsonConverter.ToJson_full(tp);
            var data = JsonConverter.FromJson_full <TestChild>(json);

            Assert.AreEqual(5, data.num);
            Assert.AreNotEqual(1, data.childNum);
        }
Ejemplo n.º 6
0
        public void TestStorageList()
        {
            _ = new DC(null);

            var parent      = new TestParent("Parent", isStoring: false);
            var storageList = new StorageList <TestChild>();

            assert(storageList, "", "");

            var child0 = new TestChild("Child0", parent, isStoring: false);

            storageList.Add(child0);
            assert(storageList,
                   @"",
                   @"Key: noKey, Text: Child0, Parent: noKey, Parent;");

            var child1 = new TestChild("Child1", parent, isStoring: false);

            storageList.Add(child1);
            assert(storageList,
                   @"",
                   @"Key: noKey, Text: Child0, Parent: noKey, Parent;
          Key: noKey, Text: Child1, Parent: noKey, Parent;");

            parent.Store();
            assert(storageList,
                   @"",
                   @"Key: noKey, Text: Child0, Parent: 0, Parent;
          Key: noKey, Text: Child1, Parent: 0, Parent;");

            child0.Store();
            assert(storageList,
                   @"Key: 0, Text: Child0, Parent: 0, Parent;",
                   @"Key: 0, Text: Child0, Parent: 0, Parent;
          Key: noKey, Text: Child1, Parent: 0, Parent;");

            child1.Store();
            assert(storageList,
                   @"Key: 0, Text: Child0, Parent: 0, Parent;
          Key: 1, Text: Child1, Parent: 0, Parent;",
                   @"Key: 0, Text: Child0, Parent: 0, Parent;
          Key: 1, Text: Child1, Parent: 0, Parent;");

            child0.Release();
            assert(storageList,
                   @"Key: 1, Text: Child1, Parent: 0, Parent;",
                   @"Key: noKey, Text: Child0, Parent: 0, Parent;
          Key: 1, Text: Child1, Parent: 0, Parent;");
        }
Ejemplo n.º 7
0
        public void Test_ParentProperty_MustBeGetOnly()
        {
            // Arrange.
            var parent = new TestParent();

            var builder = Command.For(parent)
                          .DependsOnCollection(p => p.Items);

            // Act/Assert.
            Assert.Throws <ArgumentException>(() =>
                                              builder
                                              .Where(p => p.IndependentBoolValue)
                                              .DependsOn(c => c.BoolValue)
                                              .Executes(() => { }));
        }
Ejemplo n.º 8
0
        public void Test_CanExecuteChanged_ItemAdded()
        {
            // Arrange.
            var parent = new TestParent();
            var child  = new TestItem();

            var command = Command.For(parent)
                          .DependsOnCollection(p => p.Items)
                          .When(c => c.Any(p => p.BoolValue))
                          .Executes(() => { });

            // Act/Assert.
            parent.Items.Add(child);
            AssertThat.Raises(command, c => c.CanExecuteChanged += null, () => child.BoolValue = true);
        }
Ejemplo n.º 9
0
            public void Should_Build_AsCollectionScope_When_AsCollection_WithCustomError(string testId, Func <dynamic, ISpecificationOut <TestParent> > appendContentCommands, ErrorContentApiHelper.ExpectedErrorContent expectedErrorContent, Func <dynamic, ISpecificationOut <TestParent> > appendSetupCommands, ErrorSetupApiHelper.ExpectedErrorSetup <TestParent> expectedErrorSetup)
            {
                testId.Should().NotBeNull();

                var context = new ScopeBuilderContext();

                var builder = new ScopeBuilder();

                Specification <TestClass> innerSpecification = m => m;

                Specification <TestParent> specification = m => appendContentCommands(appendSetupCommands(m.Member(m1 => m1.TestMember, innerSpecification)));

                var scope = builder.Build(specification, context);

                scope.CommandScopes.Should().NotBeEmpty();
                scope.CommandScopes.Count.Should().Be(1);
                scope.CommandScopes[0].Should().BeOfType <MemberCommandScope <TestParent, TestClass> >();

                var memberCommandScope = (MemberCommandScope <TestParent, TestClass>)scope.CommandScopes[0];

                memberCommandScope.Path.Should().Be(expectedErrorSetup.Path ?? "TestMember");
                memberCommandScope.ExecutionCondition.Should().BeSameAs(expectedErrorSetup.ShouldExecute);
                memberCommandScope.ErrorMode.Should().Be(expectedErrorContent.Mode);

                var testParent = new TestParent()
                {
                    TestMember = new TestClass()
                };

                memberCommandScope.GetMemberValue(testParent).Should().BeSameAs(testParent.TestMember);

                memberCommandScope.ErrorId.Should().HaveValue();
                context.Errors.Keys.Should().Contain(memberCommandScope.ErrorId.Value);

                if (expectedErrorContent.ShouldBeEmpty(0))
                {
                    memberCommandScope.ErrorId.Should().Be(context.DefaultErrorId);
                }
                else
                {
                    memberCommandScope.ErrorId.Should().NotBe(context.DefaultErrorId);
                    expectedErrorContent.Match(context.Errors[memberCommandScope.ErrorId.Value], 0);
                }

                context.Scopes.Keys.Should().Contain(memberCommandScope.ScopeId);

                context.Scopes[memberCommandScope.ScopeId].Should().BeOfType <SpecificationScope <TestClass> >();
            }
Ejemplo n.º 10
0
        static void Main(string[] args)
        {
            Console.WriteLine("正常处理 : Action<父类> = Action<父类>");
            Action <object> actObject = PrintObject;

            actObject("Hello World!");


            Console.WriteLine("逆变处理 : Action<子类> = Action<父类>");
            Action <string> actString = PrintObject;

            actObject("Hello World!");



            TestParent p = new TestParent()
            {
                Name = "Parent",
            };

            TestSub s = new TestSub()
            {
                Name = "Sub",
            };



            Console.WriteLine("正常处理 : 自定义接口<父类> = 自定义接口<父类>");
            IContravariantAble <TestParent> cp = new ContravariantClass <TestParent>();

            cp.PrintData(p);
            cp.PrintData(s);


            Console.WriteLine("正常处理 : 自定义接口<子类> = 自定义接口<子类>");
            IContravariantAble <TestSub> cs = new ContravariantClass <TestSub>();

            cs.PrintData(s);


            Console.WriteLine("逆变处理 : 自定义接口<子类> = 自定义接口<父类>");
            cs = cp;
            cs.PrintData(s);


            Console.ReadLine();
        }
Ejemplo n.º 11
0
        public void Test_Execute()
        {
            // Arrange.
            var parent = new TestParent();

            bool executed = false;
            var  command  = Command.For(parent)
                            .DependsOnCollection(p => p.Items)
                            .When(c => c.Any(p => p.BoolValue))
                            .Executes(() => executed = true);

            // Act.
            command.Execute(null);

            // Assert.
            Assert.True(executed);
        }
Ejemplo n.º 12
0
        public void TestDCRestore()
        {
            var directoryInfo = new DirectoryInfo("TestCsv");
            var csvConfig     = new CsvConfig(directoryInfo.FullName, reportException: reportException);

            directoryInfo.Refresh();
            if (directoryInfo.Exists)
            {
                directoryInfo.Delete(recursive: true);
                directoryInfo.Refresh();
            }

            directoryInfo.Create();
            directoryInfo.Refresh();

            try {
                var dc          = new DC(csvConfig);
                var testParent0 = new TestParent("TestParent0");
                var testParent1 = new TestParent("TestParent1");
                var testParent2 = new TestParent("TestParent2");
                var testChild0  = new TestChild("TestChild0", testParent0);
                var testChild1  = new TestChild("TestChild1", testParent2);
                var testChild2  = new TestChild("TestChild2", testParent0);
                testChild1.Release();
                testParent2.Release();
                testChild2.Update("TestChild2 updated", testParent1);
                var expectedTestParent0 = testParent0.ToString();
                var expectedTestParent1 = testParent1.ToString();
                var expectedTestChild0  = testChild0.ToString();
                var expectedTestChild2  = testChild2.ToString();
                dc.Dispose();
                File.Delete(directoryInfo.FullName + @"\TestParent.csv");
                File.Move(directoryInfo.FullName + @"\TestParent.bak", directoryInfo.FullName + @"\TestParent.csv");
                File.Delete(directoryInfo.FullName + @"\TestChild.csv");
                File.Move(directoryInfo.FullName + @"\TestChild.bak", directoryInfo.FullName + @"\TestChild.csv");

                dc = new DC(csvConfig);
                Assert.AreEqual(expectedTestParent0, dc.TestParents[0].ToString());
                Assert.AreEqual(expectedTestParent1, dc.TestParents[1].ToString());
                Assert.AreEqual(expectedTestChild0, dc.TestChildren[0].ToString());
                Assert.AreEqual(expectedTestChild2, dc.TestChildren[2].ToString());
            } finally {
                DC.Data?.Dispose();
            }
        }
Ejemplo n.º 13
0
    public void CorrectlySerializesAndDeserializesObject()
    {
        var testParent = new TestParent
        {
            Id       = 7,
            Name     = "Test name",
            Children = new[]
            {
                new TestChild(),
                new TestChild(),
                new TestChild()
            }
        };

        var json   = testParent.ToJson();
        var result = json.FromJson <TestParent>();

        Assert.Equal(testParent, result);
    }
Ejemplo n.º 14
0
        public void TestArray1()
        {
            TestGrandson test = new TestGrandson();

            test.Data = 100;
            TestChild testChild = test as TestChild;

            testChild.Data = 1;
            TestParent testParent = test as TestParent;

            testParent.Data = 33;

            Serializer serializer =
                new Regulus.Serialization.Dynamic.Serializer(new CustomFinder((name) => Type.GetType(name)));

            byte[]       buf = serializer.ObjectToBuffer(new TestParent[] { test, testChild, testParent });
            TestParent[] val = (TestParent[])serializer.BufferToObject(buf);

            Assert.AreEqual(100, (val[0] as TestGrandson).Data);
            Assert.AreEqual(1, (val[1] as TestChild).Data);
            Assert.AreEqual(33, (val[2] as TestParent).Data);
        }
Ejemplo n.º 15
0
        public void Test_Execute_Asynchronously()
        {
            // Arrange.
            using (var resetEvent = new ManualResetEventSlim())
            {
                var parent = new TestParent();

                var command = Command.For(parent)
                              .DependsOnCollection(p => p.Items)
                              .When(c => c.Any(p => p.BoolValue))
                              .Asynchronously()
                              .Executes(async() =>
                {
                    await Task.Delay(TimeSpan.FromMilliseconds(100));
                    resetEvent.Set();
                });
                // Act.
                command.Execute(null);

                // Assert.
                resetEvent.Wait();
                Assert.True(resetEvent.IsSet);
            }
        }
Ejemplo n.º 16
0
 public static extern int mono_test_ccw_query_interface([MarshalAs(UnmanagedType.Interface)] TestParent obj);
Ejemplo n.º 17
0
 public Test(TestParent p)
 {
 }
Ejemplo n.º 18
0
 public TestParent(TestParent parent)
 {
     MyInt = new InheritedProperty <int>(parent.MyInt);
 }