public void TestSerialization()
        {
            const string message = "MESSAGE";

            var ex = new Exception(message + ".INNER");

            const string path = "PATH";

            var x = new TypeMismatchException(null, path, message, ex);

            var serializer = new BinaryFormatter();

            byte[] buffer;
            using (var stream = new MemoryStream())
            {
                serializer.Serialize(stream, x);
                buffer = stream.ToArray();
            }

            TypeMismatchException y = null;

            using (var stream = new MemoryStream(buffer))
            {
                y = (TypeMismatchException)serializer.Deserialize(stream);
            }

            Assert.NotNull(y);
            Assert.Equal(message, y.Message);
            Assert.Equal(ex.Message, y.InnerException.Message);
            Assert.Equal(path, y.ConfigurationPath);
        }
Ejemplo n.º 2
0
        public void TypeMismatchExceptionConstructorTest()
        {
            Type expectedType = typeof(string);
            Type actualType   = typeof(int);
            var  target       = new TypeMismatchException(expectedType, actualType);

            Assert.IsNotNull(target);
        }
Ejemplo n.º 3
0
        public void ExpectedTypeTest()
        {
            Type expectedType = typeof(string);
            Type actualType   = typeof(int);
            var  target       = new TypeMismatchException(expectedType, actualType);

            target.ExpectedType = expectedType;
            Assert.AreEqual(expectedType, target.ExpectedType);
        }
        public void TestException1()
        {
            var x = new TypeMismatchException(null);

            Assert.NotNull(x);
            Assert.Equal($"Exception of type '{typeof(TypeMismatchException).FullName}' was thrown.", x.Message);
            Assert.Null(x.InnerException);
            Assert.Null(x.ConfigurationPath);
        }
        public void TestException2()
        {
            const string message = "MESSAGE";

            var x = new TypeMismatchException(null, message);

            Assert.NotNull(x);
            Assert.Equal(message, x.Message);
            Assert.Null(x.InnerException);
            Assert.Null(x.ConfigurationPath);
        }
        public void TestException4()
        {
            const string message = "MESSAGE";

            var ex = new Exception(message + ".INNER");

            const string path = "PATH";

            var x = new TypeMismatchException(null, path, message, ex);

            Assert.NotNull(x);
            Assert.Equal(message, x.Message);
            Assert.Equal(ex, x.InnerException);
            Assert.Equal(path, x.ConfigurationPath);
        }
Ejemplo n.º 7
0
        public void InstantiationSupplyingNullPropertyChangeArgsAndNullType()
        {
            TypeMismatchException ex = new TypeMismatchException(null, null, null);

            Assert.AreEqual("typeMismatch", ex.ErrorCode);
        }
Ejemplo n.º 8
0
        public void InstantiationSupplyingPropertyChangeArgsTypeAndRootException()
        {
            TypeMismatchException ex = new TypeMismatchException(new PropertyChangeEventArgs("Doctor", new NestedTestObject("Foo"), new TestObject("Hershey", 12)), typeof(INestedTestObject), null);

            Assert.AreEqual("typeMismatch", ex.ErrorCode);
        }
Ejemplo n.º 9
0
		/// <summary>
		/// TypeMismatchException中获取到参数错误类型
		/// </summary>
		/// <param name="e"> </param>
		private ModelAndView getParamErrors(TypeMismatchException e)
		{

			Exception t = e.InnerException;

			if (t is ConversionFailedException)
			{

				ConversionFailedException x = (ConversionFailedException) t;
				TypeDescriptor type = x.TargetType;
				Annotation[] annotations = type != null ? type.GetCustomAttributes(true) : new Annotation[0];
				IDictionary<string, string> errors = new Dictionary<string, string>();
				foreach (Annotation a in annotations)
				{
					if (a is RequestParam)
					{
						errors[((RequestParam) a).value()] = "parameter type error!";
					}
				}
				if (errors.Count > 0)
				{
					return paramError(errors, ErrorCode.TYPE_MIS_MATCH);
				}
			}

			JsonObjectBase jsonObject = JsonObjectUtils.buildGlobalError("parameter type error!", ErrorCode.TYPE_MIS_MATCH);
			return JsonObjectUtils.JsonObjectError2ModelView((JsonObjectError) jsonObject);
		}