예제 #1
0
        public void TestSerialization()
        {
            const string message = "MESSAGE";

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

            const string propertyName = "PROPERTY_NAME";

            var x = new InvalidPropertyException(propertyName, message, ex);

            var serializer = new BinaryFormatter();

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

            InvalidPropertyException y = null;

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

            Assert.NotNull(y);
            Assert.Equal(message, y.Message);
            Assert.Equal(ex.Message, y.InnerException.Message);
            Assert.Equal(propertyName, y.PropertyName);
        }
예제 #2
0
        public void TestException1()
        {
            var x = new InvalidPropertyException();

            Assert.NotNull(x);
            Assert.Equal($"Exception of type '{typeof(InvalidPropertyException).FullName}' was thrown.", x.Message);
            Assert.Null(x.InnerException);
            Assert.Null(x.PropertyName);
        }
예제 #3
0
        public void TestException2()
        {
            const string message = "MESSAGE";

            var x = new InvalidPropertyException(message);

            Assert.NotNull(x);
            Assert.Equal(message, x.Message);
            Assert.Null(x.InnerException);
            Assert.Null(x.PropertyName);
        }
예제 #4
0
        public void TestException5()
        {
            const string message      = "MESSAGE";
            const string propertyName = "PROPERTY_NAME";

            var x = new InvalidPropertyException(propertyName, message);

            Assert.NotNull(x);
            Assert.Equal(message, x.Message);
            Assert.Null(x.InnerException);
            Assert.Equal(propertyName, x.PropertyName);
        }
예제 #5
0
        public void SaveWhenPersonHasInvalidName_InvalidPropertyExceptionMustBeFire()
        {
            var           repositoryMock = new Mock <IPersonRepository>();
            PersonManager personManager  = new PersonManager(
                repositoryMock.Object
                );
            Person person = new Person();

            InvalidPropertyException exception = Assert.Throws <InvalidPropertyException>(
                () => personManager.Save(person)
                );

            Assert.IsType <InvalidPropertyException>(exception);
        }
예제 #6
0
            public void SetsValuesCorrectly()
            {
                var exception = new InvalidPropertyException("PropertyName");

                Assert.AreEqual("PropertyName", exception.PropertyName);
            }
예제 #7
0
		/// <summary>
		/// 参数转换出错
		/// </summary>
		/// <param name="e">
		/// 
		/// @return </param>
		private ModelAndView getParamErrors(InvalidPropertyException e)
		{

			IDictionary<string, string> errorMap = new Dictionary<string, string>();
			errorMap[e.PropertyName] = " parameter cannot find";
			JsonObjectBase jsonObject = JsonObjectUtils.buildFieldError(errorMap, ErrorCode.TYPE_MIS_MATCH);
			return JsonObjectUtils.JsonObjectError2ModelView((JsonObjectError) jsonObject);
		}