Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial Development #1

Merged
merged 3 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
root = true

[*]
indent_style = space
indent_size = 4
trim_trailing_whitespace = true

[*.csproj]
indent_size = 2

[*.cs]
dotnet_sort_system_directives_first = true
dotnet_style_predefined_type_for_locals_parameters_members = true
dotnet_style_predefined_type_for_member_access = false
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net48;net8.0</TargetFrameworks>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>disable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.5.0" />
<PackageReference Include="MSTest.TestFramework" Version="3.5.0" />
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="RichardSzalay.MockHttp" Version="7.0.0" />
<PackageReference Include="Serilog" Version="4.0.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Skyline.DataMiner.CICD.Tools.MSTeamsWorkflowWebhookCard.Lib\CICD.Tools.MSTeamsWorkflowWebhookCard.Lib.csproj" />
</ItemGroup>

</Project>
93 changes: 93 additions & 0 deletions CICD.Tools.MSTeamsWorkflowWebhookCard.LibTests/CicdCardTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
namespace CICD.Tools.MSTeamsWorkflowWebhookCard.LibTests
{
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

using CICD.Tools.MSTeamsWorkflowWebhookCard.LibTests.MatchTeamsRequirement;

using Microsoft.Extensions.Logging;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using RichardSzalay.MockHttp;

using Serilog;

using Skyline.DataMiner.CICD.Tools.MSTeamsWorkflowWebhookCard.Lib;

[TestClass]
public class CicdCardTests
{
[TestMethod]
public async Task SendAsyncTest_TestFormatIsValidForTeams()
{
// Arrange
var mockHttp = new MockHttpMessageHandler();

var logConfig = new LoggerConfiguration().WriteTo.Console();
logConfig.MinimumLevel.Is(Serilog.Events.LogEventLevel.Debug);
var seriLog = logConfig.CreateLogger();

using (var loggerFactory = LoggerFactory.Create(builder => builder.AddSerilog(seriLog)))
{
var logger = loggerFactory.CreateLogger("Skyline.DataMiner.CICD.Tools.MSTeamsWorkflowWebhookCard");

const string name = "TestPipeline";
const CicdResult result = CicdResult.Success;
const string details = "Some Details";
const string pathToBuild = "https://skyline.be/skyline/about";
const string iconOfService = "https://skyline.be/skylicons/duotone/SkylineLogo_Duo_Light.png";
const string url = "https://skyline.be/";

var matcher = new TeamsAdaptiveCardMatcher(logger);
var responseContent = new StringContent("OK", Encoding.UTF8, "application/string");
mockHttp.When(HttpMethod.Post, url).With(matcher).Respond(System.Net.HttpStatusCode.OK, responseContent);

using (var client = mockHttp.ToHttpClient())
{
// Act
var card = new CicdCard(logger, client);
card.ApplyConfiguration(name, result, details, pathToBuild, iconOfService);
await card.SendAsync(url);

// Assert
mockHttp.VerifyNoOutstandingExpectation();
}
}
}

[TestMethod, Ignore("For Manual Running. Fill in a valid webhook url to a teams workflow.")]
public async Task SendAsyncTest_IntegrationTest()
{
// Arrange
var logConfig = new LoggerConfiguration().WriteTo.Console();
logConfig.MinimumLevel.Is(Serilog.Events.LogEventLevel.Debug);
var seriLog = logConfig.CreateLogger();

using (var loggerFactory = LoggerFactory.Create(builder => builder.AddSerilog(seriLog)))
{
var logger = loggerFactory.CreateLogger("Skyline.DataMiner.CICD.Tools.MSTeamsWorkflowWebhookCard");

const string name = "IntegrationTestPipeline";
const CicdResult result = CicdResult.Success;
const string details = "This is an integration test running from the testbattery. \r\n This should be on a second line!";
const string pathToBuild = "https://github.com/SkylineCommunications/Skyline.DataMiner.CICD.Tools.MSTeamsWorkflowWebhookCard";
const string iconOfService = "https://skyline.be/skylicons/duotone/SkylineLogo_Duo_Light.png";
const string url = "EnterWebHookFromTeamsChannelHere";

using (HttpClient client = new HttpClient())
{
// Act
var card = new CicdCard(logger, client);
card.ApplyConfiguration(name, result, details, pathToBuild, iconOfService);
await card.SendAsync(url);

// Assert

// Manual Verification of content as this is Graphical Design.
Assert.IsTrue(true);
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
namespace CICD.Tools.MSTeamsWorkflowWebhookCard.LibTests.MatchTeamsRequirement
{
using System.Collections.Generic;

/// <summary>
/// Represents an action in a body element.
/// </summary>
public class Action
{
/// <summary>
/// Gets or sets the title of the action.
/// </summary>
public string Title { get; set; }

/// <summary>
/// Gets or sets the type of the action.
/// </summary>
public string Type { get; set; }

/// <summary>
/// Gets or sets the URL associated with the action.
/// </summary>
public string Url { get; set; }
}

/// <summary>
/// Represents an attachment in a Teams message.
/// </summary>
public class Attachment
{
/// <summary>
/// Gets or sets the content of the attachment.
/// </summary>
public Content Content { get; set; }

/// <summary>
/// Gets or sets the content type of the attachment.
/// </summary>
public string ContentType { get; set; }
}

/// <summary>
/// Represents an element in the body of an attachment content.
/// </summary>
public class BodyElement
{
/// <summary>
/// Gets or sets the list of actions in the body element.
/// </summary>
public List<Action> Actions { get; set; }

/// <summary>
/// Gets or sets the alternative text for the body element.
/// </summary>
public string AltText { get; set; }

/// <summary>
/// Gets or sets the list of columns in the body element.
/// </summary>
public List<Column> Columns { get; set; }

/// <summary>
/// Gets or sets the list of facts in the body element.
/// </summary>
public List<Fact> Facts { get; set; }

/// <summary>
/// Gets or sets the list of items in the body element.
/// </summary>
public List<Item> Items { get; set; }

/// <summary>
/// Gets or sets the size of the body element.
/// </summary>
public string Size { get; set; }

/// <summary>
/// Gets or sets the text of the body element.
/// </summary>
public string Text { get; set; }

/// <summary>
/// Gets or sets the type of the body element.
/// </summary>
public string Type { get; set; }

/// <summary>
/// Gets or sets the URL associated with the body element.
/// </summary>
public string Url { get; set; }

/// <summary>
/// Gets or sets the width of the body element.
/// </summary>
public string Width { get; set; }

/// <summary>
/// Gets or sets a value indicating whether the text should wrap.
/// </summary>
public bool Wrap { get; set; }
}

/// <summary>
/// Represents a column in a body element.
/// </summary>
public class Column
{
/// <summary>
/// Gets or sets the list of items in the column.
/// </summary>
public List<Item> Items { get; set; }

/// <summary>
/// Gets or sets the type of the column.
/// </summary>
public string Type { get; set; }

/// <summary>
/// Gets or sets the width of the column.
/// </summary>
public string Width { get; set; }
}

/// <summary>
/// Represents the content of an attachment.
/// </summary>
public class Content
{
/// <summary>
/// Gets or sets the list of body elements in the content.
/// </summary>
public List<BodyElement> Body { get; set; }

/// <summary>
/// Gets or sets the type of the content.
/// </summary>
public string Type { get; set; }

/// <summary>
/// Gets or sets the version of the content.
/// </summary>
public string Version { get; set; }
}

/// <summary>
/// Represents a fact in a body element.
/// </summary>
public class Fact
{
/// <summary>
/// Gets or sets the title of the fact.
/// </summary>
public string Title { get; set; }

/// <summary>
/// Gets or sets the value of the fact.
/// </summary>
public string Value { get; set; }
}

/// <summary>
/// Represents an item in a body element or column.
/// </summary>
public class Item
{
/// <summary>
/// Gets or sets the alternative text for the item.
/// </summary>
public string AltText { get; set; }

/// <summary>
/// Gets or sets the size of the item.
/// </summary>
public string Size { get; set; }

/// <summary>
/// Gets or sets the text of the item.
/// </summary>
public string Text { get; set; }

/// <summary>
/// Gets or sets the type of the item.
/// </summary>
public string Type { get; set; }

/// <summary>
/// Gets or sets the URL associated with the item.
/// </summary>
public string Url { get; set; }

/// <summary>
/// Gets or sets the weight of the item.
/// </summary>
public string Weight { get; set; }

/// <summary>
/// Gets or sets a value indicating whether the text should wrap.
/// </summary>
public bool Wrap { get; set; }
}

/// <summary>
/// Represents a Teams message.
/// </summary>
public class Message
{
/// <summary>
/// Gets or sets the list of attachments in the message.
/// </summary>
public List<Attachment> Attachments { get; set; }

/// <summary>
/// Gets or sets the type of the message.
/// </summary>
public string Type { get; set; }
}
}
Loading