1
- namespace Skyline . DataMiner . CICD . Tools . MSTeamsWorkflowWebhookCard . Lib . Tests
1
+ namespace CICD . Tools . MSTeamsWorkflowWebhookCard . LibTests
2
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
- }
3
+ using System . Net . Http ;
4
+ using System . Text ;
5
+ using System . Threading . Tasks ;
6
+
7
+ using CICD . Tools . MSTeamsWorkflowWebhookCard . LibTests . MatchTeamsRequirement ;
8
+
9
+ using Microsoft . Extensions . Logging ;
10
+ using Microsoft . VisualStudio . TestTools . UnitTesting ;
11
+
12
+ using RichardSzalay . MockHttp ;
13
+
14
+ using Serilog ;
15
+
16
+ using Skyline . DataMiner . CICD . Tools . MSTeamsWorkflowWebhookCard . Lib ;
17
+
18
+ [ TestClass ]
19
+ public class CicdCardTests
20
+ {
21
+ [ TestMethod ]
22
+ public async Task SendAsyncTest_TestFormatIsValidForTeams ( )
23
+ {
24
+ // Arrange
25
+ var mockHttp = new MockHttpMessageHandler ( ) ;
26
+
27
+ var logConfig = new LoggerConfiguration ( ) . WriteTo . Console ( ) ;
28
+ logConfig . MinimumLevel . Is ( Serilog . Events . LogEventLevel . Debug ) ;
29
+ var seriLog = logConfig . CreateLogger ( ) ;
30
+
31
+ using ( var loggerFactory = LoggerFactory . Create ( builder => builder . AddSerilog ( seriLog ) ) )
32
+ {
33
+ var logger = loggerFactory . CreateLogger ( "Skyline.DataMiner.CICD.Tools.MSTeamsWorkflowWebhookCard" ) ;
34
+
35
+ const string name = "TestPipeline" ;
36
+ const CicdResult result = CicdResult . Success ;
37
+ const string details = "Some Details" ;
38
+ const string pathToBuild = "https://skyline.be/skyline/about" ;
39
+ const string iconOfService = "https://skyline.be/skylicons/duotone/SkylineLogo_Duo_Light.png" ;
40
+ const string url = "https://skyline.be/" ;
41
+
42
+ var matcher = new TeamsAdaptiveCardMatcher ( logger ) ;
43
+ var responseContent = new StringContent ( "OK" , Encoding . UTF8 , "application/string" ) ;
44
+ mockHttp . When ( HttpMethod . Post , url ) . With ( matcher ) . Respond ( System . Net . HttpStatusCode . OK , responseContent ) ;
45
+
46
+ using ( var client = mockHttp . ToHttpClient ( ) )
47
+ {
48
+ // Act
49
+ var card = new CicdCard ( logger , client ) ;
50
+ card . ApplyConfiguration ( name , result , details , pathToBuild , iconOfService ) ;
51
+ await card . SendAsync ( url ) ;
52
+
53
+ // Assert
54
+ mockHttp . VerifyNoOutstandingExpectation ( ) ;
55
+ }
56
+ }
57
+ }
58
+
59
+ [ TestMethod , Ignore ]
60
+ public async Task SendAsyncTest_IntegrationTest ( )
61
+ {
62
+ // Arrange
63
+ var logConfig = new LoggerConfiguration ( ) . WriteTo . Console ( ) ;
64
+ logConfig . MinimumLevel . Is ( Serilog . Events . LogEventLevel . Debug ) ;
65
+ var seriLog = logConfig . CreateLogger ( ) ;
66
+
67
+ using ( var loggerFactory = LoggerFactory . Create ( builder => builder . AddSerilog ( seriLog ) ) )
68
+ {
69
+ var logger = loggerFactory . CreateLogger ( "Skyline.DataMiner.CICD.Tools.MSTeamsWorkflowWebhookCard" ) ;
70
+
71
+ const string name = "IntegrationTestPipeline" ;
72
+ const CicdResult result = CicdResult . Success ;
73
+ const string details = "This is an integration test running from the testbattery. \r \n This should be on a second line!" ;
74
+ const string pathToBuild = "https://github.com/SkylineCommunications/Skyline.DataMiner.CICD.Tools.MSTeamsWorkflowWebhookCard" ;
75
+ const string iconOfService = "https://skyline.be/skylicons/duotone/SkylineLogo_Duo_Light.png" ;
76
+ const string url = "EnterWebHookFromTeamsChannelHere" ;
77
+
78
+ using ( HttpClient client = new HttpClient ( ) )
79
+ {
80
+ // Act
81
+ var card = new CicdCard ( logger , client ) ;
82
+ card . ApplyConfiguration ( name , result , details , pathToBuild , iconOfService ) ;
83
+ await card . SendAsync ( url ) ;
84
+
85
+ // Assert
86
+
87
+ // Manual Verification of content as this is Graphical Design.
88
+ Assert . IsTrue ( true ) ;
89
+ }
90
+ }
91
+ }
92
+ }
82
93
}
0 commit comments