コード例 #1
0
        public void TestArrayOfStructsException()
        {
            TestGraph.Worker arthur = new TestGraph.Worker { Name = "Arthur", Image = new byte[] { 0, 1, 2, 3, 4, 5 } };
            ObjectGraph graph = new ObjectGraph(arthur) { IncludeReferenceTypes = true };
            IEnumerable<object> objects = graph.Collapse();

            Assert.AreEqual(6, objects.Count(item => item is byte));
        }
コード例 #2
0
        public void TestSerializeEnum()
        {
            TestGraph.Worker arthur = new TestGraph.Worker {Name = "Arthur", Status = TestGraph.WorkerStatus.Normal};
            CoreDataSerializer serializer = new CoreDataSerializer(arthur);

            CoreDataCommand command = serializer.Commands.First();
            Assert.AreEqual("3", command.Parameters["Status"]);
        }
コード例 #3
0
        public void TestDateTimeOutput()
        {
            TestGraph.Worker arthur = new TestGraph.Worker { Name = "Arthur", HireDate = new DateTime(2001, 01, 01, 08, 0, 0) };
            CoreDataSerializer serializer = new CoreDataSerializer(arthur);

            CoreDataCommand command = serializer.Commands.First();
            Assert.AreEqual("28800", command.Parameters["HireDate"]);
        }
コード例 #4
0
        public void TestBooleanOutput()
        {
            TestGraph.Worker arthur = new TestGraph.Worker { Name = "Arthur", IsEnabled = true };
            CoreDataSerializer serializer = new CoreDataSerializer(arthur);

            CoreDataCommand command = serializer.Commands.First();
            Assert.AreEqual("1", command.Parameters["IsEnabled"]);
        }
コード例 #5
0
        public void TestSerializeNullValue()
        {
            TestGraph.Worker arthur = new TestGraph.Worker { Name = null };
            CoreDataSerializer serializer = new CoreDataSerializer(arthur);

            IEnumerable<CoreDataCommand> commands = serializer.Commands.ToList();
            CoreDataCommand command = commands.First();
            Assert.AreEqual("", command.Parameters["Name"]);
        }
コード例 #6
0
        public void TestCustomConverter()
        {
            TestGraph.Worker arthur = new TestGraph.Worker { Name = "Arthur" };
            CoreDataSerializer serializer = new CoreDataSerializer(arthur);
            serializer.ValueConverters[typeof(string)] = value => Convert.ToString(value) + " 1234";

            CoreDataCommand command = serializer.Commands.First();
            Assert.AreEqual("Arthur 1234", command.Parameters["Name"]);
        }
コード例 #7
0
        public void TestIgnoreDataMember()
        {
            TestGraph.Worker arthur = new TestGraph.Worker {Name = "Arthur", Password = "******"};
            CoreDataSerializer serializer = new CoreDataSerializer(arthur);

            IEnumerable<CoreDataCommand> commands = serializer.Commands.ToList();
            CoreDataCommand command = commands.First();

            Assert.IsFalse(command.Parameters.ContainsKey("Password"));
        }
コード例 #8
0
        public void TestDefaultsAreNotModified()
        {
            TestGraph.Worker arthur = new TestGraph.Worker { Name = "Arthur" };

            int defaultConverters = CoreDataSerializer.DefaultValueConverters.Count;

            CoreDataSerializer serializer = new CoreDataSerializer(arthur);
            serializer.ValueConverters[typeof(string)] = value => Convert.ToString(value) + " 1234";

            Assert.AreEqual(defaultConverters, CoreDataSerializer.DefaultValueConverters.Count);
        }
コード例 #9
0
        public void TestBackwardRelation()
        {
            TestGraph.Worker arthur = new TestGraph.Worker {Name = "Arthur"};
            TestGraph.Department sales = new TestGraph.Department {Name = "sales", Workers = new[] {arthur}};
            arthur.CurrentDepartment = sales;

            CoreDataSerializer serializer = new CoreDataSerializer(sales);
            IEnumerable<CoreDataCommand> commands = serializer.Commands.ToList();
            Assert.AreEqual(2, commands.Count());

            CoreDataCommand workerCommand = commands.First(command => command.ObjectName == "Worker");
            Assert.AreEqual("1", workerCommand.Parameters["CurrentDepartment"]);
        }