ClassHelperTest.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using Masuit.Tools.Reflection;
  2. using System.Collections.Generic;
  3. using Xunit;
  4. namespace Masuit.Tools.UnitTest
  5. {
  6. public class ClassHelperTest
  7. {
  8. [Fact]
  9. public void Can_AddProperty_ReturnNewInstance()
  10. {
  11. // arrange
  12. MyClass myClass = new MyClass();
  13. // act
  14. dynamic newObj = myClass.AddProperty(new List<ClassHelper.CustPropertyInfo>()
  15. {
  16. new ClassHelper.CustPropertyInfo(typeof(string),"Name","张三"),
  17. new ClassHelper.CustPropertyInfo(typeof(int),"Age",20),
  18. });
  19. // act
  20. Assert.Equal("张三", newObj.Name);
  21. Assert.Equal(20, newObj.Age);
  22. }
  23. [Fact]
  24. public void Can_RemoveProperty_ReturnNewInstance()
  25. {
  26. // arrange
  27. MyClass myClass = new MyClass()
  28. {
  29. MyProperty = "aa",
  30. Number = 123
  31. };
  32. // act
  33. object newObj = myClass.DeleteProperty("MyProperty");
  34. // act
  35. int propertyCount = newObj.GetType().GetProperties().Length;
  36. Assert.Equal(1, propertyCount);
  37. }
  38. }
  39. public class MyClass
  40. {
  41. public string MyProperty { get; set; }
  42. public int Number { get; set; }
  43. }
  44. }