PageRenderTime 47ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/Ducksboard.Tests/DashboardTests.cs

https://github.com/khalidabuhakmeh/Ducksboard
C# | 117 lines | 97 code | 20 blank | 0 comment | 0 complexity | 006046d4eb24d1a3ba6812d4be446843 MD5 | raw file
  1. using System;
  2. using Ducksboard.Objects;
  3. using Xunit;
  4. using FluentAssertions;
  5. namespace Ducksboard.Tests
  6. {
  7. public class DashboardTests
  8. {
  9. private readonly DashboardClient _dashboardClient;
  10. public DashboardTests()
  11. {
  12. _dashboardClient = new DashboardClient("[YOUR API KEY]");
  13. }
  14. [Fact]
  15. public void Can_get_dashboards()
  16. {
  17. var dashboards = _dashboardClient.GetAll<Dashboard>();
  18. dashboards.Should().NotBeEmpty();
  19. }
  20. [Fact]
  21. public void Can_get_widgets()
  22. {
  23. var widgets = _dashboardClient.GetAll<Widget>();
  24. widgets.Should().NotBeEmpty();
  25. }
  26. [Fact]
  27. public void Delete_unknown_dashboard_returns_0()
  28. {
  29. var deleted = _dashboardClient.Delete<Dashboard>("never made one called this");
  30. deleted.Should().BeFalse();
  31. }
  32. [Fact]
  33. public void Can_create_read_update_delete_dashboard()
  34. {
  35. var dashboardName = Guid.NewGuid().ToString();
  36. var dashboard = new Dashboard()
  37. {
  38. Name = dashboardName,
  39. Background = "dark wood",
  40. };
  41. dashboard = _dashboardClient.Create(dashboard);
  42. dashboard.Should().NotBeNull();
  43. dashboard = _dashboardClient.Get<Dashboard>(dashboard.Slug);
  44. dashboard.Should().NotBeNull();
  45. var newDashboardName = Guid.NewGuid().ToString();
  46. dashboard.Name = newDashboardName;
  47. dashboard = _dashboardClient.Update(dashboard, dashboard.Slug);
  48. dashboard.Name.ShouldBeEquivalentTo(newDashboardName);
  49. var deleted = _dashboardClient.Delete<Dashboard>(dashboard.Slug);
  50. deleted.Should().BeTrue();
  51. }
  52. [Fact]
  53. public void Can_create_read_update_delete_widget()
  54. {
  55. var dashboardName = Guid.NewGuid().ToString();
  56. var dashboard = new Dashboard()
  57. {
  58. Name = dashboardName,
  59. Background = "dark wood",
  60. };
  61. dashboard = _dashboardClient.Create(dashboard);
  62. dashboard.Should().NotBeNull();
  63. var widget = new Widget
  64. {
  65. WidgetProperties = new WidgetProperties
  66. {
  67. Kind = "custom_numeric_gauge",
  68. Title = "TEST",
  69. Dashboard = dashboard.Slug,
  70. Width = 1,
  71. Height = 1,
  72. Row = 1,
  73. Column = 1,
  74. Sound = true
  75. },
  76. Slots = new Slot
  77. {
  78. Slot1 = new SlotData
  79. {
  80. Subtitle = "watchers",
  81. Timespan = "monthly",
  82. Color = "#C11F70"
  83. }
  84. }
  85. };
  86. widget = _dashboardClient.Create(widget);
  87. widget.Should().NotBeNull();
  88. widget.WidgetProperties.Title = "TEST 1, 2";
  89. widget = _dashboardClient.Update(widget, widget.Slug);
  90. widget.WidgetProperties.Title.Should().Be("TEST 1, 2");
  91. var widgetDeleted = _dashboardClient.Delete<Widget>(widget.Slug);
  92. widgetDeleted.Should().BeTrue();
  93. var deleted = _dashboardClient.Delete<Dashboard>(dashboard.Slug);
  94. deleted.Should().BeTrue();
  95. }
  96. }
  97. }