Exemplo n.º 1
0
        public static void NameEquals_InvalidInstance_Throws(string text)
        {
            string       ErrorMessage = new InvalidOperationException().Message;
            JsonProperty prop         = default;

            AssertExtensions.Throws <InvalidOperationException>(() => prop.NameEquals(text), ErrorMessage);
            AssertExtensions.Throws <InvalidOperationException>(() => prop.NameEquals(text.AsSpan()), ErrorMessage);
            byte[] expectedGetBytes = text == null ? null : Encoding.UTF8.GetBytes(text);
            AssertExtensions.Throws <InvalidOperationException>(() => prop.NameEquals(expectedGetBytes), ErrorMessage);
        }
Exemplo n.º 2
0
        public static void NameEquals_InvalidInstance_Throws(string text)
        {
            const string ErrorMessage = "Operation is not valid due to the current state of the object.";
            JsonProperty prop         = default;

            AssertExtensions.Throws <InvalidOperationException>(() => prop.NameEquals(text), ErrorMessage);
            AssertExtensions.Throws <InvalidOperationException>(() => prop.NameEquals(text.AsSpan()), ErrorMessage);
            byte[] expectedGetBytes = text == null ? null : Encoding.UTF8.GetBytes(text);
            AssertExtensions.Throws <InvalidOperationException>(() => prop.NameEquals(expectedGetBytes), ErrorMessage);
        }
Exemplo n.º 3
0
 private static void ReadPropertyValue(EncryptedMessage data, JsonProperty property)
 {
     if (property.NameEquals(EncryptedMessage_EncryptedMessageTextName))
     {
         data.EncryptedMessageText = property.Value.GetString();
     }
     else if (property.NameEquals(nameof(data.EncryptionData)))
     {
         data.EncryptionData = EncryptionDataSerializer.ReadEncryptionData(property.Value);
     }
 }
Exemplo n.º 4
0
 private static void ReadPropertyValue(EncryptedRegionInfo info, JsonProperty property)
 {
     if (property.NameEquals(nameof(info.NonceLength)))
     {
         info.NonceLength = property.Value.GetInt32();
     }
     else if (property.NameEquals(nameof(info.DataLength)))
     {
         info.DataLength = property.Value.GetInt32();
     }
 }
Exemplo n.º 5
0
 private static void ReadPropertyValue(EncryptionAgent agent, JsonProperty property)
 {
     if (property.NameEquals(nameof(agent.EncryptionAlgorithm)))
     {
         agent.EncryptionAlgorithm = new ClientSideEncryptionAlgorithm(property.Value.GetString());
     }
     else if (property.NameEquals(EncryptionAgent_EncryptionVersionName))
     {
         agent.EncryptionVersion = property.Value.GetString().ToClientSideEncryptionVersion();
     }
 }
Exemplo n.º 6
0
        public static void NameEquals_UseGoodMatches_True(string propertyName, string otherText)
        {
            string jsonString = $"{{ \"{propertyName}\" : \"itsValue\" }}";

            using (JsonDocument doc = JsonDocument.Parse(jsonString))
            {
                JsonElement  jElement         = doc.RootElement;
                JsonProperty property         = jElement.EnumerateObject().First();
                byte[]       expectedGetBytes = Encoding.UTF8.GetBytes(otherText);
                Assert.True(property.NameEquals(otherText));
                Assert.True(property.NameEquals(otherText.AsSpan()));
                Assert.True(property.NameEquals(expectedGetBytes));
            }
        }
Exemplo n.º 7
0
 private static void ReadPropertyValue(KeyEnvelope key, JsonProperty property)
 {
     if (property.NameEquals(nameof(key.Algorithm)))
     {
         key.Algorithm = property.Value.GetString();
     }
     else if (property.NameEquals(nameof(key.EncryptedKey)))
     {
         key.EncryptedKey = Convert.FromBase64String(property.Value.GetString());
     }
     else if (property.NameEquals(nameof(key.KeyId)))
     {
         key.KeyId = property.Value.GetString();
     }
 }
 private static void ReadPropertyValue(EncryptedMessage data, JsonProperty property)
 {
     if (property.NameEquals(EncryptedMessage_EncryptedMessageTextName))
     {
         data.EncryptedMessageText = property.Value.GetString();
     }
     else if (property.NameEquals(nameof(data.EncryptionData)))
     {
         data.EncryptionData = EncryptionDataSerializer.ReadEncryptionData(property.Value);
     }
     else
     {
         throw new FormatException($"Failed to deserialize `{typeof(EncryptedMessage).FullName}`. Unrecognized property `{property.Name}`.");
     }
 }
Exemplo n.º 9
0
        public void Verify()
        {
            Assert.IsType <JsonElement>(Array);
            ValidateArray((JsonElement)Array);
            Assert.IsType <JsonElement>(Object);
            JsonElement jsonObject = (JsonElement)Object;

            Assert.Equal(JsonValueKind.Object, jsonObject.ValueKind);
            JsonElement.ObjectEnumerator enumerator = jsonObject.EnumerateObject();
            JsonProperty property = enumerator.First();

            Assert.Equal("NestedArray", property.Name);
            Assert.True(property.NameEquals("NestedArray"));
            ValidateArray(property.Value);

            void ValidateArray(JsonElement element)
            {
                Assert.Equal(JsonValueKind.Array, element.ValueKind);
                JsonElement[] elements = element.EnumerateArray().ToArray();

                Assert.Equal(JsonValueKind.Number, elements[0].ValueKind);
                Assert.Equal("1", elements[0].ToString());
                Assert.Equal(JsonValueKind.String, elements[1].ValueKind);
                Assert.Equal("Hello", elements[1].ToString());
                Assert.Equal(JsonValueKind.True, elements[2].ValueKind);
                Assert.True(elements[2].GetBoolean());
                Assert.Equal(JsonValueKind.False, elements[3].ValueKind);
                Assert.False(elements[3].GetBoolean());
            }
        }
 private static void ReadPropertyValue(ConfigurationSetting setting, JsonProperty property)
 {
     if (property.NameEquals("content_type"))
     {
         setting.ContentType = property.Value.GetString();
     }
     else if (property.NameEquals("etag"))
     {
         setting.ETag = new ETag(property.Value.GetString());
     }
     else if (property.NameEquals("key"))
     {
         setting.Key = property.Value.GetString();
     }
     else if (property.NameEquals("label"))
     {
         setting.Label = property.Value.GetString();
     }
     else if (property.NameEquals("last_modified"))
     {
         if (property.Value.ValueKind == JsonValueKind.Null)
         {
             setting.LastModified = null;
         }
         else
         {
             setting.LastModified = DateTimeOffset.Parse(property.Value.GetString(), CultureInfo.InvariantCulture);
         }
     }
     else if (property.NameEquals("locked"))
     {
         if (property.Value.ValueKind == JsonValueKind.Null)
         {
             setting.IsReadOnly = null;
         }
         else
         {
             setting.IsReadOnly = property.Value.GetBoolean();
         }
     }
     else if (property.NameEquals("tags"))
     {
         foreach (JsonProperty element in property.Value.EnumerateObject())
         {
             setting.Tags.Add(element.Name, element.Value.GetString());
         }
     }
     else if (property.NameEquals("value"))
     {
         setting.Value = property.Value.GetString();
     }
 }
 private static void ReadPropertyValue(EncryptionData data, JsonProperty property)
 {
     if (property.NameEquals(nameof(data.EncryptionMode)))
     {
         data.EncryptionMode = property.Value.GetString();
     }
     else if (property.NameEquals(nameof(data.WrappedContentKey)))
     {
         var key = new KeyEnvelope();
         foreach (var subProperty in property.Value.EnumerateObject())
         {
             ReadPropertyValue(key, subProperty);
         }
         data.WrappedContentKey = key;
     }
     else if (property.NameEquals(nameof(data.EncryptionAgent)))
     {
         var agent = new EncryptionAgent();
         foreach (var subProperty in property.Value.EnumerateObject())
         {
             ReadPropertyValue(agent, subProperty);
         }
         data.EncryptionAgent = agent;
     }
     else if (property.NameEquals(nameof(data.ContentEncryptionIV)))
     {
         data.ContentEncryptionIV = Convert.FromBase64String(property.Value.GetString());
     }
     else if (property.NameEquals(nameof(data.KeyWrappingMetadata)))
     {
         var metadata = new Dictionary <string, string>();
         foreach (var entry in property.Value.EnumerateObject())
         {
             metadata.Add(entry.Name, entry.Value.GetString());
         }
         data.KeyWrappingMetadata = metadata;
     }
 }
Exemplo n.º 12
0
        public static void NameEquals_GivenPropertyAndValue_TrueForPropertyName()
        {
            string jsonString = $"{{ \"aPropertyName\" : \"itsValue\" }}";

            using (JsonDocument doc = JsonDocument.Parse(jsonString))
            {
                JsonElement  jElement = doc.RootElement;
                JsonProperty property = jElement.EnumerateObject().First();

                string text             = "aPropertyName";
                byte[] expectedGetBytes = Encoding.UTF8.GetBytes(text);
                Assert.True(property.NameEquals(text));
                Assert.True(property.NameEquals(text.AsSpan()));
                Assert.True(property.NameEquals(expectedGetBytes));

                text             = "itsValue";
                expectedGetBytes = Encoding.UTF8.GetBytes(text);
                Assert.False(property.NameEquals(text));
                Assert.False(property.NameEquals(text.AsSpan()));
                Assert.False(property.NameEquals(expectedGetBytes));
            }
        }
 internal static void ReadProperty(MouseEventArgs eventArgs, JsonProperty property)
 {
     if (property.NameEquals(Detail.EncodedUtf8Bytes))
     {
         eventArgs.Detail = property.Value.GetInt64();
     }
     else if (property.NameEquals(ScreenX.EncodedUtf8Bytes))
     {
         eventArgs.ScreenX = property.Value.GetDouble();
     }
     else if (property.NameEquals(ScreenY.EncodedUtf8Bytes))
     {
         eventArgs.ScreenY = property.Value.GetDouble();
     }
     else if (property.NameEquals(ClientX.EncodedUtf8Bytes))
     {
         eventArgs.ClientX = property.Value.GetDouble();
     }
     else if (property.NameEquals(ClientY.EncodedUtf8Bytes))
     {
         eventArgs.ClientY = property.Value.GetDouble();
     }
     else if (property.NameEquals(OffsetX.EncodedUtf8Bytes))
     {
         eventArgs.OffsetX = property.Value.GetDouble();
     }
     else if (property.NameEquals(OffsetY.EncodedUtf8Bytes))
     {
         eventArgs.OffsetY = property.Value.GetDouble();
     }
     else if (property.NameEquals(Button.EncodedUtf8Bytes))
     {
         eventArgs.Button = property.Value.GetInt64();
     }
     else if (property.NameEquals(Buttons.EncodedUtf8Bytes))
     {
         eventArgs.Buttons = property.Value.GetInt64();
     }
     else if (property.NameEquals(CtrlKey.EncodedUtf8Bytes))
     {
         eventArgs.CtrlKey = property.Value.GetBoolean();
     }
     else if (property.NameEquals(ShiftKey.EncodedUtf8Bytes))
     {
         eventArgs.ShiftKey = property.Value.GetBoolean();
     }
     else if (property.NameEquals(AltKey.EncodedUtf8Bytes))
     {
         eventArgs.AltKey = property.Value.GetBoolean();
     }
     else if (property.NameEquals(MetaKey.EncodedUtf8Bytes))
     {
         eventArgs.MetaKey = property.Value.GetBoolean();
     }
     else if (property.NameEquals(Type.EncodedUtf8Bytes))
     {
         eventArgs.Type = property.Value.GetString() !;
     }
     else
     {
         throw new JsonException($"Unknown property {property.Name}");
     }
 }