public void TestDictionarySerialization()
        {
            var accessor = CreateTokenCacheAccessor();

            var s1 = new TokenCacheDictionarySerializer(accessor);

            byte[] bytes = s1.Serialize(null);
            string json  = new UTF8Encoding().GetString(bytes);

            var otherAccessor = new InMemoryTokenCacheAccessor(Substitute.For <ICoreLogger>());
            var s2            = new TokenCacheDictionarySerializer(otherAccessor);

            s2.Deserialize(bytes, false);

            AssertAccessorsAreEqual(accessor, otherAccessor);
        }
        public void TestDictionarySerialization()
        {
            var accessor = CreateTokenCacheAccessor();

            var s1 = new TokenCacheDictionarySerializer(accessor);

            byte[] bytes = s1.Serialize(null);
            string json  = new UTF8Encoding().GetString(bytes);

            // TODO(cache): assert json value?  or look at JObject?

            var otherAccessor = new InMemoryTokenCacheAccessor();
            var s2            = new TokenCacheDictionarySerializer(otherAccessor);

            s2.Deserialize(bytes, false);

            AssertAccessorsAreEqual(accessor, otherAccessor);
        }
        public void TestMsalNet2XCacheSerializationInterop()
        {
            var    accessor    = new InMemoryTokenCacheAccessor(Substitute.For <ICoreLogger>());
            var    s           = new TokenCacheDictionarySerializer(accessor);
            string binFilePath = ResourceHelper.GetTestResourceRelativePath("cachecompat_dotnet_dictionary.bin");

            byte[] bytes = File.ReadAllBytes(binFilePath);
            s.Deserialize(bytes, false);

            Assert.AreEqual(1, accessor.GetAllAccessTokens().Count());
            Assert.AreEqual(1, accessor.GetAllRefreshTokens().Count());
            Assert.AreEqual(1, accessor.GetAllIdTokens().Count());
            Assert.AreEqual(1, accessor.GetAllAccounts().Count());
            Assert.AreEqual(0, accessor.GetAllAppMetadata().Count());

            var expectedAccessTokenItem = new MsalAccessTokenCacheItem("User.Read User.ReadBasic.All profile openid email")
            {
                AdditionalFieldsJson           = "{\r\n  \"access_token_type\": \"Bearer\"\r\n}",
                Environment                    = "login.windows.net",
                HomeAccountId                  = "13dd2c19-84cd-416a-ae7d-49573e425619.26039cce-489d-4002-8293-5b0c5134eacb",
                RawClientInfo                  = string.Empty,
                ClientId                       = "b945c513-3946-4ecd-b179-6499803a2167",
                TenantId                       = "26039cce-489d-4002-8293-5b0c5134eacb",
                CachedAt                       = "1548803419",
                ExpiresOnUnixTimestamp         = "1548846619",
                ExtendedExpiresOnUnixTimestamp = "1548846619",
                UserAssertionHash              = string.Empty,
                TokenType                      = StorageJsonValues.TokenTypeBearer
            };

            AssertAccessTokenCacheItemsAreEqual(expectedAccessTokenItem, accessor.GetAllAccessTokens().First());

            var expectedRefreshTokenItem = new MsalRefreshTokenCacheItem
            {
                Environment   = "login.windows.net",
                HomeAccountId = "13dd2c19-84cd-416a-ae7d-49573e425619.26039cce-489d-4002-8293-5b0c5134eacb",
                RawClientInfo = string.Empty,
                ClientId      = "b945c513-3946-4ecd-b179-6499803a2167"
            };

            AssertRefreshTokenCacheItemsAreEqual(expectedRefreshTokenItem, accessor.GetAllRefreshTokens().First());

            var expectedIdTokenItem = new MsalIdTokenCacheItem
            {
                Environment   = "login.windows.net",
                HomeAccountId = "13dd2c19-84cd-416a-ae7d-49573e425619.26039cce-489d-4002-8293-5b0c5134eacb",
                RawClientInfo = string.Empty,
                ClientId      = "b945c513-3946-4ecd-b179-6499803a2167",
                TenantId      = "26039cce-489d-4002-8293-5b0c5134eacb"
            };

            AssertIdTokenCacheItemsAreEqual(expectedIdTokenItem, accessor.GetAllIdTokens().First());

            var expectedAccountItem = new MsalAccountCacheItem
            {
                Environment       = "login.windows.net",
                HomeAccountId     = "13dd2c19-84cd-416a-ae7d-49573e425619.26039cce-489d-4002-8293-5b0c5134eacb",
                RawClientInfo     = "eyJ1aWQiOiIxM2RkMmMxOS04NGNkLTQxNmEtYWU3ZC00OTU3M2U0MjU2MTkiLCJ1dGlkIjoiMjYwMzljY2UtNDg5ZC00MDAyLTgyOTMtNWIwYzUxMzRlYWNiIn0",
                PreferredUsername = "******",
                Name           = "Abhi Test",
                GivenName      = string.Empty,
                FamilyName     = string.Empty,
                LocalAccountId = "13dd2c19-84cd-416a-ae7d-49573e425619",
                TenantId       = "26039cce-489d-4002-8293-5b0c5134eacb"
            };

            AssertAccountCacheItemsAreEqual(expectedAccountItem, accessor.GetAllAccounts().First());
        }