-
Notifications
You must be signed in to change notification settings - Fork 4
/
DashboardBuilderTests.cs
352 lines (327 loc) · 31.7 KB
/
DashboardBuilderTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
using System;
using System.Collections.Generic;
using Kustomaur.Dashboard;
using Kustomaur.Dashboard.DashboardParts.Implementations;
using Kustomaur.Dashboard.Implementation;
using Kustomaur.Models;
using Xunit;
namespace Kustomaur.Builder.Tests
{
public class DashboardBuilderTests
{
[Fact]
public void CanCreateADashboard()
{
//arrange
var subscriptionId = "6b062fa3-dbe5-4e4a-8d54-ce7286ec9ef6";
var resourceGroup = Guid.NewGuid().ToString();
var name = "ce043e69-f9f3-4618-bbe2-2a93e769b56d";
// Act
var dashboard = new DashboardBuilder()
.WithSubscription(subscriptionId)
.WithResourceGroup(resourceGroup)
.WithName(name)
.Build();
// Assert
Assert.Equal(
"{\"properties\":{\"lenses\":null,\"metadata\":{\"model\":{\"timeRange\":{\"value\":{\"relative\":{\"duration\":24,\"timeUnit\":1}},\"type\":\"MsPortalFx.Composition.Configuration.ValueTypes.TimeRange\"},\"filters\":{\"value\":{\"MsPortalFx_TimeRange\":{\"model\":{\"format\":\"utc\",\"granularity\":\"auto\",\"relative\":\"24h\"},\"displayCache\":{\"name\":\"UTC Time\",\"value\":\"Past 24 hours\"},\"filteredPartIds\":[]}}},\"filterLocale\":{\"value\":\"en-us\"}}}},\"name\":\"ce043e69-f9f3-4618-bbe2-2a93e769b56d\",\"type\":\"Microsoft.Portal/dashboards\",\"location\":null,\"tags\":{\"hidden-title\":\"ce043e69-f9f3-4618-bbe2-2a93e769b56d\"}}",
Dashboard.Generator.Generate(dashboard));
}
[Fact]
public void CanCreateADashboardWithPartsBuilder()
{
//arrange
var subscriptionId = "6b062fa3-dbe5-4e4a-8d54-ce7286ec9ef6";
var resourceGroup = Guid.NewGuid().ToString();
var name = "ce043e69-f9f3-4618-bbe2-2a93e769b56d";
// Act
var dashboard = new DashboardBuilder()
.WithSubscription(subscriptionId)
.WithResourceGroup(resourceGroup)
.WithName(name)
.WithBuilder(new DashboardPartsBuilder()
.AddPart(new MarkdownPart(content:"My first thing")))
.Build();
// Assert
Assert.Equal(
"{\"properties\":{\"lenses\":{\"0\":{\"order\":0,\"parts\":{\"0\":{\"position\":{\"x\":0,\"y\":0,\"colSpan\":3,\"rowSpan\":3},\"metadata\":{\"type\":\"Extension/HubsExtension/PartType/MarkdownPart\",\"inputs\":[],\"settings\":{\"content\":{\"settings\":{\"content\":\"My first thing\",\"title\":\"\",\"subtitle\":\"\",\"markdownSource\":1,\"markdownUri\":null}}}}}}}},\"metadata\":{\"model\":{\"timeRange\":{\"value\":{\"relative\":{\"duration\":24,\"timeUnit\":1}},\"type\":\"MsPortalFx.Composition.Configuration.ValueTypes.TimeRange\"},\"filters\":{\"value\":{\"MsPortalFx_TimeRange\":{\"model\":{\"format\":\"utc\",\"granularity\":\"auto\",\"relative\":\"24h\"},\"displayCache\":{\"name\":\"UTC Time\",\"value\":\"Past 24 hours\"},\"filteredPartIds\":[]}}},\"filterLocale\":{\"value\":\"en-us\"}}}},\"name\":\"ce043e69-f9f3-4618-bbe2-2a93e769b56d\",\"type\":\"Microsoft.Portal/dashboards\",\"location\":null,\"tags\":{\"hidden-title\":\"ce043e69-f9f3-4618-bbe2-2a93e769b56d\"}}",
Dashboard.Generator.Generate(dashboard));
}
[Fact]
public void CanCreateADashboardWithMultipleParts()
{
//arrange
var subscriptionId = "6b062fa3-dbe5-4e4a-8d54-ce7286ec9ef6";
var resourceGroup = Guid.NewGuid().ToString();
var name = "ce043e69-f9f3-4618-bbe2-2a93e769b56d";
// Act
var dashboard = new DashboardBuilder()
.WithSubscription(subscriptionId)
.WithResourceGroup(resourceGroup)
.WithName(name)
.WithBuilder(new DashboardPartsBuilder()
.AddPart(new MarkdownPart(content:"My first thing")
.WithColSpan(5)
.WithRowSpan(5)
.GeneratePart())
.AddPart(new MarkdownPart("My second thing")
.WithX(5)
.WithY(0)
.WithColSpan(7)
.WithRowSpan(7)
.GeneratePart()))
.Build();
Assert.Equal(
"{\"properties\":{\"lenses\":{\"0\":{\"order\":0,\"parts\":{\"0\":{\"position\":{\"x\":0,\"y\":0,\"colSpan\":5,\"rowSpan\":5},\"metadata\":{\"type\":\"Extension/HubsExtension/PartType/MarkdownPart\",\"inputs\":[],\"settings\":{\"content\":{\"settings\":{\"content\":\"My first thing\",\"title\":\"\",\"subtitle\":\"\",\"markdownSource\":1,\"markdownUri\":null}}}}},\"1\":{\"position\":{\"x\":5,\"y\":0,\"colSpan\":7,\"rowSpan\":7},\"metadata\":{\"type\":\"Extension/HubsExtension/PartType/MarkdownPart\",\"inputs\":[],\"settings\":{\"content\":{\"settings\":{\"content\":\"My second thing\",\"title\":\"\",\"subtitle\":\"\",\"markdownSource\":1,\"markdownUri\":null}}}}}}}},\"metadata\":{\"model\":{\"timeRange\":{\"value\":{\"relative\":{\"duration\":24,\"timeUnit\":1}},\"type\":\"MsPortalFx.Composition.Configuration.ValueTypes.TimeRange\"},\"filters\":{\"value\":{\"MsPortalFx_TimeRange\":{\"model\":{\"format\":\"utc\",\"granularity\":\"auto\",\"relative\":\"24h\"},\"displayCache\":{\"name\":\"UTC Time\",\"value\":\"Past 24 hours\"},\"filteredPartIds\":[]}}},\"filterLocale\":{\"value\":\"en-us\"}}}},\"name\":\"ce043e69-f9f3-4618-bbe2-2a93e769b56d\",\"type\":\"Microsoft.Portal/dashboards\",\"location\":null,\"tags\":{\"hidden-title\":\"ce043e69-f9f3-4618-bbe2-2a93e769b56d\"}}",
Dashboard.Generator.Generate(dashboard));
}
[Fact]
public void CanCreateADashboardWithMultiplePartsAsARow()
{
//arrange
var subscriptionId = "6b062fa3-dbe5-4e4a-8d54-ce7286ec9ef6";
var resourceGroup = Guid.NewGuid().ToString();
var name = "ce043e69-f9f3-4618-bbe2-2a93e769b56d";
// Act
var dashboard = new DashboardBuilder()
.WithSubscription(subscriptionId)
.WithResourceGroup(resourceGroup)
.WithName(name)
.WithBuilder(new DashboardPartsBuilder()
.AddPartsAsRow(new List<Part>()
{
new MarkdownPart(content:"# my first part in 1st row")
.WithColSpan(3)
.GeneratePart(),
new MarkdownPart(content:"# my second part in 1st row")
.WithColSpan(3)
.GeneratePart()
}, out int firstRowMaxY) // firstRowMaxY is what we should set the new row Y value
.AddPartsAsRow(new List<Part>()
{
new MarkdownPart(content:"# my first part in 2nd row")
.WithColSpan(4)
.GeneratePart(),
new MarkdownPart(content:"# my second part in 2nd row")
.WithColSpan(4)
.GeneratePart()
}, out int secondRowMaxY, startYPos:firstRowMaxY)
.AddPartsAsRow(new List<Part>()
{
new MarkdownPart(content:"# my first part in 3rd row")
.WithColSpan(5)
.GeneratePart(),
new MarkdownPart(content:"# my second part in 3rd row")
.WithColSpan(5)
.GeneratePart()
}, out int thirdRowMaxY, startYPos:secondRowMaxY))
.Build();
Assert.Equal(
"{\"properties\":{\"lenses\":{\"0\":{\"order\":0,\"parts\":{\"0\":{\"position\":{\"x\":0,\"y\":0,\"colSpan\":3,\"rowSpan\":3},\"metadata\":{\"type\":\"Extension/HubsExtension/PartType/MarkdownPart\",\"inputs\":[],\"settings\":{\"content\":{\"settings\":{\"content\":\"# my first part in 1st row\",\"title\":\"\",\"subtitle\":\"\",\"markdownSource\":1,\"markdownUri\":null}}}}},\"1\":{\"position\":{\"x\":3,\"y\":0,\"colSpan\":3,\"rowSpan\":3},\"metadata\":{\"type\":\"Extension/HubsExtension/PartType/MarkdownPart\",\"inputs\":[],\"settings\":{\"content\":{\"settings\":{\"content\":\"# my second part in 1st row\",\"title\":\"\",\"subtitle\":\"\",\"markdownSource\":1,\"markdownUri\":null}}}}},\"2\":{\"position\":{\"x\":0,\"y\":3,\"colSpan\":4,\"rowSpan\":3},\"metadata\":{\"type\":\"Extension/HubsExtension/PartType/MarkdownPart\",\"inputs\":[],\"settings\":{\"content\":{\"settings\":{\"content\":\"# my first part in 2nd row\",\"title\":\"\",\"subtitle\":\"\",\"markdownSource\":1,\"markdownUri\":null}}}}},\"3\":{\"position\":{\"x\":4,\"y\":3,\"colSpan\":4,\"rowSpan\":3},\"metadata\":{\"type\":\"Extension/HubsExtension/PartType/MarkdownPart\",\"inputs\":[],\"settings\":{\"content\":{\"settings\":{\"content\":\"# my second part in 2nd row\",\"title\":\"\",\"subtitle\":\"\",\"markdownSource\":1,\"markdownUri\":null}}}}},\"4\":{\"position\":{\"x\":0,\"y\":6,\"colSpan\":5,\"rowSpan\":3},\"metadata\":{\"type\":\"Extension/HubsExtension/PartType/MarkdownPart\",\"inputs\":[],\"settings\":{\"content\":{\"settings\":{\"content\":\"# my first part in 3rd row\",\"title\":\"\",\"subtitle\":\"\",\"markdownSource\":1,\"markdownUri\":null}}}}},\"5\":{\"position\":{\"x\":5,\"y\":6,\"colSpan\":5,\"rowSpan\":3},\"metadata\":{\"type\":\"Extension/HubsExtension/PartType/MarkdownPart\",\"inputs\":[],\"settings\":{\"content\":{\"settings\":{\"content\":\"# my second part in 3rd row\",\"title\":\"\",\"subtitle\":\"\",\"markdownSource\":1,\"markdownUri\":null}}}}}}}},\"metadata\":{\"model\":{\"timeRange\":{\"value\":{\"relative\":{\"duration\":24,\"timeUnit\":1}},\"type\":\"MsPortalFx.Composition.Configuration.ValueTypes.TimeRange\"},\"filters\":{\"value\":{\"MsPortalFx_TimeRange\":{\"model\":{\"format\":\"utc\",\"granularity\":\"auto\",\"relative\":\"24h\"},\"displayCache\":{\"name\":\"UTC Time\",\"value\":\"Past 24 hours\"},\"filteredPartIds\":[]}}},\"filterLocale\":{\"value\":\"en-us\"}}}},\"name\":\"ce043e69-f9f3-4618-bbe2-2a93e769b56d\",\"type\":\"Microsoft.Portal/dashboards\",\"location\":null,\"tags\":{\"hidden-title\":\"ce043e69-f9f3-4618-bbe2-2a93e769b56d\"}}",
Dashboard.Generator.Generate(dashboard));
}
[Fact]
public void CanCreateADashboardWithMultiplePartsAsARowAutoCalculated()
{
//arrange
var subscriptionId = "6b062fa3-dbe5-4e4a-8d54-ce7286ec9ef6";
var resourceGroup = Guid.NewGuid().ToString();
var name = "ce043e69-f9f3-4618-bbe2-2a93e769b56d";
// Act
var dashboard = new DashboardBuilder()
.WithSubscription(subscriptionId)
.WithResourceGroup(resourceGroup)
.WithName(name)
.WithBuilder(new DashboardPartsBuilder()
.AddPartsAsRow(new List<Part>()
{
new MarkdownPart(content:"# my first part in 1st row")
.WithColSpan(3)
.GeneratePart(),
new MarkdownPart(content:"# my second part in 1st row")
.WithColSpan(3)
.GeneratePart()
})
.AddPartsAsRow(new List<Part>()
{
new MarkdownPart(content:"# my first part in 2nd row")
.WithColSpan(4)
.GeneratePart(),
new MarkdownPart(content:"# my second part in 2nd row")
.WithColSpan(4)
.GeneratePart()
})
.AddPartsAsRow(new List<Part>()
{
new MarkdownPart(content:"# my first part in 3rd row")
.WithColSpan(5)
.GeneratePart(),
new MarkdownPart(content:"# my second part in 3rd row")
.WithColSpan(5)
.GeneratePart()
}))
.Build();
Assert.Equal(
"{\"properties\":{\"lenses\":{\"0\":{\"order\":0,\"parts\":{\"0\":{\"position\":{\"x\":0,\"y\":0,\"colSpan\":3,\"rowSpan\":3},\"metadata\":{\"type\":\"Extension/HubsExtension/PartType/MarkdownPart\",\"inputs\":[],\"settings\":{\"content\":{\"settings\":{\"content\":\"# my first part in 1st row\",\"title\":\"\",\"subtitle\":\"\",\"markdownSource\":1,\"markdownUri\":null}}}}},\"1\":{\"position\":{\"x\":3,\"y\":0,\"colSpan\":3,\"rowSpan\":3},\"metadata\":{\"type\":\"Extension/HubsExtension/PartType/MarkdownPart\",\"inputs\":[],\"settings\":{\"content\":{\"settings\":{\"content\":\"# my second part in 1st row\",\"title\":\"\",\"subtitle\":\"\",\"markdownSource\":1,\"markdownUri\":null}}}}},\"2\":{\"position\":{\"x\":0,\"y\":3,\"colSpan\":4,\"rowSpan\":3},\"metadata\":{\"type\":\"Extension/HubsExtension/PartType/MarkdownPart\",\"inputs\":[],\"settings\":{\"content\":{\"settings\":{\"content\":\"# my first part in 2nd row\",\"title\":\"\",\"subtitle\":\"\",\"markdownSource\":1,\"markdownUri\":null}}}}},\"3\":{\"position\":{\"x\":4,\"y\":3,\"colSpan\":4,\"rowSpan\":3},\"metadata\":{\"type\":\"Extension/HubsExtension/PartType/MarkdownPart\",\"inputs\":[],\"settings\":{\"content\":{\"settings\":{\"content\":\"# my second part in 2nd row\",\"title\":\"\",\"subtitle\":\"\",\"markdownSource\":1,\"markdownUri\":null}}}}},\"4\":{\"position\":{\"x\":0,\"y\":6,\"colSpan\":5,\"rowSpan\":3},\"metadata\":{\"type\":\"Extension/HubsExtension/PartType/MarkdownPart\",\"inputs\":[],\"settings\":{\"content\":{\"settings\":{\"content\":\"# my first part in 3rd row\",\"title\":\"\",\"subtitle\":\"\",\"markdownSource\":1,\"markdownUri\":null}}}}},\"5\":{\"position\":{\"x\":5,\"y\":6,\"colSpan\":5,\"rowSpan\":3},\"metadata\":{\"type\":\"Extension/HubsExtension/PartType/MarkdownPart\",\"inputs\":[],\"settings\":{\"content\":{\"settings\":{\"content\":\"# my second part in 3rd row\",\"title\":\"\",\"subtitle\":\"\",\"markdownSource\":1,\"markdownUri\":null}}}}}}}},\"metadata\":{\"model\":{\"timeRange\":{\"value\":{\"relative\":{\"duration\":24,\"timeUnit\":1}},\"type\":\"MsPortalFx.Composition.Configuration.ValueTypes.TimeRange\"},\"filters\":{\"value\":{\"MsPortalFx_TimeRange\":{\"model\":{\"format\":\"utc\",\"granularity\":\"auto\",\"relative\":\"24h\"},\"displayCache\":{\"name\":\"UTC Time\",\"value\":\"Past 24 hours\"},\"filteredPartIds\":[]}}},\"filterLocale\":{\"value\":\"en-us\"}}}},\"name\":\"ce043e69-f9f3-4618-bbe2-2a93e769b56d\",\"type\":\"Microsoft.Portal/dashboards\",\"location\":null,\"tags\":{\"hidden-title\":\"ce043e69-f9f3-4618-bbe2-2a93e769b56d\"}}",
Dashboard.Generator.Generate(dashboard));
}
[Fact]
public void CanCreateADashboardWithMultiplePartsAsAColumn()
{
//arrange
var subscriptionId = "6b062fa3-dbe5-4e4a-8d54-ce7286ec9ef6";
var resourceGroup = Guid.NewGuid().ToString();
var name = "ce043e69-f9f3-4618-bbe2-2a93e769b56d";
// Act
var dashboard = new DashboardBuilder()
.WithSubscription(subscriptionId)
.WithResourceGroup(resourceGroup)
.WithName(name)
.WithBuilder(new DashboardPartsBuilder()
.AddPartsAsColumn(new List<Part>()
{
new MarkdownPart(content:"# my first part in 1st column")
.WithRowSpan(3)
.GeneratePart(),
new MarkdownPart(content:"# my second part in 1st column")
.WithRowSpan(3)
.GeneratePart()
}, out int firstColumnMaxX) // firstRowMaxY is what we should set the new row Y value
.AddPartsAsColumn(new List<Part>()
{
new MarkdownPart(content:"# my first part in 2nd column")
.WithRowSpan(4)
.GeneratePart(),
new MarkdownPart(content:"# my second part in 2nd column")
.WithRowSpan(4)
.GeneratePart()
}, out int secondColumnMaxX, startXPos:firstColumnMaxX)
.AddPartsAsColumn(new List<Part>()
{
new MarkdownPart(content:"# my first part in 3rd column")
.WithRowSpan(5)
.GeneratePart(),
new MarkdownPart(content:"# my second part in 3rd column")
.WithRowSpan(5)
.GeneratePart()
}, out int thirdColumnMaxX, startXPos:secondColumnMaxX))
.Build();
Assert.Equal(
"{\"properties\":{\"lenses\":{\"0\":{\"order\":0,\"parts\":{\"0\":{\"position\":{\"x\":0,\"y\":0,\"colSpan\":3,\"rowSpan\":3},\"metadata\":{\"type\":\"Extension/HubsExtension/PartType/MarkdownPart\",\"inputs\":[],\"settings\":{\"content\":{\"settings\":{\"content\":\"# my first part in 1st column\",\"title\":\"\",\"subtitle\":\"\",\"markdownSource\":1,\"markdownUri\":null}}}}},\"1\":{\"position\":{\"x\":0,\"y\":3,\"colSpan\":3,\"rowSpan\":3},\"metadata\":{\"type\":\"Extension/HubsExtension/PartType/MarkdownPart\",\"inputs\":[],\"settings\":{\"content\":{\"settings\":{\"content\":\"# my second part in 1st column\",\"title\":\"\",\"subtitle\":\"\",\"markdownSource\":1,\"markdownUri\":null}}}}},\"2\":{\"position\":{\"x\":3,\"y\":0,\"colSpan\":3,\"rowSpan\":4},\"metadata\":{\"type\":\"Extension/HubsExtension/PartType/MarkdownPart\",\"inputs\":[],\"settings\":{\"content\":{\"settings\":{\"content\":\"# my first part in 2nd column\",\"title\":\"\",\"subtitle\":\"\",\"markdownSource\":1,\"markdownUri\":null}}}}},\"3\":{\"position\":{\"x\":3,\"y\":4,\"colSpan\":3,\"rowSpan\":4},\"metadata\":{\"type\":\"Extension/HubsExtension/PartType/MarkdownPart\",\"inputs\":[],\"settings\":{\"content\":{\"settings\":{\"content\":\"# my second part in 2nd column\",\"title\":\"\",\"subtitle\":\"\",\"markdownSource\":1,\"markdownUri\":null}}}}},\"4\":{\"position\":{\"x\":6,\"y\":0,\"colSpan\":3,\"rowSpan\":5},\"metadata\":{\"type\":\"Extension/HubsExtension/PartType/MarkdownPart\",\"inputs\":[],\"settings\":{\"content\":{\"settings\":{\"content\":\"# my first part in 3rd column\",\"title\":\"\",\"subtitle\":\"\",\"markdownSource\":1,\"markdownUri\":null}}}}},\"5\":{\"position\":{\"x\":6,\"y\":5,\"colSpan\":3,\"rowSpan\":5},\"metadata\":{\"type\":\"Extension/HubsExtension/PartType/MarkdownPart\",\"inputs\":[],\"settings\":{\"content\":{\"settings\":{\"content\":\"# my second part in 3rd column\",\"title\":\"\",\"subtitle\":\"\",\"markdownSource\":1,\"markdownUri\":null}}}}}}}},\"metadata\":{\"model\":{\"timeRange\":{\"value\":{\"relative\":{\"duration\":24,\"timeUnit\":1}},\"type\":\"MsPortalFx.Composition.Configuration.ValueTypes.TimeRange\"},\"filters\":{\"value\":{\"MsPortalFx_TimeRange\":{\"model\":{\"format\":\"utc\",\"granularity\":\"auto\",\"relative\":\"24h\"},\"displayCache\":{\"name\":\"UTC Time\",\"value\":\"Past 24 hours\"},\"filteredPartIds\":[]}}},\"filterLocale\":{\"value\":\"en-us\"}}}},\"name\":\"ce043e69-f9f3-4618-bbe2-2a93e769b56d\",\"type\":\"Microsoft.Portal/dashboards\",\"location\":null,\"tags\":{\"hidden-title\":\"ce043e69-f9f3-4618-bbe2-2a93e769b56d\"}}",
Dashboard.Generator.Generate(dashboard));
}
[Fact]
public void CanCreateADashboardWithMultiplePartsAsAColumAutoGenerated()
{
//arrange
var subscriptionId = "6b062fa3-dbe5-4e4a-8d54-ce7286ec9ef6";
var resourceGroup = Guid.NewGuid().ToString();
var name = "ce043e69-f9f3-4618-bbe2-2a93e769b56d";
// Act
var dashboard = new DashboardBuilder()
.WithSubscription(subscriptionId)
.WithResourceGroup(resourceGroup)
.WithName(name)
.WithBuilder(new DashboardPartsBuilder()
.AddPartsAsColumn(new List<Part>()
{
new MarkdownPart(content:"# my first part in 1st column")
.WithRowSpan(3)
.GeneratePart(),
new MarkdownPart(content:"# my second part in 1st column")
.WithRowSpan(3)
.GeneratePart()
})
.AddPartsAsColumn(new List<Part>()
{
new MarkdownPart(content:"# my first part in 2nd column")
.WithRowSpan(4)
.GeneratePart(),
new MarkdownPart(content:"# my second part in 2nd column")
.WithRowSpan(4)
.GeneratePart()
})
.AddPartsAsColumn(new List<Part>()
{
new MarkdownPart(content:"# my first part in 3rd column")
.WithRowSpan(5)
.GeneratePart(),
new MarkdownPart(content:"# my second part in 3rd column")
.WithRowSpan(5)
.GeneratePart()
}))
.Build();
Assert.Equal(
"{\"properties\":{\"lenses\":{\"0\":{\"order\":0,\"parts\":{\"0\":{\"position\":{\"x\":0,\"y\":0,\"colSpan\":3,\"rowSpan\":3},\"metadata\":{\"type\":\"Extension/HubsExtension/PartType/MarkdownPart\",\"inputs\":[],\"settings\":{\"content\":{\"settings\":{\"content\":\"# my first part in 1st column\",\"title\":\"\",\"subtitle\":\"\",\"markdownSource\":1,\"markdownUri\":null}}}}},\"1\":{\"position\":{\"x\":0,\"y\":3,\"colSpan\":3,\"rowSpan\":3},\"metadata\":{\"type\":\"Extension/HubsExtension/PartType/MarkdownPart\",\"inputs\":[],\"settings\":{\"content\":{\"settings\":{\"content\":\"# my second part in 1st column\",\"title\":\"\",\"subtitle\":\"\",\"markdownSource\":1,\"markdownUri\":null}}}}},\"2\":{\"position\":{\"x\":3,\"y\":0,\"colSpan\":3,\"rowSpan\":4},\"metadata\":{\"type\":\"Extension/HubsExtension/PartType/MarkdownPart\",\"inputs\":[],\"settings\":{\"content\":{\"settings\":{\"content\":\"# my first part in 2nd column\",\"title\":\"\",\"subtitle\":\"\",\"markdownSource\":1,\"markdownUri\":null}}}}},\"3\":{\"position\":{\"x\":3,\"y\":4,\"colSpan\":3,\"rowSpan\":4},\"metadata\":{\"type\":\"Extension/HubsExtension/PartType/MarkdownPart\",\"inputs\":[],\"settings\":{\"content\":{\"settings\":{\"content\":\"# my second part in 2nd column\",\"title\":\"\",\"subtitle\":\"\",\"markdownSource\":1,\"markdownUri\":null}}}}},\"4\":{\"position\":{\"x\":6,\"y\":0,\"colSpan\":3,\"rowSpan\":5},\"metadata\":{\"type\":\"Extension/HubsExtension/PartType/MarkdownPart\",\"inputs\":[],\"settings\":{\"content\":{\"settings\":{\"content\":\"# my first part in 3rd column\",\"title\":\"\",\"subtitle\":\"\",\"markdownSource\":1,\"markdownUri\":null}}}}},\"5\":{\"position\":{\"x\":6,\"y\":5,\"colSpan\":3,\"rowSpan\":5},\"metadata\":{\"type\":\"Extension/HubsExtension/PartType/MarkdownPart\",\"inputs\":[],\"settings\":{\"content\":{\"settings\":{\"content\":\"# my second part in 3rd column\",\"title\":\"\",\"subtitle\":\"\",\"markdownSource\":1,\"markdownUri\":null}}}}}}}},\"metadata\":{\"model\":{\"timeRange\":{\"value\":{\"relative\":{\"duration\":24,\"timeUnit\":1}},\"type\":\"MsPortalFx.Composition.Configuration.ValueTypes.TimeRange\"},\"filters\":{\"value\":{\"MsPortalFx_TimeRange\":{\"model\":{\"format\":\"utc\",\"granularity\":\"auto\",\"relative\":\"24h\"},\"displayCache\":{\"name\":\"UTC Time\",\"value\":\"Past 24 hours\"},\"filteredPartIds\":[]}}},\"filterLocale\":{\"value\":\"en-us\"}}}},\"name\":\"ce043e69-f9f3-4618-bbe2-2a93e769b56d\",\"type\":\"Microsoft.Portal/dashboards\",\"location\":null,\"tags\":{\"hidden-title\":\"ce043e69-f9f3-4618-bbe2-2a93e769b56d\"}}",
Dashboard.Generator.Generate(dashboard));
}
[Fact]
public void CanCreateADashboardWithMultiplePartsAsAColumnAndRows()
{
//arrange
var subscriptionId = "6b062fa3-dbe5-4e4a-8d54-ce7286ec9ef6";
var resourceGroup = Guid.NewGuid().ToString();
var name = "ce043e69-f9f3-4618-bbe2-2a93e769b56d";
// Act
var dashboard = new DashboardBuilder()
.WithSubscription(subscriptionId)
.WithResourceGroup(resourceGroup)
.WithName(name)
.WithBuilder(new DashboardPartsBuilder()
.AddPartsAsColumn(new List<Part>()
{
new MarkdownPart(content:"# my first part in 1st column")
.WithRowSpan(3).WithColSpan(2)
.GeneratePart(),
new MarkdownPart(content:"# my second part in 1st column")
.WithRowSpan(3).WithColSpan(2)
.GeneratePart()
}, out int firstColumnMaxX) // firstRowMaxY is what we should set the new row Y value
.AddPartsAsColumn(new List<Part>()
{
new MarkdownPart(content:"# my first part in 2nd column")
.WithRowSpan(4).WithColSpan(2)
.GeneratePart(),
new MarkdownPart(content:"# my second part in 2nd column")
.WithRowSpan(4).WithColSpan(2)
.GeneratePart()
}, out int secondColumnMaxX, startXPos:firstColumnMaxX)
.AddPartsAsColumn(new List<Part>()
{
new MarkdownPart(content:"# my first part in 3rd column")
.WithRowSpan(5).WithColSpan(2)
.GeneratePart(),
new MarkdownPart(content:"# my second part in 3rd column")
.WithRowSpan(5).WithColSpan(2)
.GeneratePart()
}, out int thirdColumnMaxX, startXPos:secondColumnMaxX)
.AddPartsAsRow(new List<Part>()
{
new MarkdownPart(content: "# my first part in the 4th column - as 1st row")
.WithX(thirdColumnMaxX)
.WithRowSpan(10).WithColSpan(6)
.GeneratePart(),
new MarkdownPart(content: "# my second part in the 5th column - as 1st row")
.WithX(thirdColumnMaxX)
.WithRowSpan(10).WithColSpan(6)
.GeneratePart()
}, out int firstRowMaxY)
.AddPartsAsRow(new List<Part>()
{
new MarkdownPart(content: "# my first part in the 4th column - as 2nd row")
.WithX(thirdColumnMaxX)
.WithRowSpan(10).WithColSpan(6)
.GeneratePart(),
new MarkdownPart(content: "# my second part in the 5th column - as 2nd row")
.WithX(thirdColumnMaxX)
.WithRowSpan(10).WithColSpan(6)
.GeneratePart()
}, out int secondRowMaxY, startYPos: firstRowMaxY)
)
.Build();
Assert.Equal(
"{\"properties\":{\"lenses\":{\"0\":{\"order\":0,\"parts\":{\"0\":{\"position\":{\"x\":0,\"y\":0,\"colSpan\":2,\"rowSpan\":3},\"metadata\":{\"type\":\"Extension/HubsExtension/PartType/MarkdownPart\",\"inputs\":[],\"settings\":{\"content\":{\"settings\":{\"content\":\"# my first part in 1st column\",\"title\":\"\",\"subtitle\":\"\",\"markdownSource\":1,\"markdownUri\":null}}}}},\"1\":{\"position\":{\"x\":0,\"y\":3,\"colSpan\":2,\"rowSpan\":3},\"metadata\":{\"type\":\"Extension/HubsExtension/PartType/MarkdownPart\",\"inputs\":[],\"settings\":{\"content\":{\"settings\":{\"content\":\"# my second part in 1st column\",\"title\":\"\",\"subtitle\":\"\",\"markdownSource\":1,\"markdownUri\":null}}}}},\"2\":{\"position\":{\"x\":2,\"y\":0,\"colSpan\":2,\"rowSpan\":4},\"metadata\":{\"type\":\"Extension/HubsExtension/PartType/MarkdownPart\",\"inputs\":[],\"settings\":{\"content\":{\"settings\":{\"content\":\"# my first part in 2nd column\",\"title\":\"\",\"subtitle\":\"\",\"markdownSource\":1,\"markdownUri\":null}}}}},\"3\":{\"position\":{\"x\":2,\"y\":4,\"colSpan\":2,\"rowSpan\":4},\"metadata\":{\"type\":\"Extension/HubsExtension/PartType/MarkdownPart\",\"inputs\":[],\"settings\":{\"content\":{\"settings\":{\"content\":\"# my second part in 2nd column\",\"title\":\"\",\"subtitle\":\"\",\"markdownSource\":1,\"markdownUri\":null}}}}},\"4\":{\"position\":{\"x\":4,\"y\":0,\"colSpan\":2,\"rowSpan\":5},\"metadata\":{\"type\":\"Extension/HubsExtension/PartType/MarkdownPart\",\"inputs\":[],\"settings\":{\"content\":{\"settings\":{\"content\":\"# my first part in 3rd column\",\"title\":\"\",\"subtitle\":\"\",\"markdownSource\":1,\"markdownUri\":null}}}}},\"5\":{\"position\":{\"x\":4,\"y\":5,\"colSpan\":2,\"rowSpan\":5},\"metadata\":{\"type\":\"Extension/HubsExtension/PartType/MarkdownPart\",\"inputs\":[],\"settings\":{\"content\":{\"settings\":{\"content\":\"# my second part in 3rd column\",\"title\":\"\",\"subtitle\":\"\",\"markdownSource\":1,\"markdownUri\":null}}}}},\"6\":{\"position\":{\"x\":6,\"y\":0,\"colSpan\":6,\"rowSpan\":10},\"metadata\":{\"type\":\"Extension/HubsExtension/PartType/MarkdownPart\",\"inputs\":[],\"settings\":{\"content\":{\"settings\":{\"content\":\"# my first part in the 4th column - as 1st row\",\"title\":\"\",\"subtitle\":\"\",\"markdownSource\":1,\"markdownUri\":null}}}}},\"7\":{\"position\":{\"x\":12,\"y\":0,\"colSpan\":6,\"rowSpan\":10},\"metadata\":{\"type\":\"Extension/HubsExtension/PartType/MarkdownPart\",\"inputs\":[],\"settings\":{\"content\":{\"settings\":{\"content\":\"# my second part in the 5th column - as 1st row\",\"title\":\"\",\"subtitle\":\"\",\"markdownSource\":1,\"markdownUri\":null}}}}},\"8\":{\"position\":{\"x\":6,\"y\":10,\"colSpan\":6,\"rowSpan\":10},\"metadata\":{\"type\":\"Extension/HubsExtension/PartType/MarkdownPart\",\"inputs\":[],\"settings\":{\"content\":{\"settings\":{\"content\":\"# my first part in the 4th column - as 2nd row\",\"title\":\"\",\"subtitle\":\"\",\"markdownSource\":1,\"markdownUri\":null}}}}},\"9\":{\"position\":{\"x\":12,\"y\":10,\"colSpan\":6,\"rowSpan\":10},\"metadata\":{\"type\":\"Extension/HubsExtension/PartType/MarkdownPart\",\"inputs\":[],\"settings\":{\"content\":{\"settings\":{\"content\":\"# my second part in the 5th column - as 2nd row\",\"title\":\"\",\"subtitle\":\"\",\"markdownSource\":1,\"markdownUri\":null}}}}}}}},\"metadata\":{\"model\":{\"timeRange\":{\"value\":{\"relative\":{\"duration\":24,\"timeUnit\":1}},\"type\":\"MsPortalFx.Composition.Configuration.ValueTypes.TimeRange\"},\"filters\":{\"value\":{\"MsPortalFx_TimeRange\":{\"model\":{\"format\":\"utc\",\"granularity\":\"auto\",\"relative\":\"24h\"},\"displayCache\":{\"name\":\"UTC Time\",\"value\":\"Past 24 hours\"},\"filteredPartIds\":[]}}},\"filterLocale\":{\"value\":\"en-us\"}}}},\"name\":\"ce043e69-f9f3-4618-bbe2-2a93e769b56d\",\"type\":\"Microsoft.Portal/dashboards\",\"location\":null,\"tags\":{\"hidden-title\":\"ce043e69-f9f3-4618-bbe2-2a93e769b56d\"}}",
Dashboard.Generator.Generate(dashboard));
}
}
}