Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

ArticlesDataAccessTest.cs 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. using System.Collections.Generic;
  2. using Luticate2.Utils.Dbo.Result;
  3. using Luticate2.Utils.Utils;
  4. using WebApiWebSem.DataAccess;
  5. using WebApiWebSem.Dbo.Articles;
  6. using WebApiWebSem.Dbo.ArticlesFields;
  7. using Xunit;
  8. namespace Test.DataAccess
  9. {
  10. public class ArticlesDataAccessTest
  11. {
  12. [Fact]
  13. public void Test1()
  14. {
  15. Tests.TestRealDb<ArticlesDataAccess>(access =>
  16. {
  17. var res = access.AddDbo(new ArticlesAddDbo
  18. {
  19. Fields = new List<ArticlesFieldsAddDbo>
  20. {
  21. new ArticlesFieldsAddDbo
  22. {
  23. Property = "deathDate",
  24. Type = "date/date",
  25. Value = "1965-01-24"
  26. }
  27. },
  28. Id = "Winston_Churchill",
  29. PictureCaption = "Winston Churchill en 1942.",
  30. PictureUrl = "http://commons.wikimedia.org/wiki/Special:FilePath/Sir_Winston_S_Churchill.jpg?width=300",
  31. Text = "Winston Churchill, né le 30 novembre 1874 au palais de Blenheim",
  32. Type = "person"
  33. });
  34. Assert.Equal(LuStatus.Success, res.Status);
  35. Assert.Equal("Winston_Churchill", res.Data.Id);
  36. });
  37. }
  38. [Fact]
  39. public void Test2()
  40. {
  41. Tests.TestRealDb<ArticlesDataAccess>(access =>
  42. {
  43. var res = access.AddDbo(new ArticlesAddDbo
  44. {
  45. Fields = new List<ArticlesFieldsAddDbo>
  46. {
  47. new ArticlesFieldsAddDbo
  48. {
  49. Property = "deathDate",
  50. Type = "date/date",
  51. Value = "1965-01-24"
  52. }
  53. },
  54. Id = "Winston_Churchill",
  55. PictureCaption = "Winston Churchill en 1942.",
  56. PictureUrl = "http://commons.wikimedia.org/wiki/Special:FilePath/Sir_Winston_S_Churchill.jpg?width=300",
  57. Text = "Winston Churchill, né le 30 novembre 1874 au palais de Blenheim",
  58. Type = "person"
  59. });
  60. Assert.Equal(LuStatus.Success, res.Status);
  61. Assert.Equal("Winston_Churchill", res.Data.Id);
  62. var resGet = access.GetSingleById("Winston_Churchill");
  63. Assert.Equal(LuStatus.Success, resGet.Status);
  64. Assert.Equal("Winston_Churchill", resGet.Data.Id);
  65. Assert.Equal(1, resGet.Data.Fields.Count);
  66. Assert.Equal("deathDate", resGet.Data.Fields[0].Property);
  67. });
  68. }
  69. [Fact]
  70. public void Test3()
  71. {
  72. Tests.TestRealDb<ArticlesDataAccess>(access =>
  73. {
  74. var res = access.AddDbo(new ArticlesAddDbo
  75. {
  76. Fields = new List<ArticlesFieldsAddDbo>
  77. {
  78. new ArticlesFieldsAddDbo
  79. {
  80. Property = "deathDate",
  81. Type = "date/date",
  82. Value = "1965-01-24"
  83. }
  84. },
  85. Id = "Winston_Churchill",
  86. PictureCaption = "Winston Churchill en 1942.",
  87. PictureUrl = "http://commons.wikimedia.org/wiki/Special:FilePath/Sir_Winston_S_Churchill.jpg?width=300",
  88. Text = "Winston Churchill, né le 30 novembre 1874 au palais de Blenheim",
  89. Type = "person"
  90. });
  91. Assert.Equal(LuStatus.Success, res.Status);
  92. Assert.Equal("Winston_Churchill", res.Data.Id);
  93. var resEdit = access.EditSingleByIdDbo("Winston_Churchill", new ArticlesEditDbo
  94. {
  95. Fields = new List<ArticlesFieldsEditDbo>
  96. {
  97. new ArticlesFieldsAddDbo
  98. {
  99. Property = "deathDate",
  100. Type = "date/date",
  101. Value = "1965-01-25"
  102. }
  103. },
  104. PictureCaption = "Test.",
  105. PictureUrl = "http://commons.wikimedia.org/wiki/Special:FilePath/Sir_Winston_S_Churchill.jpg?width=300",
  106. Text = "Winston Churchill, né le 30 novembre 1874 au palais de Blenheim"
  107. });
  108. Assert.Equal(null, resEdit.Exception);
  109. Assert.Equal(LuStatus.Success, resEdit.Status);
  110. Assert.Equal("Winston_Churchill", resEdit.Data.Id);
  111. Assert.Equal("Test.", resEdit.Data.PictureCaption);
  112. Assert.Equal(1, resEdit.Data.Fields.Count);
  113. Assert.Equal("deathDate", resEdit.Data.Fields[0].Property);
  114. Assert.Equal("1965-01-25", resEdit.Data.Fields[0].Value);
  115. var resGet = access.GetSingleById("Winston_Churchill");
  116. Assert.Equal(LuStatus.Success, resGet.Status);
  117. Assert.Equal("Winston_Churchill", resGet.Data.Id);
  118. Assert.Equal(1, resGet.Data.Fields.Count);
  119. Assert.Equal("deathDate", resGet.Data.Fields[0].Property);
  120. Assert.Equal("1965-01-25", resGet.Data.Fields[0].Value);
  121. });
  122. }
  123. }
  124. }