示例#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));
        }
        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"]);
        }
        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"]);
        }
        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"]);
        }
        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"]);
        }
        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"]);
        }
        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"));
        }
        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);
        }
        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"]);
        }