Skip to content

Commit 2819e3e

Browse files
Initial Development
1 parent 13668c7 commit 2819e3e

18 files changed

+1086
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
8+
<IsPackable>false</IsPackable>
9+
<IsTestProject>true</IsTestProject>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
14+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
15+
<PackageReference Include="MSTest.TestAdapter" Version="3.0.4" />
16+
<PackageReference Include="MSTest.TestFramework" Version="3.0.4" />
17+
<PackageReference Include="coverlet.collector" Version="6.0.0" />
18+
<PackageReference Include="RichardSzalay.MockHttp" Version="7.0.0" />
19+
<PackageReference Include="Serilog" Version="4.0.0" />
20+
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
21+
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
22+
</ItemGroup>
23+
24+
<ItemGroup>
25+
<ProjectReference Include="..\Skyline.DataMiner.CICD.Tools.MSTeamsWorkflowWebhookCard.Lib\CICD.Tools.MSTeamsWorkflowWebhookCard.Lib.csproj" />
26+
</ItemGroup>
27+
28+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
namespace Skyline.DataMiner.CICD.Tools.MSTeamsWorkflowWebhookCard.Lib.Tests
2+
{
3+
using System.Text;
4+
5+
using Microsoft.Extensions.Logging;
6+
using Microsoft.VisualStudio.TestTools.UnitTesting;
7+
8+
using RichardSzalay.MockHttp;
9+
10+
using Serilog;
11+
12+
[TestClass()]
13+
public class CicdCardTests
14+
{
15+
[TestMethod()]
16+
public async Task SendAsyncTest_TestFormatIsValidForTeams()
17+
{
18+
// Arrange
19+
var mockHttp = new MockHttpMessageHandler();
20+
21+
var logConfig = new LoggerConfiguration().WriteTo.Console();
22+
logConfig.MinimumLevel.Is(Serilog.Events.LogEventLevel.Debug);
23+
var seriLog = logConfig.CreateLogger();
24+
25+
using var loggerFactory = LoggerFactory.Create(builder => builder.AddSerilog(seriLog));
26+
var logger = loggerFactory.CreateLogger("Skyline.DataMiner.CICD.Tools.MSTeamsWorkflowWebhookCard");
27+
28+
string name = "TestPipeline";
29+
CicdResult result = CicdResult.Success;
30+
string details = "Some Details";
31+
string pathToBuild = "https://skyline.be/skyline/about";
32+
string iconOfService = "https://skyline.be/skylicons/duotone/SkylineLogo_Duo_Light.png";
33+
string url = "https://skyline.be/";
34+
35+
var matcher = new TeamsAdaptiveCardMatcher(logger);
36+
var responseContent = new StringContent("OK", Encoding.UTF8, "application/string");
37+
mockHttp.When(HttpMethod.Post, url).With(matcher).Respond(System.Net.HttpStatusCode.OK, responseContent);
38+
39+
using var client = mockHttp.ToHttpClient();
40+
41+
// Act
42+
var card = new CicdCard(logger, client);
43+
card.ApplyConfiguration(name, result, details, pathToBuild, iconOfService);
44+
await card.SendAsync(url);
45+
46+
// Assert
47+
mockHttp.VerifyNoOutstandingExpectation();
48+
}
49+
50+
51+
[TestMethod(), Ignore]
52+
public async Task SendAsyncTest_IntegrationTest()
53+
{
54+
// Arrange
55+
var logConfig = new LoggerConfiguration().WriteTo.Console();
56+
logConfig.MinimumLevel.Is(Serilog.Events.LogEventLevel.Debug);
57+
var seriLog = logConfig.CreateLogger();
58+
59+
using var loggerFactory = LoggerFactory.Create(builder => builder.AddSerilog(seriLog));
60+
var logger = loggerFactory.CreateLogger("Skyline.DataMiner.CICD.Tools.MSTeamsWorkflowWebhookCard");
61+
62+
string name = "IntegrationTestPipeline";
63+
CicdResult result = CicdResult.Success;
64+
string details = "This is an integration test running from the testbattery. \r\n This should be on a second line!";
65+
string pathToBuild = "https://github.com/SkylineCommunications/Skyline.DataMiner.CICD.Tools.MSTeamsWorkflowWebhookCard";
66+
string iconOfService = "https://skyline.be/skylicons/duotone/SkylineLogo_Duo_Light.png";
67+
string url = "EnterWebHookFromTeamsChannelHere";
68+
69+
using HttpClient client = new HttpClient();
70+
71+
// Act
72+
var card = new CicdCard(logger, client);
73+
card.ApplyConfiguration(name, result, details, pathToBuild, iconOfService);
74+
await card.SendAsync(url);
75+
76+
// Assert
77+
78+
// Manual Verification of content as this is Graphical Design.
79+
Assert.IsTrue(true);
80+
}
81+
}
82+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
namespace Skyline.DataMiner.CICD.Tools.MSTeamsWorkflowWebhookCard.Lib.Tests
2+
{
3+
using System.Collections.Generic;
4+
5+
/// <summary>
6+
/// Represents an action in a body element.
7+
/// </summary>
8+
public class Action
9+
{
10+
/// <summary>
11+
/// Gets or sets the title of the action.
12+
/// </summary>
13+
public string? Title { get; set; }
14+
15+
/// <summary>
16+
/// Gets or sets the type of the action.
17+
/// </summary>
18+
public string? Type { get; set; }
19+
20+
/// <summary>
21+
/// Gets or sets the URL associated with the action.
22+
/// </summary>
23+
public string? Url { get; set; }
24+
}
25+
26+
/// <summary>
27+
/// Represents an attachment in a Teams message.
28+
/// </summary>
29+
public class Attachment
30+
{
31+
/// <summary>
32+
/// Gets or sets the content of the attachment.
33+
/// </summary>
34+
public Content? Content { get; set; }
35+
36+
/// <summary>
37+
/// Gets or sets the content type of the attachment.
38+
/// </summary>
39+
public string? ContentType { get; set; }
40+
}
41+
42+
/// <summary>
43+
/// Represents an element in the body of an attachment content.
44+
/// </summary>
45+
public class BodyElement
46+
{
47+
/// <summary>
48+
/// Gets or sets the list of actions in the body element.
49+
/// </summary>
50+
public List<Action>? Actions { get; set; }
51+
52+
/// <summary>
53+
/// Gets or sets the alternative text for the body element.
54+
/// </summary>
55+
public string? AltText { get; set; }
56+
57+
/// <summary>
58+
/// Gets or sets the list of columns in the body element.
59+
/// </summary>
60+
public List<Column>? Columns { get; set; }
61+
62+
/// <summary>
63+
/// Gets or sets the list of facts in the body element.
64+
/// </summary>
65+
public List<Fact>? Facts { get; set; }
66+
67+
/// <summary>
68+
/// Gets or sets the list of items in the body element.
69+
/// </summary>
70+
public List<Item>? Items { get; set; }
71+
72+
/// <summary>
73+
/// Gets or sets the size of the body element.
74+
/// </summary>
75+
public string? Size { get; set; }
76+
77+
/// <summary>
78+
/// Gets or sets the text of the body element.
79+
/// </summary>
80+
public string? Text { get; set; }
81+
82+
/// <summary>
83+
/// Gets or sets the type of the body element.
84+
/// </summary>
85+
public string? Type { get; set; }
86+
87+
/// <summary>
88+
/// Gets or sets the URL associated with the body element.
89+
/// </summary>
90+
public string? Url { get; set; }
91+
92+
/// <summary>
93+
/// Gets or sets the width of the body element.
94+
/// </summary>
95+
public string? Width { get; set; }
96+
97+
/// <summary>
98+
/// Gets or sets a value indicating whether the text should wrap.
99+
/// </summary>
100+
public bool Wrap { get; set; }
101+
}
102+
103+
/// <summary>
104+
/// Represents a column in a body element.
105+
/// </summary>
106+
public class Column
107+
{
108+
/// <summary>
109+
/// Gets or sets the list of items in the column.
110+
/// </summary>
111+
public List<Item>? Items { get; set; }
112+
113+
/// <summary>
114+
/// Gets or sets the type of the column.
115+
/// </summary>
116+
public string? Type { get; set; }
117+
118+
/// <summary>
119+
/// Gets or sets the width of the column.
120+
/// </summary>
121+
public string? Width { get; set; }
122+
}
123+
124+
/// <summary>
125+
/// Represents the content of an attachment.
126+
/// </summary>
127+
public class Content
128+
{
129+
/// <summary>
130+
/// Gets or sets the list of body elements in the content.
131+
/// </summary>
132+
public List<BodyElement>? Body { get; set; }
133+
134+
/// <summary>
135+
/// Gets or sets the type of the content.
136+
/// </summary>
137+
public string? Type { get; set; }
138+
139+
/// <summary>
140+
/// Gets or sets the version of the content.
141+
/// </summary>
142+
public string? Version { get; set; }
143+
}
144+
145+
/// <summary>
146+
/// Represents a fact in a body element.
147+
/// </summary>
148+
public class Fact
149+
{
150+
/// <summary>
151+
/// Gets or sets the title of the fact.
152+
/// </summary>
153+
public string? Title { get; set; }
154+
155+
/// <summary>
156+
/// Gets or sets the value of the fact.
157+
/// </summary>
158+
public string? Value { get; set; }
159+
}
160+
161+
/// <summary>
162+
/// Represents an item in a body element or column.
163+
/// </summary>
164+
public class Item
165+
{
166+
/// <summary>
167+
/// Gets or sets the alternative text for the item.
168+
/// </summary>
169+
public string? AltText { get; set; }
170+
171+
/// <summary>
172+
/// Gets or sets the size of the item.
173+
/// </summary>
174+
public string? Size { get; set; }
175+
176+
/// <summary>
177+
/// Gets or sets the text of the item.
178+
/// </summary>
179+
public string? Text { get; set; }
180+
181+
/// <summary>
182+
/// Gets or sets the type of the item.
183+
/// </summary>
184+
public string? Type { get; set; }
185+
186+
/// <summary>
187+
/// Gets or sets the URL associated with the item.
188+
/// </summary>
189+
public string? Url { get; set; }
190+
191+
/// <summary>
192+
/// Gets or sets the weight of the item.
193+
/// </summary>
194+
public string? Weight { get; set; }
195+
196+
/// <summary>
197+
/// Gets or sets a value indicating whether the text should wrap.
198+
/// </summary>
199+
public bool Wrap { get; set; }
200+
}
201+
202+
/// <summary>
203+
/// Represents a Teams message.
204+
/// </summary>
205+
public class Message
206+
{
207+
/// <summary>
208+
/// Gets or sets the list of attachments in the message.
209+
/// </summary>
210+
public List<Attachment>? Attachments { get; set; }
211+
212+
/// <summary>
213+
/// Gets or sets the type of the message.
214+
/// </summary>
215+
public string? Type { get; set; }
216+
}
217+
}

0 commit comments

Comments
 (0)