Exemple #1
0
 public void TestSerializeToValue(
     CultureInfo culture,
     object clrValue,
     SpannerDbType spannerDbType,
     string expectedJsonValue,
     TestType testType = TestType.Both)
 {
     if (testType == TestType.ValueToClr)
     {
         return;
     }
     WithCulture(culture, () =>
     {
         string infoAddendum = $", type:{clrValue?.GetType().Name}, spannerType:{spannerDbType} ";
         try
         {
             string expected = expectedJsonValue;
             var jsonValue   = spannerDbType.ToProtobufValue(clrValue, options: null);
             string actual   = jsonValue.ToString();
             if (expected != actual)
             {
                 if (jsonValue.KindCase == Value.KindOneofCase.StructValue)
                 {
                     AssertJsonEqual <Struct>(expected, actual);
                 }
                 else
                 {
                     // Our error message contains an informational addendum
                     // which tells us which theory test case failed.
                     Assert.Equal(expected + infoAddendum, actual + infoAddendum);
                 }
             }
         }
         catch (Exception e)
         {
             Assert.True(false, infoAddendum + e.Message);
             throw;
         }
     });
 }
Exemple #2
0
        public void TestInvalidSerializeToValue(
            object value,
            SpannerDbType type,
            TestType testType = TestType.Both)
        {
            if (testType == TestType.ValueToClr)
            {
                return;
            }
            string infoAddendum = $"type:{value?.GetType().Name}, spannerType:{type}";

            var exceptionCaught = false;

            try
            {
                type.ToProtobufValue(value, options: null);
            }
            catch (Exception e) when(e is OverflowException || e is InvalidCastException || e is FormatException)
            {
                exceptionCaught = true;
            }
            Assert.True(exceptionCaught, infoAddendum);
        }