Exemple #1
0
        public void TestNewSerializeClassWithId()
        {
            var testObject = new TestClassWithId()
            {
                Id             = 123,
                BoolArray      = new bool[0],
                BoolEnumerable = new List <bool>()
                {
                    true, false
                },
                BoolList = new List <bool>()
                {
                    true
                },
                BoolProperty   = false,
                DateTime       = new DateTime(2020, 10, 25, 13, 24, 25),
                DoubleProperty = -1.1,
                IntProperty    = 0,
                StringProperty = "string value",
                TestEnum1      = TestEnum1.First,
            };
            var triples = testObject.ToTriples().ToList();

            Assert.NotNull(triples);
            Assert.NotEmpty(triples);

            var actual = triples.ToNTriples11().ToList();

            var expected = new List <string>()
            {
                "<http://example.rdf/1> <http://example.rdf/Id> \"123\"^^<http://www.w3.org/2001/XMLSchema#integer> .",
                "<http://example.rdf/1> <http://example.rdf/StringProperty> \"string value\"^^<http://www.w3.org/2001/XMLSchema#string> .",
                "<http://example.rdf/1> <http://example.rdf/IntProperty> \"0\"^^<http://www.w3.org/2001/XMLSchema#integer> .",
                "<http://example.rdf/1> <http://example.rdf/DoubleProperty> \"-1.1\"^^<http://www.w3.org/2001/XMLSchema#double> .",
                "<http://example.rdf/1> <http://example.rdf/DateTime> \"2020-10-25T13:24:25.000000\"^^<http://www.w3.org/2001/XMLSchema#dateTime> .",
                "<http://example.rdf/1> <http://example.rdf/BoolProperty> \"false\"^^<http://www.w3.org/2001/XMLSchema#boolean> .",
                "<http://example.rdf/1> <http://example.rdf/BoolEnumerable> \"true\"^^<http://www.w3.org/2001/XMLSchema#boolean> .",
                "<http://example.rdf/1> <http://example.rdf/BoolEnumerable> \"false\"^^<http://www.w3.org/2001/XMLSchema#boolean> .",
                "<http://example.rdf/1> <http://example.rdf/BoolList> \"true\"^^<http://www.w3.org/2001/XMLSchema#boolean> .",
                "<http://example.rdf/1> <http://example.rdf/TestEnum1> \"0\"^^<http://www.w3.org/2001/XMLSchema#integer> .",
            };

            foreach (var item in expected)
            {
                Assert.Contains(item, actual);
            }

            foreach (var item in actual)
            {
                Assert.Contains(item, expected);
            }

            //TODO: What about the Enum?
            //TODO: What about the NullString?
            //TODO: Fails when a collection (e.g.:BoolEnumerable) has 2 times true; It only shows one
            //TODO: DateTime ToString is different in Windows and Linux.
            Assert.Equal(expected.Count, actual.Count());
            Assert.Empty(expected.Except(actual));
        }
Exemple #2
0
        public void TestSerializeClassWithId()
        {
            var testObject = new TestClassWithId()
            {
                Id             = 123,
                BoolArray      = new bool[0],
                BoolEnumerable = new List <bool>()
                {
                    true, false
                },
                BoolList = new List <bool>()
                {
                    true
                },
                BoolProperty   = false,
                DateTime       = new DateTime(2020, 10, 25, 13, 24, 25),
                DoubleProperty = -1.1,
                IntProperty    = 0,
                StringProperty = "string value",
                TestEnum1      = TestEnum1.First,
            };
            var graph = testObject.SerializeRdf();

            Assert.NotNull(graph);
            var actual = graph.ToNTriples11();

            var expected = new List <string>()
            {
                "<http://example.rdf/123> <http://example.rdf/Id> \"123\" .",
                "<http://example.rdf/123> <http://example.rdf/StringProperty> \"string value\" .",
                "<http://example.rdf/123> <http://example.rdf/DoubleProperty> \"-1.1\" .",
                "<http://example.rdf/123> <http://example.rdf/IntProperty> \"0\" .",
                "<http://example.rdf/123> <http://example.rdf/TestEnum1> \"0\" .",
                "<http://example.rdf/123> <http://example.rdf/DateTime> \"2020-10-25 13:24:25\" .",
                "<http://example.rdf/123> <http://example.rdf/BoolProperty> \"False\" .",
                "<http://example.rdf/123> <http://example.rdf/BoolEnumerable> \"True\" .",
                "<http://example.rdf/123> <http://example.rdf/BoolEnumerable> \"False\" .",
                "<http://example.rdf/123> <http://example.rdf/BoolList> \"True\" .",
                "<http://example.rdf/123> <http://example.rdf/NullString> \"\" .",
            };

            foreach (var item in expected)
            {
                Assert.Contains(item, actual);
            }

            foreach (var item in actual)
            {
                Assert.Contains(item, expected);
            }

            //TODO: What about the Enum?
            //TODO: What about the NullString?
            //TODO: Fails when a collection (e.g.:BoolEnumerable) has 2 times true; It only shows one
            //TODO: DateTime ToString is different in Windows and Linux.
            Assert.Equal(expected.Count, actual.Count());
            Assert.Empty(expected.Except(actual));
        }