Пример #1
0
        public void TypePropertiesAreCorrect()
        {
            Assert.AreEqual(typeof(PromiseException).GetClassName(), "Bridge.PromiseException", "Name");
            object d = new PromiseException(new object[0]);

            Assert.True(d is PromiseException, "is PromiseException");
            Assert.True(d is Exception, "is Exception");
        }
        public void ArgumentsAndMessageConstructorWorks()
        {
            var args = new object[] { "a", 1 };
            var ex   = new PromiseException(args, "Some message");

            Assert.IsTrue((object)ex is PromiseException, "is PromiseException");
            Assert.IsTrue(ex.InnerException == null, "InnerException");
            Assert.AreEqual(ex.Arguments, args, "Arguments");
            Assert.AreEqual(ex.Message, "Some message", "Message");
        }
        public void ArgumentsAndMessageAndInnerExceptionConstructorWorks()
        {
            var inner = new Exception("a");
            var args  = new object[] { "a", 1 };
            var ex    = new PromiseException(args, "Some message", inner);

            Assert.IsTrue((object)ex is PromiseException, "is PromiseException");
            Assert.IsTrue(ReferenceEquals(ex.InnerException, inner), "InnerException");
            Assert.AreEqual(ex.Arguments, args, "Arguments");
            Assert.AreEqual(ex.Message, "Some message", "Message");
        }
Пример #4
0
        public void ArgumentsOnlyConstructorWorks()
        {
            var args = new object[] { "a", 1 };
            var ex   = new PromiseException(args);

            Assert.True((object)ex is PromiseException, "is PromiseException");
            Assert.AreEqual(args, ex.Arguments, "Arguments");
            Assert.True(ex.InnerException == null, "InnerException");
            // #1528
            Assert.AreEqual("Promise exception: [a, 1]", ex.Message, "Message");
        }
Пример #5
0
        /// <summary>
        /// Get readable error list
        /// </summary>
        /// <param name="exception"></param>
        /// <returns></returns>
        public static IEnumerable <string> GetValidationErrors(this PromiseException exception)
        {
            var errors = exception.GetValidationErrorResponse();

            foreach (var error in errors)
            {
                foreach (var errorDescription in error.Value)
                {
                    yield return($"{error.Key} {errorDescription}");
                }
            }
        }
        public void TypePropertiesAreCorrect()
        {
            Assert.AreEqual(typeof(PromiseException).FullName, "ss.PromiseException", "Name");
            Assert.IsTrue(typeof(PromiseException).IsClass, "IsClass");
            Assert.AreEqual(typeof(PromiseException).BaseType, typeof(Exception), "BaseType");
            object d = new PromiseException(new object[0]);

            Assert.IsTrue(d is PromiseException, "is PromiseException");
            Assert.IsTrue(d is Exception, "is Exception");

            var interfaces = typeof(PromiseException).GetInterfaces();

            Assert.AreEqual(interfaces.Length, 0, "Interfaces length");
        }
Пример #7
0
        /// <summary>
        /// Get error code for promise exception
        /// </summary>
        /// <param name="exception"></param>
        /// <returns></returns>
        public static int ErrorCode(this PromiseException exception)
        {
            var errorCode = (int)exception.Arguments[0].ToDynamic().status;

            return(errorCode);
        }
Пример #8
0
        /// <summary>
        /// Deserialize realworld promise exception to get errors
        /// </summary>
        /// <param name="exception"></param>
        /// <returns></returns>
        public static Dictionary <string, string[]> GetValidationErrorResponse(this PromiseException exception)
        {
            var errors = (ErrorResponse)JsonConvert.DeserializeObject <ErrorResponse>(exception.Arguments[0].ToDynamic().responseJSON);

            return(errors.Errors);
        }