Beispiel #1
0
        public void EnsureDateTypeKindIsCorret()
        {
            // arrange
            var type = new UuidType();

            // assert
            Assert.Equal(TypeKind.Scalar, type.Kind);
        }
Beispiel #2
0
        public void IsInstanceOfType_Null()
        {
            // arrange
            var uuidType = new UuidType();

            // act
            void Action() => uuidType.IsInstanceOfType(null !);

            // assert
            Assert.Throws <ArgumentNullException>(Action);
        }
Beispiel #3
0
        public void ParseLiteral_Null()
        {
            // arrange
            var uuidType = new UuidType();

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

            // assert
            Assert.Throws <ArgumentNullException>(action);
        }
Beispiel #4
0
        public void Serialize_Null()
        {
            // arrange
            var uuidType = new UuidType();

            // act
            var serializedValue = uuidType.Serialize(null);

            // assert
            Assert.Null(serializedValue);
        }
Beispiel #5
0
        public void Serialize_With_Format(char format)
        {
            // arrange
            var  uuidType = new UuidType(defaultFormat: format);
            Guid guid     = Guid.Empty;

            // act
            string s = (string)uuidType.Serialize(guid) !;

            // assert
            Assert.Equal(guid.ToString(format.ToString()), s);
        }
Beispiel #6
0
        public void ParseValue_Int()
        {
            // arrange
            var uuidType = new UuidType();
            var value    = 123;

            // act
            void Action() => uuidType.ParseValue(value);

            // assert
            Assert.Throws <SerializationException>(Action);
        }
Beispiel #7
0
        public void IsInstanceOfType_NullLiteral()
        {
            // arrange
            var uuidType = new UuidType();
            var literal  = new NullValueNode(null);

            // act
            var isOfType = uuidType.IsInstanceOfType(literal);

            // assert
            Assert.True(isOfType);
        }
Beispiel #8
0
        public void IsInstanceOfType_StringLiteral()
        {
            // arrange
            var uuidType = new UuidType();
            var guid     = Guid.NewGuid();

            // act
            var isOfType = uuidType.IsInstanceOfType(guid);

            // assert
            Assert.True(isOfType);
        }
Beispiel #9
0
        public void IsInstanceOf_Guid_Valid_Format(bool enforceFormat)
        {
            // arrange
            var input    = new StringValueNode("fbdef721-93c5-4267-8f92-ca27b60aa51f");
            var uuidType = new UuidType(defaultFormat: 'D', enforceFormat: enforceFormat);

            // act
            var result = uuidType.IsInstanceOfType(input);

            // assert
            Assert.True(result);
        }
Beispiel #10
0
        public void IsInstanceOf_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
            var result = uuidType.IsInstanceOfType(input);

            // assert
            Assert.False(result);
        }
Beispiel #11
0
        public void Deserialize_Guid_Valid_Format(bool enforceFormat)
        {
            // arrange
            var input    = "fbdef721-93c5-4267-8f92-ca27b60aa51f";
            var uuidType = new UuidType(defaultFormat: 'D', enforceFormat: enforceFormat);

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

            // assert
            Assert.Equal(input, guid.ToString("D"));
        }
Beispiel #12
0
        public void ParseValue_With_Format(char format)
        {
            // arrange
            var  uuidType = new UuidType(defaultFormat: format);
            Guid guid     = Guid.Empty;

            // act
            var s = (StringValueNode)uuidType.ParseValue(guid);

            // assert
            Assert.Equal(guid.ToString(format.ToString()), s.Value);
        }
Beispiel #13
0
        public void IsInstanceOfType_IntLiteral()
        {
            // arrange
            var uuidType = new UuidType();
            var literal  = new IntValueNode(123);

            // act
            var isOfType = uuidType.IsInstanceOfType(literal);

            // assert
            Assert.False(isOfType);
        }
Beispiel #14
0
        public void Serialize_Int()
        {
            // arrange
            var uuidType = new UuidType();
            var value    = 123;

            // act
            Action action = () => uuidType.Serialize(value);

            // assert
            Assert.Throws <ScalarSerializationException>(action);
        }
Beispiel #15
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"));
        }
Beispiel #16
0
        public void IsInstanceOfType_Null()
        {
            // arrange
            var uuidType = new UuidType();
            var guid     = Guid.NewGuid();

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

            // assert
            Assert.Throws <ArgumentNullException>(action);
        }
Beispiel #17
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);
        }
Beispiel #18
0
        public void ParseLiteral_NullValueNode()
        {
            // arrange
            var           uuidType = new UuidType();
            NullValueNode literal  = NullValueNode.Default;

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

            // assert
            Assert.Null(value);
        }
Beispiel #19
0
        public void Deserialize_Null()
        {
            // arrange
            var uuidType = new UuidType();

            // act
            var success = uuidType.TryDeserialize(null, out object o);

            // assert
            Assert.True(success);
            Assert.Null(o);
        }
Beispiel #20
0
        public void Deserialize_Int()
        {
            // arrange
            var uuidType = new UuidType();
            var value    = 123;

            // act
            var success = uuidType.TryDeserialize(value, out _);

            // assert
            Assert.False(success);
        }
Beispiel #21
0
        public void Serialize_Guid()
        {
            // arrange
            var uuidType = new UuidType();
            var guid     = Guid.NewGuid();

            // act
            object?serializedValue = uuidType.Serialize(guid);

            // assert
            Assert.Equal(guid.ToString("N"), Assert.IsType <string>(serializedValue));
        }
Beispiel #22
0
        public void Deserialize_Guid_String_With_Appended_String(bool enforceFormat)
        {
            // arrange
            var input    = "fbdef721-93c5-4267-8f92-ca27b60aa51f-foobar";
            var uuidType = new UuidType(defaultFormat: 'D', enforceFormat: enforceFormat);

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

            // assert
            Assert.Throws <SerializationException>(Fail);
        }
Beispiel #23
0
        public void IsInstanceOfType_StringLiteral()
        {
            // arrange
            var uuidType = new UuidType();
            var guid     = Guid.NewGuid();
            var literal  = new StringValueNode(guid.ToString("N"));

            // act
            bool isOfType = uuidType.IsInstanceOfType(guid);

            // assert
            Assert.True(isOfType);
        }
Beispiel #24
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);
        }
Beispiel #25
0
        public void Serialize_Guid()
        {
            // arrange
            var uuidType      = new UuidType();
            var guid          = Guid.NewGuid();
            var expectedValue = guid.ToString("N");

            // act
            var serializedValue = uuidType.Serialize(guid);

            // assert
            Assert.Equal(guid, Assert.IsType <Guid>(serializedValue));
        }
Beispiel #26
0
        public void ParseValue_Guid()
        {
            // arrange
            var uuidType             = new UuidType();
            var expected             = Guid.NewGuid();
            var expectedLiteralValue = expected.ToString("N");

            // act
            var stringLiteral = (StringValueNode)uuidType.ParseValue(expected);

            // assert
            Assert.Equal(expectedLiteralValue, stringLiteral.Value);
        }
Beispiel #27
0
        public void ParseValue_Null()
        {
            // arrange
            var  uuidType = new UuidType();
            Guid?guid     = null;

            // act
            IValueNode stringLiteral = uuidType.ParseValue(guid);

            // assert
            Assert.True(stringLiteral is NullValueNode);
            Assert.Null(((NullValueNode)stringLiteral).Value);
        }
Beispiel #28
0
        public void Deserialize_Guid()
        {
            // arrange
            var uuidType = new UuidType();
            var guid     = Guid.NewGuid();

            // act
            var success = uuidType.TryDeserialize(guid, out object o);

            // assert
            Assert.True(success);
            Assert.Equal(guid, o);
        }
Beispiel #29
0
        public void Deserialize_With_Format(char format)
        {
            // arrange
            var    uuidType   = new UuidType(defaultFormat: format);
            Guid   guid       = Guid.Empty;
            string serialized = guid.ToString(format.ToString());

            // act
            var deserialized = (Guid)uuidType.Deserialize(serialized) !;

            // assert
            Assert.Equal(guid, deserialized);
        }
Beispiel #30
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);
        }