From c599731b3f21a6b931a22928071c94cab1815098 Mon Sep 17 00:00:00 2001 From: Matias Quaranta Date: Tue, 22 Mar 2022 16:21:26 -0700 Subject: [PATCH 1/3] fixing error message --- src/CosmosCacheSessionConverter.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/CosmosCacheSessionConverter.cs b/src/CosmosCacheSessionConverter.cs index c909def..53e489a 100644 --- a/src/CosmosCacheSessionConverter.cs +++ b/src/CosmosCacheSessionConverter.cs @@ -36,14 +36,14 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist if (!jObject.TryGetValue(CosmosCacheSessionConverter.IdAttributeName, out JToken idJToken)) { - throw new JsonReaderException("Missing id on Cosmos DB session item."); + throw new JsonReaderException("Missing 'id' on Cosmos DB session item."); } cosmosCacheSession.SessionKey = idJToken.Value(); if (!jObject.TryGetValue(CosmosCacheSessionConverter.ContentAttributeName, out JToken contentJToken)) { - throw new JsonReaderException("Missing id on Cosmos DB session item."); + throw new JsonReaderException("Missing 'content' on Cosmos DB session item."); } cosmosCacheSession.Content = Convert.FromBase64String(contentJToken.Value()); From 59d497dffaf1fd6e4179872328d2520d6f9a4dda Mon Sep 17 00:00:00 2001 From: Matias Quaranta Date: Tue, 22 Mar 2022 16:25:14 -0700 Subject: [PATCH 2/3] test --- tests/unit/CosmosSessionSerializationTests.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/unit/CosmosSessionSerializationTests.cs b/tests/unit/CosmosSessionSerializationTests.cs index 399d8f7..176a785 100644 --- a/tests/unit/CosmosSessionSerializationTests.cs +++ b/tests/unit/CosmosSessionSerializationTests.cs @@ -78,5 +78,17 @@ public void ValidatesContract() string serialized = JsonConvert.SerializeObject(existingSession); Assert.Equal(expectedContract , serialized); } + + [Fact] + public void MissingRequiredProperties() + { + const string withoutId = "{\"content\":\"AQ==\",\"ttl\":5,\"isSlidingExpiration\":true,\"absoluteSlidingExpiration\":10}"; + JsonReaderException withoutIdException = Assert.Throws(() => JsonConvert.DeserializeObject(withoutId)); + Assert.Contains("Missing 'id'", withoutIdException.Message); + + const string withoutContent = "{\"id\":\"1\", \"ttl\":5,\"isSlidingExpiration\":true,\"absoluteSlidingExpiration\":10}"; + JsonReaderException withoutContentException = Assert.Throws(() => JsonConvert.DeserializeObject(withoutContent)); + Assert.Contains("Missing 'content'", withoutContentException.Message); + } } } \ No newline at end of file From 8e8e89bfefaa97fd79a9f86d874e6aeaca2a2764 Mon Sep 17 00:00:00 2001 From: Matias Quaranta Date: Tue, 22 Mar 2022 16:27:25 -0700 Subject: [PATCH 3/3] changelog --- changelog.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/changelog.md b/changelog.md index 1718807..6e261a4 100644 --- a/changelog.md +++ b/changelog.md @@ -4,6 +4,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ## Unreleased +### Fixed + +- [#62](https://github.com/Azure/Microsoft.Extensions.Caching.Cosmos/pull/62) Fixed error text to point to correct missing property when deserializing session object + ## 1.2.0 - 2022-02-23 ### Added