You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
2.6 KiB

2 years ago
  1. using OrmTest.Models;
  2. using SqlSugar;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. namespace OrmTest.UnitTest
  8. {
  9. public class DataTest : UnitTestBase
  10. {
  11. private DataTest() { }
  12. public DataTest(int eachCount)
  13. {
  14. this.Count = eachCount;
  15. }
  16. public void Init()
  17. {
  18. var db = GetInstance();
  19. db.DbMaintenance.TruncateTable("DataTestInfo");
  20. var insertObject = new DataTestInfo()
  21. {
  22. Datetime1 = DateTime.Now,
  23. Datetime2 = DateTime.Now,
  24. Decimal1 = 1,
  25. Decimal2 = 2,
  26. Float1 = 3,
  27. Float2 = 4,
  28. Guid1 = Guid.Empty,
  29. Guid2 = null,
  30. Image1 = new byte[] { 1, 2 },
  31. Image2 = new byte[] { 2, 3 },
  32. Int2 = 6,
  33. Money1 = 7,
  34. Money2 = 8,
  35. Varbinary1 = new byte[] { 4, 5 },
  36. Varbinary2 = null,
  37. String = "string"
  38. };
  39. var id = db.Insertable<DataTestInfo>(insertObject).ExecuteReturnIdentity();
  40. var data = db.Queryable<DataTestInfo>().InSingle(id);
  41. if (
  42. insertObject.Datetime1.ToString("yyyy-MM-dd HH:mm:ss") != data.Datetime1.ToString("yyyy-MM-dd HH:mm:ss") ||
  43. insertObject.Decimal1 != data.Decimal1 ||
  44. insertObject.Float1 != data.Float1 ||
  45. insertObject.Float2 != data.Float2 ||
  46. insertObject.Int2 != data.Int2 ||
  47. insertObject.Money1 != data.Money1 ||
  48. string.Join(",", insertObject.Varbinary1) != string.Join(",", data.Varbinary1) ||
  49. insertObject.String != data.String)
  50. {
  51. throw new Exception("DataTest Error");
  52. }
  53. data.Float1= data.Float1+1;
  54. db.Updateable(data).ExecuteCommand();
  55. data = db.Queryable<DataTestInfo>().InSingle(id);
  56. if (
  57. insertObject.Datetime1.ToString("yyyy-MM-dd HH:mm:ss") != data.Datetime1.ToString("yyyy-MM-dd HH:mm:ss") ||
  58. insertObject.Decimal1 != data.Decimal1 ||
  59. (insertObject.Float1+1) != data.Float1 ||
  60. insertObject.Float2 != data.Float2 ||
  61. insertObject.Int2 != data.Int2 ||
  62. insertObject.Money1 != data.Money1 ||
  63. string.Join(",", insertObject.Varbinary1) != string.Join(",", data.Varbinary1) ||
  64. insertObject.String != data.String)
  65. {
  66. throw new Exception("DataTest Error");
  67. }
  68. }
  69. }
  70. }