Skip to content

Commit 945d626

Browse files
Add more unit tests
- Add unit tests for `BrowserStackAutomateException`. - Add global usings for test project.
1 parent 0ccefb8 commit 945d626

File tree

4 files changed

+142
-5
lines changed

4 files changed

+142
-5
lines changed

tests/MartinCostello.BrowserStack.Automate.Tests/BrowserStackAutomateClientExtensionsTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Copyright (c) Martin Costello, 2015. All rights reserved.
22
// Licensed under the Apache 2.0 license. See the LICENSE file in the project root for full license information.
33

4-
using Xunit;
5-
64
namespace MartinCostello.BrowserStack.Automate;
75

86
/// <summary>

tests/MartinCostello.BrowserStack.Automate.Tests/BrowserStackAutomateClientTests.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
using Microsoft.Extensions.DependencyInjection;
77
using Microsoft.Extensions.Logging;
88
using Polly.CircuitBreaker;
9-
using Shouldly;
10-
using Xunit;
11-
using Xunit.Abstractions;
129

1310
namespace MartinCostello.BrowserStack.Automate;
1411

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
// Copyright (c) Martin Costello, 2015. All rights reserved.
2+
// Licensed under the Apache 2.0 license. See the LICENSE file in the project root for full license information.
3+
4+
namespace MartinCostello.BrowserStack.Automate;
5+
6+
public static class BrowserStackAutomateExceptionTests
7+
{
8+
[Fact]
9+
public static void Default_Constructor_Initializes_Properties()
10+
{
11+
// Act
12+
var exception = new BrowserStackAutomateException();
13+
14+
// Assert
15+
exception.Message.ShouldBe("A BrowserStack Automate error occurred.");
16+
exception.ErrorDetail.ShouldBeNull();
17+
exception.InnerException.ShouldBeNull();
18+
}
19+
20+
[Fact]
21+
public static void Constructor_With_Message_Initializes_Properties()
22+
{
23+
// Arrange
24+
string expectedMessage = "Test message";
25+
26+
// Act
27+
var exception = new BrowserStackAutomateException(expectedMessage);
28+
29+
// Assert
30+
exception.Message.ShouldBe(expectedMessage);
31+
exception.ErrorDetail.ShouldBeNull();
32+
exception.InnerException.ShouldBeNull();
33+
}
34+
35+
[Fact]
36+
public static void Constructor_With_Message_And_InnerException_Initializes_Properties()
37+
{
38+
// Arrange
39+
string expectedMessage = "Test message";
40+
var innerException = new InvalidOperationException("Inner exception");
41+
42+
// Act
43+
var exception = new BrowserStackAutomateException(expectedMessage, innerException);
44+
45+
// Assert
46+
exception.Message.ShouldBe(expectedMessage);
47+
exception.ErrorDetail.ShouldBeNull();
48+
exception.InnerException.ShouldBeSameAs(innerException);
49+
}
50+
51+
[Fact]
52+
public static void Constructor_With_Null_ErrorDetail_Initializes_Properties()
53+
{
54+
// Arrange
55+
BrowserStackAutomateError? errorDetail = null;
56+
57+
// Act
58+
var exception = new BrowserStackAutomateException(errorDetail);
59+
60+
// Assert
61+
exception.Message.ShouldBe("A BrowserStack Automate error occurred.");
62+
exception.ErrorDetail.ShouldBeNull();
63+
exception.InnerException.ShouldBeNull();
64+
}
65+
66+
[Fact]
67+
public static void Constructor_With_Null_ErrorDetail_Message_Initializes_Properties()
68+
{
69+
// Arrange
70+
var errorDetail = new BrowserStackAutomateError() { Message = null! };
71+
72+
// Act
73+
var exception = new BrowserStackAutomateException(errorDetail);
74+
75+
// Assert
76+
exception.Message.ShouldBe("A BrowserStack Automate error occurred.");
77+
exception.ErrorDetail.ShouldBeSameAs(errorDetail);
78+
exception.InnerException.ShouldBeNull();
79+
}
80+
81+
[Fact]
82+
public static void Constructor_With_ErrorDetail_Initializes_Properties()
83+
{
84+
// Arrange
85+
var errorDetail = new BrowserStackAutomateError()
86+
{
87+
Message = "Test error message",
88+
};
89+
90+
// Act
91+
var exception = new BrowserStackAutomateException(errorDetail);
92+
93+
// Assert
94+
exception.Message.ShouldBe(errorDetail.Message);
95+
exception.ErrorDetail.ShouldBeSameAs(errorDetail);
96+
exception.InnerException.ShouldBeNull();
97+
}
98+
99+
[Fact]
100+
public static void Constructor_With_Message_And_ErrorDetail_Initializes_Properties()
101+
{
102+
// Arrange
103+
string expectedMessage = "Test message";
104+
var errorDetail = new BrowserStackAutomateError()
105+
{
106+
Message = "Test error message",
107+
};
108+
109+
// Act
110+
var exception = new BrowserStackAutomateException(expectedMessage, errorDetail);
111+
112+
// Assert
113+
exception.Message.ShouldBe(expectedMessage);
114+
exception.ErrorDetail.ShouldBeSameAs(errorDetail);
115+
exception.InnerException.ShouldBeNull();
116+
}
117+
118+
[Fact]
119+
public static void Constructor_With_Message_Inner_Exception_And_ErrorDetail_Initializes_Properties()
120+
{
121+
// Arrange
122+
string expectedMessage = "Test message";
123+
var innerException = new InvalidOperationException("Inner exception");
124+
var errorDetail = new BrowserStackAutomateError()
125+
{
126+
Message = "Test error message",
127+
};
128+
129+
// Act
130+
var exception = new BrowserStackAutomateException(expectedMessage, errorDetail, innerException);
131+
132+
// Assert
133+
exception.Message.ShouldBe(expectedMessage);
134+
exception.ErrorDetail.ShouldBeSameAs(errorDetail);
135+
exception.InnerException.ShouldBeSameAs(innerException);
136+
}
137+
}

tests/MartinCostello.BrowserStack.Automate.Tests/MartinCostello.BrowserStack.Automate.Tests.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@
2929
<PackageReference Include="xunit.runner.visualstudio" />
3030
<PackageReference Include="Xunit.SkippableFact" />
3131
</ItemGroup>
32+
<ItemGroup>
33+
<Using Include="Shouldly" />
34+
<Using Include="Xunit" />
35+
<Using Include="Xunit.Abstractions" />
36+
</ItemGroup>
3237
<PropertyGroup Condition=" '$(BuildingInsideVisualStudio)' != 'true' ">
3338
<CollectCoverage>true</CollectCoverage>
3439
<CoverletOutputFormat>cobertura,json</CoverletOutputFormat>

0 commit comments

Comments
 (0)