Skip to content

Commit 42a9436

Browse files
authored
Merge pull request #33 from xm-i/testing-improvement-colormodel-9837427964900693405
🧪 [testing improvement] Add unit tests for ColorModel
2 parents a0b5f28 + 0e5e804 commit 42a9436

3 files changed

Lines changed: 143 additions & 0 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net10.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
<PlatformTarget>x64</PlatformTarget>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
12+
<PackageReference Include="Microsoft.TestPlatform" Version="18.3.0" />
13+
<PackageReference Include="Shouldly" Version="4.3.0" />
14+
<PackageReference Include="xunit" Version="2.9.3" />
15+
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5" />
16+
</ItemGroup>
17+
18+
<ItemGroup>
19+
<ProjectReference Include="..\RemoteLogViewer.Composition\RemoteLogViewer.Composition.csproj" />
20+
</ItemGroup>
21+
22+
<ItemGroup>
23+
<Using Include="Xunit" />
24+
</ItemGroup>
25+
26+
</Project>
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
using RemoteLogViewer.Composition.Utils.Objects;
2+
3+
using Shouldly;
4+
5+
namespace RemoteLogViewer.Composition.Tests.Utils.Objects;
6+
7+
/// <summary>
8+
/// <see cref="ColorModel"/> のテストクラスです。
9+
/// </summary>
10+
public class ColorModelTests {
11+
/// <summary>
12+
/// <see cref="ColorModel.FromArgb(byte, byte, byte, byte)"/> が正しくプロパティを設定することを確認します。
13+
/// </summary>
14+
[Fact]
15+
public void FromArgb_ShouldSetPropertiesCorrectly() {
16+
// Arrange
17+
byte a = 255;
18+
byte r = 100;
19+
byte g = 150;
20+
byte b = 200;
21+
22+
// Act
23+
var color = ColorModel.FromArgb(a, r, g, b);
24+
25+
// Assert
26+
color.A.ShouldBe(a);
27+
color.R.ShouldBe(r);
28+
color.G.ShouldBe(g);
29+
color.B.ShouldBe(b);
30+
}
31+
32+
/// <summary>
33+
/// <see cref="ColorModel.Equals(ColorModel?)"/> が正しく動作することを確認します。
34+
/// </summary>
35+
[Fact]
36+
public void Equals_ColorModel_ShouldWorkCorrectly() {
37+
// Arrange
38+
var color1 = ColorModel.FromArgb(255, 100, 150, 200);
39+
var color2 = ColorModel.FromArgb(255, 100, 150, 200);
40+
var color3 = ColorModel.FromArgb(255, 101, 150, 200);
41+
42+
// Assert
43+
color1.Equals(null).ShouldBeFalse();
44+
color1.Equals(color1).ShouldBeTrue();
45+
color1.Equals(color2).ShouldBeTrue();
46+
color1.Equals(color3).ShouldBeFalse();
47+
}
48+
49+
/// <summary>
50+
/// <see cref="ColorModel.Equals(object?)"/> が正しく動作することを確認します。
51+
/// </summary>
52+
[Fact]
53+
public void Equals_Object_ShouldWorkCorrectly() {
54+
// Arrange
55+
var color1 = ColorModel.FromArgb(255, 100, 150, 200);
56+
var color2 = ColorModel.FromArgb(255, 100, 150, 200);
57+
58+
// Assert
59+
color1.Equals((object?)null).ShouldBeFalse();
60+
color1.Equals("not a color").ShouldBeFalse();
61+
color1.Equals((object)color1).ShouldBeTrue();
62+
color1.Equals((object)color2).ShouldBeTrue();
63+
}
64+
65+
/// <summary>
66+
/// <see cref="ColorModel.GetHashCode"/> が同じ値のオブジェクトに対して同じハッシュコードを返すことを確認します。
67+
/// </summary>
68+
[Fact]
69+
public void GetHashCode_ShouldBeConsistent() {
70+
// Arrange
71+
var color1 = ColorModel.FromArgb(255, 100, 150, 200);
72+
var color2 = ColorModel.FromArgb(255, 100, 150, 200);
73+
74+
// Assert
75+
color1.GetHashCode().ShouldBe(color2.GetHashCode());
76+
}
77+
78+
/// <summary>
79+
/// 比較演算子が正しく動作することを確認します。
80+
/// </summary>
81+
[Fact]
82+
public void Operators_ShouldWorkCorrectly() {
83+
// Arrange
84+
var color1 = ColorModel.FromArgb(255, 100, 150, 200);
85+
var color2 = ColorModel.FromArgb(255, 100, 150, 200);
86+
var color3 = ColorModel.FromArgb(255, 101, 150, 200);
87+
ColorModel? nullColor = null;
88+
89+
// Assert
90+
(color1 == color2).ShouldBeTrue();
91+
(color1 != color2).ShouldBeFalse();
92+
(color1 == color3).ShouldBeFalse();
93+
(color1 != color3).ShouldBeTrue();
94+
(color1 == nullColor).ShouldBeFalse();
95+
(nullColor == color1).ShouldBeFalse();
96+
(nullColor == (ColorModel?)null).ShouldBeTrue();
97+
}
98+
99+
/// <summary>
100+
/// <see cref="ColorModel.ToString"/> が期待される形式の文字列を返すことを確認します。
101+
/// </summary>
102+
[Fact]
103+
public void ToString_ShouldReturnExpectedFormat() {
104+
// Arrange
105+
var color = ColorModel.FromArgb(0xFF, 0x12, 0x34, 0x56);
106+
107+
// Act
108+
var result = color.ToString();
109+
110+
// Assert
111+
result.ShouldBe("#FF123456");
112+
}
113+
}

RemoteLogViewer.slnx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@
4444
<BuildType Solution="Debug-Unpackaged|*" Project="Debug" />
4545
<BuildType Solution="Release-Unpackaged|*" Project="Release" />
4646
</Project>
47+
<Project Path="RemoteLogViewer.Composition.Tests/RemoteLogViewer.Composition.Tests.csproj" Id="098c3284-8303-484e-87a1-dd7ca870adb6">
48+
<BuildType Solution="Debug-Unpackaged|*" Project="Debug" />
49+
<BuildType Solution="Release-Unpackaged|*" Project="Release" />
50+
</Project>
4751
<Project Path="RemoteLogViewer.Core.Tests/RemoteLogViewer.Core.Tests.csproj" Id="15ab1059-0a93-4bfd-b38e-748a18fb3088">
4852
<BuildType Solution="Debug-Unpackaged|*" Project="Debug" />
4953
<BuildType Solution="Release-Unpackaged|*" Project="Release" />

0 commit comments

Comments
 (0)