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); }
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); }
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); }
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); }
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); }
public void SetsValuesCorrectly() { var exception = new InvalidPropertyException("PropertyName"); Assert.AreEqual("PropertyName", exception.PropertyName); }
/// <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); }