PageRenderTime 44ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/Ducksboard.Tests/Objects/ObjectTests.cs

https://github.com/khalidabuhakmeh/Ducksboard
C# | 212 lines | 181 code | 31 blank | 0 comment | 0 complexity | f25a90d9d8880fc68f5d54befd3e9f2c MD5 | raw file
  1. using System;
  2. using Ducksboard.Objects;
  3. using FluentAssertions;
  4. using Xunit;
  5. namespace Ducksboard.Tests.Objects
  6. {
  7. public class NumbersTests : SerializationTest
  8. {
  9. [Fact]
  10. public void Can_serialize_value_properly()
  11. {
  12. var target = new Numbers { Value = 3.5m };
  13. string result = Serializer.Serialize(target);
  14. result.Should().NotBeNullOrEmpty();
  15. }
  16. [Fact]
  17. public void Can_call_to_json_on_a_ducksboard_object()
  18. {
  19. new Numbers { Value = 3 }.ToJson().Should().NotBeNullOrEmpty();
  20. }
  21. [Fact]
  22. public void Can_serialize_delta_properly()
  23. {
  24. var target = new Numbers { Delta = 3.5m };
  25. string result = Serializer.Serialize(target);
  26. result.Should().NotBeNullOrEmpty();
  27. }
  28. [Fact]
  29. public void Can_serialize_date_to_unix_timestamp()
  30. {
  31. var target = new Numbers(new DateTime(2012, 5, 26, 0, 0, 0, DateTimeKind.Utc));
  32. target.Timestamp.Should().HaveValue();
  33. target.Timestamp.Should().Be(1337990400);
  34. }
  35. [Fact]
  36. public void Can_set_date_which_sets_timestamp()
  37. {
  38. var target = new Numbers { Date = new DateTime(2012, 5, 26, 0, 0, 0, DateTimeKind.Utc), Value = 3 };
  39. target.Timestamp.Should().HaveValue();
  40. target.Timestamp.Should().Be(1337990400);
  41. string result = Serializer.Serialize(target);
  42. result.Should().NotBeNull();
  43. }
  44. [Fact]
  45. public void Can_serialize_an_array_of_numbers()
  46. {
  47. var numbers = new[] {new Numbers {Value = 1}, new Numbers {Value = 2}};
  48. var result = Serializer.Serialize(numbers);
  49. result.Should().NotBeNull();
  50. result.Should().StartWith("[");
  51. result.Should().EndWith("]");
  52. }
  53. }
  54. public class GaugesTests : SerializationTest
  55. {
  56. [Fact]
  57. public void Can_serialize_a_gague_properly()
  58. {
  59. var target = new Gauges { Value = 0.25m };
  60. string result = Serializer.Serialize(target);
  61. result.Should().NotBeNullOrEmpty();
  62. }
  63. }
  64. public class TimelineTests : SerializationTest
  65. {
  66. [Fact]
  67. public void Can_serialize_timeline_objects_properly()
  68. {
  69. var target = new Timeline();
  70. target.Value.Title = "error message";
  71. target.Value.Image = "http://assets.example.or/error.png";
  72. target.Value.Content = "All system stop!";
  73. target.Value.Link = "http://monitoring.example.org/incident/354";
  74. string result = Serializer.Serialize(target);
  75. result.Should().NotBeNullOrEmpty();
  76. }
  77. }
  78. public class ImageTests : SerializationTest
  79. {
  80. [Fact]
  81. public void Can_serialize_image_objects()
  82. {
  83. var target = new Image();
  84. target.Value.Source = "http://assets.example.org/logo.png";
  85. target.Value.Caption = "Example Corp, Inc.";
  86. string result = Serializer.Serialize(target);
  87. result.Should().NotBeNullOrEmpty();
  88. }
  89. }
  90. public class TextTests : SerializationTest
  91. {
  92. [Fact]
  93. public void Can_serialize_text_objects()
  94. {
  95. var target = new Text();
  96. target.Value.Content = @"Text!\nLorem ipsum dolor sit amet...";
  97. string result = Serializer.Serialize(target);
  98. result.Should().NotBeNullOrEmpty();
  99. }
  100. }
  101. public class LeaderboardTests : SerializationTest
  102. {
  103. [Fact]
  104. public void Can_serialize_leaderboard_objects()
  105. {
  106. var target = new Leaderboard();
  107. target
  108. .Add("Abdul-Jabbar", 38387, 1560, 24.6m)
  109. .Add("Karl Malone", 36928, 1476, 25.0m)
  110. .Add("Michael Jordan", 32292, 1072, 30.1m)
  111. .Add("W. Chamberlain", 31419, 1045, 30.1m)
  112. .Add("Kobe Bryant", 29484, 1161, 25.4m)
  113. .Add("Shaq O Neal", 28596, 1207, 23.7m)
  114. .Add("Moses Malone", 27409, 1329, 20.6m)
  115. .Add("Elvis Hayes", 28313, 1303, 21.0m)
  116. .Add("H. Olajuwon", 26946, 1238, 21.8m);
  117. string result = Serializer.Serialize(target);
  118. result.Should().NotBeNullOrEmpty();
  119. }
  120. }
  121. public class TrendLeaderboardTests : SerializationTest
  122. {
  123. [Fact]
  124. public void Can_serialize_trend_leaderboard_objects()
  125. {
  126. var target = new TrendLeaderboard();
  127. target
  128. .Add("value1", null, 1560, 24.6m)
  129. .Add("value2", null, 1560, 24.6m)
  130. .Add("value3", null, 1560, 24.6m)
  131. .Add("overridden", TrendLeaderboard.Trends.Up, 1560, 24.6m);
  132. string result = Serializer.Serialize(target);
  133. result.Should().NotBeNullOrEmpty();
  134. }
  135. }
  136. public class StatusLeaderboardTests : SerializationTest
  137. {
  138. [Fact]
  139. public void Can_serialize_status_leaderboard_objects()
  140. {
  141. var target = new StatusLeaderboard();
  142. target
  143. .Add("everything fine", StatusLeaderboard.Status.Green, "100%")
  144. .Add("warning, warning", StatusLeaderboard.Status.Yellow, "80%")
  145. .Add("very bad", StatusLeaderboard.Status.Red, "15%")
  146. .Add("not sure", StatusLeaderboard.Status.Gray, "--");
  147. string result = Serializer.Serialize(target);
  148. result.Should().NotBeNullOrEmpty();
  149. }
  150. }
  151. public class FunnelTests : SerializationTest
  152. {
  153. [Fact]
  154. public void Can_serialize_funnel_objects()
  155. {
  156. var target = new Funnel();
  157. target
  158. .Add("STEP 1", 1600)
  159. .Add("STEP 2", 1400)
  160. .Add("STEP 3", 1200)
  161. .Add("STEP 4", 900)
  162. .Add("STEP 5", 600)
  163. .Add("STEP 6", 330);
  164. string result = Serializer.Serialize(target);
  165. result.Should().NotBeNullOrEmpty();
  166. }
  167. }
  168. public class CompletionTests : SerializationTest
  169. {
  170. [Fact]
  171. public void Can_serialize_completion_objects()
  172. {
  173. var target = new Completion();
  174. target.Value.Min = 0;
  175. target.Value.Max = 100;
  176. target.Value.Current = 75.25M;
  177. string result = Serializer.Serialize(target);
  178. result.Should().NotBeNullOrEmpty();
  179. }
  180. }
  181. }