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.

60 lines
2.1 KiB

2 years ago
  1. using System;
  2. using System.Collections.Generic;
  3. using SqlSugar;
  4. using System.Linq;
  5. namespace OrmTest.UnitTest
  6. {
  7. public class UnitTestBase
  8. {
  9. public int Count { get; set; }
  10. private DateTime BeginTime { get; set; }
  11. private DateTime EndTime { get; set; }
  12. public void Begin()
  13. {
  14. this.BeginTime = DateTime.Now;
  15. }
  16. public void End(string title)
  17. {
  18. this.EndTime = DateTime.Now;
  19. Console.WriteLine(title + " \r\nCount: " + this.Count + "\r\nTime: " + (this.EndTime - this.BeginTime).TotalSeconds + " Seconds \r\n");
  20. }
  21. internal void Check(string value, List<SugarParameter> pars, string validValue, List<SugarParameter> validPars, string errorMessage)
  22. {
  23. if (value.Trim() != validValue.Trim())
  24. {
  25. throw new Exception(errorMessage);
  26. }
  27. if (pars != null && pars.Count > 0)
  28. {
  29. if (pars.Count != validPars.Count)
  30. {
  31. throw new Exception(errorMessage);
  32. }
  33. else
  34. {
  35. foreach (var item in pars)
  36. {
  37. if (!validPars.Any(it => it.ParameterName.Equals(item.ParameterName) && it.Value.ObjToString().Equals(item.Value.ObjToString())))
  38. {
  39. throw new Exception(errorMessage);
  40. }
  41. }
  42. }
  43. }
  44. }
  45. public SqlSugarClient GetInstance()
  46. {
  47. SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { ConnectionString = Config.ConnectionString, DbType = DbType.SqlServer, IsAutoCloseConnection = true });
  48. return db;
  49. }
  50. public SqlSugarClient GetInstanceByAttribute()
  51. {
  52. SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { InitKeyType=InitKeyType.Attribute, ConnectionString = Config.ConnectionString, DbType = DbType.SqlServer, IsAutoCloseConnection = true });
  53. return db;
  54. }
  55. }
  56. }