public void Constructor(byte[] key, EE ee)
 {
     try
     {
         var symmetricSecurityKey = new SymmetricSecurityKey(key);
         ee.ProcessNoException();
     }
     catch (Exception exception)
     {
         ee.ProcessException(exception);
     }
 }
Example #2
0
        public static ClaimsPrincipal ValidateToken(string securityToken, TokenValidationParameters validationParameters, ISecurityTokenValidator tokenValidator, ExpectedException expectedException)
        {
            ClaimsPrincipal retVal = null;

            try
            {
                retVal = tokenValidator.ValidateToken(securityToken, validationParameters, out SecurityToken validatedToken);
                expectedException.ProcessNoException();
            }
            catch (Exception ex)
            {
                expectedException.ProcessException(ex);
            }

            return(retVal);
        }
        /// <summary>
        /// Sets a property, then checks it, checking for an expected exception.
        /// </summary>
        /// <param name="obj">object that has a 'setter'.</param>
        /// <param name="property">the name of the property.</param>
        /// <param name="propertyValue">value to set on the property.</param>
        /// <param name="expectedException">checks that exception is correct.</param>
        public static void SetGet(object obj, string property, object propertyValue, ExpectedException expectedException, GetSetContext context)
        {
            if (obj == null)
            {
                throw new TestException("obj == null");
            }

            if (string.IsNullOrWhiteSpace(property))
            {
                throw new TestException("string.IsNullOrWhiteSpace(property)");
            }

            Type         type         = obj.GetType();
            PropertyInfo propertyInfo = type.GetProperty(property);

            if (propertyInfo == null)
            {
                context.Errors.Add("'get is not found for property: '" + property + "', type: '" + type.ToString() + "'");
                return;
            }

            if (!propertyInfo.CanWrite)
            {
                context.Errors.Add("can not write to property: '" + property + "', type: '" + type.ToString() + "'");
                return;
            }

            var compareContext = new CompareContext();

            try
            {
                propertyInfo.SetValue(obj, propertyValue);
                object retval = propertyInfo.GetValue(obj);
                IdentityComparer.AreEqual(propertyValue, retval, compareContext);
                expectedException.ProcessNoException(compareContext);
            }
            catch (Exception exception)
            {
                // look for InnerException as exception is a wrapped exception.
                expectedException.ProcessException(exception.InnerException, compareContext);
            }

            context.Errors.AddRange(compareContext.Diffs);
        }