Skip to content

Commit f4dbcc5

Browse files
zhenlei520blazor-component
authored andcommitted
Fix/configuration
1 parent 37307e5 commit f4dbcc5

7 files changed

Lines changed: 172 additions & 3 deletions

File tree

‎.editorconfig‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
[*.cs]
2+
3+
# CS8618: When exiting the constructor, the non-nullable field must contain a non-null value. Please consider declaring as nullable。
4+
dotnet_diagnostic.CS8618.severity = none
5+
6+
# top-most EditorConfig file
7+
root = true
8+
9+
# Don't use tabs for indentation.
10+
[*]
11+
indent_style = space
12+
trim_trailing_whitespace = true
13+
guidelines = 140
14+
max_line_length = 140
15+
16+
# Code files
17+
[*.{cs,csx,vb,vbx}]
18+
indent_size = 4
19+
insert_final_newline = true
20+
charset = utf-8
21+
22+
# Xml project files
23+
[*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,projitems,shproj}]
24+
indent_size = 2
25+
26+
# Xml config files
27+
[*.{props,targets,ruleset,config,nuspec,resx,vsixmanifest,vsct,xml,stylecop}]
28+
indent_size = 2
29+
30+
# JSON files
31+
[*.json]
32+
indent_size = 2

‎MASA.BuildingBlocks.sln‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MASA.BuildingBlocks.Data.Uo
4949
EndProject
5050
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MASA.BuildingBlocks.Configuration", "src\Configuration\MASA.BuildingBlocks.Configuration\MASA.BuildingBlocks.Configuration.csproj", "{1B72DF2B-CD4A-4634-9E11-30DCAEA3C881}"
5151
EndProject
52+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MASA.BuildingBlocks.Configuration.Tests", "test\MASA.BuildingBlocks.Configuration.Tests\MASA.BuildingBlocks.Configuration.Tests.csproj", "{C68DCC37-CBB0-4D1F-B83A-5353D6971A4C}"
53+
EndProject
5254
Global
5355
GlobalSection(SolutionConfigurationPlatforms) = preSolution
5456
Debug|Any CPU = Debug|Any CPU
@@ -95,6 +97,10 @@ Global
9597
{1B72DF2B-CD4A-4634-9E11-30DCAEA3C881}.Debug|Any CPU.Build.0 = Debug|Any CPU
9698
{1B72DF2B-CD4A-4634-9E11-30DCAEA3C881}.Release|Any CPU.ActiveCfg = Release|Any CPU
9799
{1B72DF2B-CD4A-4634-9E11-30DCAEA3C881}.Release|Any CPU.Build.0 = Release|Any CPU
100+
{C68DCC37-CBB0-4D1F-B83A-5353D6971A4C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
101+
{C68DCC37-CBB0-4D1F-B83A-5353D6971A4C}.Debug|Any CPU.Build.0 = Debug|Any CPU
102+
{C68DCC37-CBB0-4D1F-B83A-5353D6971A4C}.Release|Any CPU.ActiveCfg = Release|Any CPU
103+
{C68DCC37-CBB0-4D1F-B83A-5353D6971A4C}.Release|Any CPU.Build.0 = Release|Any CPU
98104
EndGlobalSection
99105
GlobalSection(SolutionProperties) = preSolution
100106
HideSolutionNode = FALSE
@@ -121,6 +127,7 @@ Global
121127
{DC8FFD2B-1A35-48AF-8CB9-5310E0BD1417} = {509BDB5A-5D32-478F-BF27-F0470C18C7C9}
122128
{49A817E9-17E2-4F6C-A732-73BD10B5E74B} = {64FB8703-E922-45DE-9D01-3FE9EFE56727}
123129
{1B72DF2B-CD4A-4634-9E11-30DCAEA3C881} = {77D17E30-CB7C-4DD7-8CF1-9D5350FF2304}
130+
{C68DCC37-CBB0-4D1F-B83A-5353D6971A4C} = {6ED365E6-4A1A-499F-85FB-F22E865CA4BA}
124131
EndGlobalSection
125132
GlobalSection(ExtensibilityGlobals) = postSolution
126133
SolutionGuid = {40383055-CC50-4600-AD9A-53C14F620D03}

‎src/Configuration/MASA.BuildingBlocks.Configuration/Properties.cs‎

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
namespace MASA.BuildingBlocks.Configuration;
2-
public class Properties
1+
namespace MASA.BuildingBlocks.Configuration;
2+
public class Properties : IEquatable<Properties>, IEquatable<object>
33
{
44
private readonly Dictionary<string, string> _dict;
55

@@ -22,4 +22,48 @@ public Properties(IDictionary<string, string>? dictionary) =>
2222
}
2323

2424
public ISet<string> GetPropertyNames() => new HashSet<string>(_dict.Keys);
25+
26+
public override bool Equals(object? obj)
27+
{
28+
if (this is null ^ obj is null) return false;
29+
30+
if (obj is Properties other)
31+
{
32+
return Equals(other);
33+
}
34+
else
35+
{
36+
return false;
37+
}
38+
}
39+
40+
public bool Equals(Properties? newProperties)
41+
{
42+
if (newProperties == null) return false;
43+
44+
return GetHashCode() == newProperties.GetHashCode();
45+
}
46+
47+
public static bool operator ==(Properties? x, Properties? y)
48+
{
49+
if (x is null ^ y is null) return false;
50+
51+
if (x is null) return true;
52+
53+
return x.Equals(y);
54+
}
55+
56+
public static bool operator !=(Properties? x, Properties? y)
57+
{
58+
if (x is null ^ y is null) return false;
59+
60+
if (x is null) return false;
61+
62+
return !x.Equals(y);
63+
}
64+
65+
public override int GetHashCode()
66+
{
67+
return _dict.Select(key => key.Key + key.Value).Aggregate(0, (hashCode, next) => HashCode.Combine(hashCode, next));
68+
}
2569
}

‎src/Service/MASA.BuildingBlocks.Service.MinimalAPIs/MASA.BuildingBlocks.Service.MinimalAPIs.csproj‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
<ItemGroup>
1010
<FrameworkReference Include="Microsoft.AspNetCore.App"></FrameworkReference>
11-
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="5.0.0" />
11+
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0-rc.2.21480.5" />
1212
</ItemGroup>
1313

1414
</Project>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net6.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<IsPackable>false</IsPackable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
12+
<PackageReference Include="MSTest.TestAdapter" Version="2.2.3" />
13+
<PackageReference Include="MSTest.TestFramework" Version="2.2.3" />
14+
<PackageReference Include="coverlet.collector" Version="3.0.2" />
15+
</ItemGroup>
16+
17+
<ItemGroup>
18+
<ProjectReference Include="..\..\src\Configuration\MASA.BuildingBlocks.Configuration\MASA.BuildingBlocks.Configuration.csproj" />
19+
</ItemGroup>
20+
21+
22+
</Project>
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
namespace MASA.BuildingBlocks.Configuration.Tests;
2+
3+
[TestClass]
4+
public class TestProperties
5+
{
6+
[TestMethod]
7+
public void TestEquals()
8+
{
9+
var id = Guid.NewGuid().ToString();
10+
var x = new Properties(new Dictionary<string, string>()
11+
{
12+
{"id", id},
13+
});
14+
var y = new Properties(new Dictionary<string, string>()
15+
{
16+
{"id", id},
17+
});
18+
var z = new Properties(new Dictionary<string, string>()
19+
{
20+
{"id2", Guid.NewGuid().ToString()},
21+
{"id", id}
22+
});
23+
Assert.IsTrue(x.Equals(y));
24+
Assert.IsTrue(!x.Equals(null));
25+
Assert.IsTrue(!x.Equals(z));
26+
Assert.IsTrue(!z.Equals(x));
27+
28+
var w = new Properties(new Dictionary<string, string>()
29+
{
30+
{"id", Guid.NewGuid().ToString()},
31+
});
32+
33+
Assert.IsFalse(x!.Equals(w));
34+
}
35+
36+
[TestMethod]
37+
public void TestGetHashCode()
38+
{
39+
var id = Guid.NewGuid().ToString();
40+
Properties x = new(new Dictionary<string, string>() { { "Id", id } });
41+
Properties y = new(new Dictionary<string, string>() { { "Id", id } });
42+
43+
Assert.AreEqual(x.GetHashCode(), y.GetHashCode());
44+
}
45+
46+
[TestMethod]
47+
public void TestOperator()
48+
{
49+
var id = Guid.NewGuid().ToString();
50+
Properties x = new(new Dictionary<string, string>() { { "Id", id } });
51+
Properties y = new(new Dictionary<string, string>() { { "Id", id } });
52+
Properties z = new(new Dictionary<string, string>() { { "Id", Guid.NewGuid().ToString() } });
53+
54+
Assert.IsTrue(x == y);
55+
Assert.IsTrue(x != z);
56+
57+
Properties m = null;
58+
Assert.IsTrue(m == null);
59+
Assert.IsTrue(null == m);
60+
Assert.IsFalse(null != m);
61+
Assert.IsFalse(m != null);
62+
}
63+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
global using Microsoft.VisualStudio.TestTools.UnitTesting;

0 commit comments

Comments
 (0)