コード例 #1
0
#pragma warning restore CS3016 // Arrays as attribute arguments is not CLS-compliant
        public void RoundTrip(List <Claim> claims, JwtPayload payloadSetDirect, JwtPayload payloadSetUsingDeserialize)
        {
            var context             = new CompareContext();
            var payload             = new JwtPayload(claims);
            var encodedPayload      = payload.SerializeToJson();
            var payloadDeserialized = JwtPayload.Deserialize(encodedPayload);
            var instanceContext     = new CompareContext();

            IdentityComparer.AreEqual(payload, payloadDeserialized, instanceContext);
            context.Merge(string.Format(CultureInfo.InvariantCulture, "AreEqual({0}, {1})", nameof(payload), nameof(payloadDeserialized)), instanceContext);

            instanceContext = new CompareContext();
            IdentityComparer.AreEqual(payload, payloadSetDirect, instanceContext);
            context.Merge(string.Format(CultureInfo.InvariantCulture, "AreEqual({0}, {1})", nameof(payload), nameof(payloadSetDirect)), instanceContext);

            instanceContext = new CompareContext();
            IdentityComparer.AreEqual(payload, payloadSetUsingDeserialize, instanceContext);
            context.Merge(string.Format(CultureInfo.InvariantCulture, "AreEqual({0}, {1})", nameof(payload), nameof(payloadSetUsingDeserialize)), instanceContext);

            instanceContext.Diffs.Clear();
            IdentityComparer.AreEqual(payload.Claims, claims, instanceContext);
            context.Merge(string.Format(CultureInfo.InvariantCulture, "AreEqual({0}, {1})", nameof(payload.Claims), nameof(claims)), instanceContext);

            instanceContext.Diffs.Clear();
            CheckClaimsTypeParsing(payload.Claims, instanceContext);
            context.Merge(string.Format(CultureInfo.InvariantCulture, "CheckClaimsTypeParsing({0})", nameof(payload.Claims)), instanceContext);

            instanceContext.Diffs.Clear();
            CheckClaimsTypeParsing(payloadDeserialized.Claims, instanceContext);
            context.Merge(string.Format(CultureInfo.InvariantCulture, "CheckClaimsTypeParsing({0})", nameof(payloadDeserialized.Claims)), instanceContext);

            TestUtilities.AssertFailIfErrors(context);
        }
コード例 #2
0
        public static bool AreDateTimesEqual(DateTime?date1, DateTime?date2, CompareContext context)
        {
            var localContext = new CompareContext(context);

            if (!IdentityComparer.ContinueCheckingEquality(date1, date2, localContext))
            {
                return(context.Merge(localContext));
            }

            if (!date1.Equals(date2))
            {
                context.Diffs.Add($"dates are not equal: '{date1}' : '{date2}'");
                return(false);
            }

            return(true);
        }
コード例 #3
0
        public static bool AreStringsEqual(string str1, string str2, CompareContext context)
        {
            var localContext = new CompareContext(context);

            if (!IdentityComparer.ContinueCheckingEquality(str1, str2, localContext))
            {
                return(context.Merge(localContext));
            }

            if (!str1.Equals(str2))
            {
                context.Diffs.Add($"strings are not equal: '{str1}' : '{str2}'");
                return(false);
            }

            return(true);
        }
コード例 #4
0
        public static bool AreUrisEqual(Uri uri1, Uri uri2, CompareContext context)
        {
            var localContext = new CompareContext(context);

            if (!IdentityComparer.ContinueCheckingEquality(uri1, uri2, localContext))
            {
                return(context.Merge(localContext));
            }

            var str1 = uri1.OriginalString;
            var str2 = uri2.OriginalString;

            if (!str1.Equals(str2))
            {
                context.Diffs.Add($"uris are not equal: '{str1}' : '{str2}'");
                return(false);
            }

            return(true);
        }