Ejemplo n.º 1
0
        public void ParseLiteral_StringValueNode()
        {
            // arrange
            var uuidType = new UuidType();
            var expected = Guid.NewGuid();
            var literalA = new StringValueNode(expected.ToString("N"));
            var literalB = new StringValueNode(expected.ToString("P"));

            // act
            var runtimeValueA = (Guid)uuidType.ParseLiteral(literalA) !;
            var runtimeValueB = (Guid)uuidType.ParseLiteral(literalB) !;

            // assert
            Assert.Equal(expected, runtimeValueA);
            Assert.Equal(expected, runtimeValueB);
        }
Ejemplo n.º 2
0
        public void ParseLiteral_Null()
        {
            // arrange
            var uuidType = new UuidType();

            // act
            Action action = () => uuidType.ParseLiteral(null);

            // assert
            Assert.Throws <ArgumentNullException>(action);
        }
Ejemplo n.º 3
0
        public void ParseLiteral_NullValueNode()
        {
            // arrange
            var           uuidType = new UuidType();
            NullValueNode literal  = NullValueNode.Default;

            // act
            var value = uuidType.ParseLiteral(literal);

            // assert
            Assert.Null(value);
        }
Ejemplo n.º 4
0
        public void ParseLiteral_IntValueNode()
        {
            // arrange
            var uuidType = new UuidType();
            var literal  = new IntValueNode(123);

            // act
            Action action = () => uuidType.ParseLiteral(literal);

            // assert
            Assert.Throws <ScalarSerializationException>(action);
        }
Ejemplo n.º 5
0
        public void Parse_Guid_Valid_Input(bool enforceFormat)
        {
            // arrange
            var input    = new StringValueNode("fbdef721-93c5-4267-8f92-ca27b60aa51f");
            var uuidType = new UuidType(defaultFormat: 'D', enforceFormat: enforceFormat);

            // act
            var guid = (Guid)uuidType.ParseLiteral(input) !;

            // assert
            Assert.Equal(input.Value, guid.ToString("D"));
        }
Ejemplo n.º 6
0
        public void Parse_Guid_String_With_Appended_String(bool enforceFormat)
        {
            // arrange
            var input    = new StringValueNode("fbdef721-93c5-4267-8f92-ca27b60aa51f-foobar");
            var uuidType = new UuidType(defaultFormat: 'D', enforceFormat: enforceFormat);

            // act
            void Fail() => uuidType.ParseLiteral(input);

            // assert
            Assert.Throws <SerializationException>(Fail);
        }
Ejemplo n.º 7
0
        public void ParseLiteral_With_Format(char format)
        {
            // arrange
            var  uuidType = new UuidType(defaultFormat: format);
            Guid guid     = Guid.Empty;
            var  literal  = new StringValueNode(guid.ToString(format.ToString()));

            // act
            var deserialized = (Guid)uuidType.ParseLiteral(literal) !;

            // assert
            Assert.Equal(guid, deserialized);
        }
Ejemplo n.º 8
0
        public void ParseLiteral_StringValueNode_Enforce_Format()
        {
            // arrange
            var uuidType = new UuidType(defaultFormat: 'P', enforceFormat: true);
            var expected = Guid.NewGuid();
            var literal  = new StringValueNode(expected.ToString("N"));

            // act
            void Action() => uuidType.ParseLiteral(literal);

            // assert
            Assert.Throws <SerializationException>(Action);
        }
Ejemplo n.º 9
0
        public void ParseLiteral_StringValueNode()
        {
            // arrange
            var uuidType = new UuidType();
            var expected = Guid.NewGuid();
            var literal  = new StringValueNode(expected.ToString());

            // act
            var actual = (Guid)uuidType
                         .ParseLiteral(literal);

            // assert
            Assert.Equal(expected, actual);
        }