UnitTest1.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using System;
  2. using System.Collections.Generic;
  3. using Microsoft.VisualStudio.TestTools.UnitTesting;
  4. using TaskDatabase;
  5. using TaskDatabase.Model;
  6. using NHibernate.Cfg;
  7. using Newtonsoft.Json;
  8. namespace UnitTestDatabase
  9. {
  10. [TestClass]
  11. public class UnitTest1
  12. {
  13. [TestInitialize()]
  14. public void init() {
  15. var cfg = new Configuration();
  16. cfg.Configure();
  17. }
  18. [TestMethod]
  19. public void SelectAllValid()
  20. {
  21. TaskService service = new TaskService();
  22. IList<TaskModel> tasks = service.GetTasksByStatus(0);
  23. Assert.IsTrue(tasks.Count== 2) ;
  24. }
  25. [TestMethod]
  26. public void TestIfExist()
  27. {
  28. TaskService service = new TaskService();
  29. IList<TaskModel> tasks = service.GetTasksByStatus(0);
  30. Assert.IsTrue(service.isContainsTask(tasks[0].Id));
  31. Assert.IsTrue(service.isContainsTask(tasks[1].Id));
  32. Assert.IsFalse(service.isContainsTask(100));
  33. }
  34. [TestMethod]
  35. public void TestUpdate()
  36. {
  37. TaskService service = new TaskService();
  38. IList<TaskModel> tasks = service.GetTasksByStatus(0);
  39. TaskModel task = tasks[0];
  40. string json = JsonConvert.SerializeObject(task, Formatting.None);
  41. Console.WriteLine(json);
  42. foreach (var download in task.DownloadTaskModelList) {
  43. download.Task_md5 = "abc";
  44. service.UpdateDownload(download);
  45. }
  46. json = JsonConvert.SerializeObject(task, Formatting.None);
  47. service.UpdateTask(task);
  48. }
  49. [TestMethod]
  50. public void TestUpdate2()
  51. {
  52. TaskService service = new TaskService();
  53. IList<TaskModel> tasks = service.GetTasksByStatus(0);
  54. TaskModel task = tasks[0];
  55. string json = JsonConvert.SerializeObject(task, Formatting.None);
  56. Console.WriteLine(json);
  57. //task.Task_status = 1;
  58. task.Task_expected_finish_time = 100;
  59. json = JsonConvert.SerializeObject(task, Formatting.None);
  60. service.UpdateTask(task);
  61. TaskModel newTask = service.GetTasksByTid(task.Tid);
  62. json = JsonConvert.SerializeObject(task, Formatting.None);
  63. Console.WriteLine(json);
  64. }
  65. [TestMethod]
  66. public void TestAdd()
  67. {
  68. TaskService service = new TaskService();
  69. IList<TaskModel> tasks = service.GetTasksByStatus(0);
  70. TaskModel task = tasks[1];
  71. task.Task_status = 1;
  72. task.Task_cmd = "cmd";
  73. task.Id = 10;
  74. task.Task_expected_finish_time = 10000;
  75. task.Task_param = "param";
  76. task.Task_result_json = "json";
  77. service.AddTask(task);
  78. //TaskModel newTask = service.GetTasksByTid(task.Tid);
  79. //json = JsonConvert.SerializeObject(task, Formatting.None);
  80. //Console.WriteLine(json);
  81. }
  82. }
  83. }