Skip to content

Commit a65d0f7

Browse files
committed
snapshot
1 parent 3645c36 commit a65d0f7

17 files changed

+511
-80
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using System;
2+
using FluentAssertions;
3+
using Microsoft.VisualStudio.TestTools.UnitTesting;
4+
5+
namespace ValueTypeAssertions.Tests
6+
{
7+
[TestClass]
8+
public class CaseInsensitiveStringWithCaseSensitiveGetHashCode
9+
{
10+
[TestMethod]
11+
public void Test()
12+
{
13+
((Action) (() => ValueTypeAssertions.HasValueEquality(new C("foo"), new C("FOO"))))
14+
.ShouldThrow<AssertFailedException>()
15+
.And.Message.Should().Contain("GetHashCode");
16+
}
17+
18+
private class C : IEquatable<C>
19+
{
20+
public readonly string Value;
21+
22+
public C(string value)
23+
{
24+
Value = value;
25+
}
26+
27+
public bool Equals(C other)
28+
{
29+
if (ReferenceEquals(null, other)) return false;
30+
if (ReferenceEquals(this, other)) return true;
31+
return string.Equals(Value, other.Value, StringComparison.OrdinalIgnoreCase);
32+
}
33+
34+
public override bool Equals(object obj)
35+
{
36+
if (ReferenceEquals(null, obj)) return false;
37+
if (ReferenceEquals(this, obj)) return true;
38+
if (obj.GetType() != GetType()) return false;
39+
return Equals((C) obj);
40+
}
41+
42+
public override int GetHashCode()
43+
{
44+
return Value.GetHashCode();
45+
}
46+
47+
public static bool operator ==(C left, C right)
48+
{
49+
return Equals(left, right);
50+
}
51+
52+
public static bool operator !=(C left, C right)
53+
{
54+
return !Equals(left, right);
55+
}
56+
}
57+
}
58+
}
+112
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
using System;
2+
using FluentAssertions;
3+
using Microsoft.VisualStudio.TestTools.UnitTesting;
4+
5+
namespace ValueTypeAssertions.Tests
6+
{
7+
[TestClass]
8+
public class HappyPaths
9+
{
10+
[TestMethod]
11+
public void Int()
12+
{
13+
((Action) (() => ValueTypeAssertions.HasValueEquality(1, 1))).ShouldNotThrow();
14+
((Action) (() => ValueTypeAssertions.HasValueEquality(1, 2))).ShouldThrow<AssertFailedException>();
15+
((Action) (() => ValueTypeAssertions.HasValueInequality(2, 1))).ShouldNotThrow();
16+
((Action) (() => ValueTypeAssertions.HasValueInequality(2, 2))).ShouldThrow<AssertFailedException>();
17+
}
18+
19+
[TestMethod]
20+
public void String()
21+
{
22+
((Action) (() => ValueTypeAssertions.HasValueEquality("", ""))).ShouldNotThrow();
23+
((Action) (() => ValueTypeAssertions.HasValueEquality("foo", "foo"))).ShouldNotThrow();
24+
((Action) (() => ValueTypeAssertions.HasValueEquality("foo", "bar"))).ShouldThrow<AssertFailedException>();
25+
((Action) (() => ValueTypeAssertions.HasValueInequality("foo", "foo"))).ShouldThrow<AssertFailedException>();
26+
}
27+
28+
[TestMethod]
29+
public void CustomReferenceTypeTest()
30+
{
31+
((Action) (() => ValueTypeAssertions.HasValueEquality(new AClass(1), new AClass(1)))).ShouldNotThrow();
32+
((Action) (() => ValueTypeAssertions.HasValueEquality(new AClass(1), new AClass(2))))
33+
.ShouldThrow<AssertFailedException>();
34+
((Action) (() => ValueTypeAssertions.HasValueInequality(new AClass(1), new AClass(2)))).ShouldNotThrow();
35+
((Action) (() => ValueTypeAssertions.HasValueInequality(new AClass(1), new AClass(1))))
36+
.ShouldThrow<AssertFailedException>();
37+
}
38+
39+
[TestMethod]
40+
public void CustomValueTypeTest()
41+
{
42+
((Action) (() => ValueTypeAssertions.HasValueEquality(new AStruct(1), new AStruct(1)))).ShouldNotThrow();
43+
((Action) (() => ValueTypeAssertions.HasValueEquality(new AStruct(1), new AStruct(2))))
44+
.ShouldThrow<AssertFailedException>();
45+
((Action) (() => ValueTypeAssertions.HasValueInequality(new AStruct(1), new AStruct(2)))).ShouldNotThrow();
46+
((Action) (() => ValueTypeAssertions.HasValueInequality(new AStruct(1), new AStruct(1))))
47+
.ShouldThrow<AssertFailedException>();
48+
}
49+
50+
private struct AStruct : IEquatable<AStruct>
51+
{
52+
public readonly int X;
53+
54+
public AStruct(int x)
55+
{
56+
X = x;
57+
}
58+
59+
bool IEquatable<AStruct>.Equals(AStruct other) => Equals(other);
60+
61+
public static bool operator ==(AStruct left, AStruct right)
62+
{
63+
return left.Equals(right);
64+
}
65+
66+
public static bool operator !=(AStruct left, AStruct right)
67+
{
68+
return !left.Equals(right);
69+
}
70+
}
71+
72+
private class AClass : IEquatable<AClass>
73+
{
74+
public readonly int X;
75+
76+
public AClass(int x)
77+
{
78+
X = x;
79+
}
80+
81+
bool IEquatable<AClass>.Equals(AClass other)
82+
{
83+
if (ReferenceEquals(null, other)) return false;
84+
if (ReferenceEquals(this, other)) return true;
85+
return X == other.X;
86+
}
87+
88+
public override bool Equals(object obj)
89+
{
90+
if (ReferenceEquals(null, obj)) return false;
91+
if (ReferenceEquals(this, obj)) return true;
92+
if (obj.GetType() != GetType()) return false;
93+
return ((IEquatable<AClass>) this).Equals((AClass) obj);
94+
}
95+
96+
public override int GetHashCode()
97+
{
98+
return X.GetHashCode();
99+
}
100+
101+
public static bool operator ==(AClass left, AClass right)
102+
{
103+
return Equals(left, right);
104+
}
105+
106+
public static bool operator !=(AClass left, AClass right)
107+
{
108+
return !Equals(left, right);
109+
}
110+
}
111+
}
112+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("ValueTypeAssertions.Tests")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("ValueTypeAssertions.Tests")]
13+
[assembly: AssemblyCopyright("Copyright © 2016")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("84f91a31-17f9-406c-bad4-b3b8a71cdd0f")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{84F91A31-17F9-406C-BAD4-B3B8A71CDD0F}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>ValueTypeAssertions.Tests</RootNamespace>
11+
<AssemblyName>ValueTypeAssertions.Tests</AssemblyName>
12+
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
</PropertyGroup>
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16+
<DebugSymbols>true</DebugSymbols>
17+
<DebugType>full</DebugType>
18+
<Optimize>false</Optimize>
19+
<OutputPath>bin\Debug\</OutputPath>
20+
<DefineConstants>DEBUG;TRACE</DefineConstants>
21+
<ErrorReport>prompt</ErrorReport>
22+
<WarningLevel>4</WarningLevel>
23+
</PropertyGroup>
24+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
25+
<DebugType>pdbonly</DebugType>
26+
<Optimize>true</Optimize>
27+
<OutputPath>bin\Release\</OutputPath>
28+
<DefineConstants>TRACE</DefineConstants>
29+
<ErrorReport>prompt</ErrorReport>
30+
<WarningLevel>4</WarningLevel>
31+
</PropertyGroup>
32+
<ItemGroup>
33+
<Reference Include="FluentAssertions, Version=4.6.0.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL">
34+
<HintPath>..\packages\FluentAssertions.4.6.0\lib\net45\FluentAssertions.dll</HintPath>
35+
<Private>True</Private>
36+
</Reference>
37+
<Reference Include="FluentAssertions.Core, Version=4.6.0.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL">
38+
<HintPath>..\packages\FluentAssertions.4.6.0\lib\net45\FluentAssertions.Core.dll</HintPath>
39+
<Private>True</Private>
40+
</Reference>
41+
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
42+
<Reference Include="System" />
43+
<Reference Include="System.Core" />
44+
<Reference Include="System.Xml.Linq" />
45+
<Reference Include="System.Data.DataSetExtensions" />
46+
<Reference Include="Microsoft.CSharp" />
47+
<Reference Include="System.Data" />
48+
<Reference Include="System.Net.Http" />
49+
<Reference Include="System.Xml" />
50+
</ItemGroup>
51+
<ItemGroup>
52+
<Compile Include="HappyPaths.cs" />
53+
<Compile Include="Properties\AssemblyInfo.cs" />
54+
<Compile Include="CaseInsensitiveStringWithCaseSensitiveGetHashCode.cs" />
55+
</ItemGroup>
56+
<ItemGroup>
57+
<ProjectReference Include="..\ValueTypeAssertions\ValueTypeAssertions.csproj">
58+
<Project>{7f27d5b3-a517-4b70-9368-5a52ce3205ac}</Project>
59+
<Name>ValueTypeAssertions</Name>
60+
</ProjectReference>
61+
</ItemGroup>
62+
<ItemGroup>
63+
<None Include="packages.config" />
64+
</ItemGroup>
65+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
66+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
67+
Other similar extension points exist, see Microsoft.Common.targets.
68+
<Target Name="BeforeBuild">
69+
</Target>
70+
<Target Name="AfterBuild">
71+
</Target>
72+
-->
73+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<ProjectConfiguration>
2+
<AutoDetectNugetBuildDependencies>true</AutoDetectNugetBuildDependencies>
3+
<BuildPriority>1000</BuildPriority>
4+
<CopyReferencedAssembliesToWorkspace>false</CopyReferencedAssembliesToWorkspace>
5+
<ConsiderInconclusiveTestsAsPassing>false</ConsiderInconclusiveTestsAsPassing>
6+
<PreloadReferencedAssemblies>false</PreloadReferencedAssemblies>
7+
<AllowDynamicCodeContractChecking>true</AllowDynamicCodeContractChecking>
8+
<AllowStaticCodeContractChecking>false</AllowStaticCodeContractChecking>
9+
<AllowCodeAnalysis>false</AllowCodeAnalysis>
10+
<IgnoreThisComponentCompletely>false</IgnoreThisComponentCompletely>
11+
<RunPreBuildEvents>false</RunPreBuildEvents>
12+
<RunPostBuildEvents>false</RunPostBuildEvents>
13+
<PreviouslyBuiltSuccessfully>true</PreviouslyBuiltSuccessfully>
14+
<InstrumentAssembly>true</InstrumentAssembly>
15+
<PreventSigningOfAssembly>false</PreventSigningOfAssembly>
16+
<AnalyseExecutionTimes>true</AnalyseExecutionTimes>
17+
<DetectStackOverflow>true</DetectStackOverflow>
18+
<IncludeStaticReferencesInWorkspace>true</IncludeStaticReferencesInWorkspace>
19+
<DefaultTestTimeout>60000</DefaultTestTimeout>
20+
<UseBuildConfiguration />
21+
<UseBuildPlatform />
22+
<ProxyProcessPath />
23+
<UseCPUArchitecture>AutoDetect</UseCPUArchitecture>
24+
<MSTestThreadApartmentState>STA</MSTestThreadApartmentState>
25+
<BuildProcessArchitecture>x86</BuildProcessArchitecture>
26+
</ProjectConfiguration>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="FluentAssertions" version="4.6.0" targetFramework="net452" />
4+
</packages>

ValueTypeAssertions.sln

+11-13
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,28 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 14
44
VisualStudioVersion = 14.0.25123.0
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{BD8A492B-2C00-483D-A3F3-D958637FD422}"
7-
EndProject
86
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C3BFB2E0-8697-4BA3-9C9F-D4FE7BE9C809}"
9-
ProjectSection(SolutionItems) = preProject
10-
global.json = global.json
11-
EndProjectSection
127
EndProject
13-
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "ValueTypeAssertions", "src\ValueTypeAssertions\ValueTypeAssertions.xproj", "{E916E707-CC13-4501-A005-0D6972AC5BE5}"
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ValueTypeAssertions.Tests", "ValueTypeAssertions.Tests\ValueTypeAssertions.Tests.csproj", "{84F91A31-17F9-406C-BAD4-B3B8A71CDD0F}"
9+
EndProject
10+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ValueTypeAssertions", "ValueTypeAssertions\ValueTypeAssertions.csproj", "{7F27D5B3-A517-4B70-9368-5A52CE3205AC}"
1411
EndProject
1512
Global
1613
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1714
Debug|Any CPU = Debug|Any CPU
1815
Release|Any CPU = Release|Any CPU
1916
EndGlobalSection
2017
GlobalSection(ProjectConfigurationPlatforms) = postSolution
21-
{E916E707-CC13-4501-A005-0D6972AC5BE5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
22-
{E916E707-CC13-4501-A005-0D6972AC5BE5}.Debug|Any CPU.Build.0 = Debug|Any CPU
23-
{E916E707-CC13-4501-A005-0D6972AC5BE5}.Release|Any CPU.ActiveCfg = Release|Any CPU
24-
{E916E707-CC13-4501-A005-0D6972AC5BE5}.Release|Any CPU.Build.0 = Release|Any CPU
18+
{84F91A31-17F9-406C-BAD4-B3B8A71CDD0F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
19+
{84F91A31-17F9-406C-BAD4-B3B8A71CDD0F}.Debug|Any CPU.Build.0 = Debug|Any CPU
20+
{84F91A31-17F9-406C-BAD4-B3B8A71CDD0F}.Release|Any CPU.ActiveCfg = Release|Any CPU
21+
{84F91A31-17F9-406C-BAD4-B3B8A71CDD0F}.Release|Any CPU.Build.0 = Release|Any CPU
22+
{7F27D5B3-A517-4B70-9368-5A52CE3205AC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
23+
{7F27D5B3-A517-4B70-9368-5A52CE3205AC}.Debug|Any CPU.Build.0 = Debug|Any CPU
24+
{7F27D5B3-A517-4B70-9368-5A52CE3205AC}.Release|Any CPU.ActiveCfg = Release|Any CPU
25+
{7F27D5B3-A517-4B70-9368-5A52CE3205AC}.Release|Any CPU.Build.0 = Release|Any CPU
2526
EndGlobalSection
2627
GlobalSection(SolutionProperties) = preSolution
2728
HideSolutionNode = FALSE
2829
EndGlobalSection
29-
GlobalSection(NestedProjects) = preSolution
30-
{E916E707-CC13-4501-A005-0D6972AC5BE5} = {BD8A492B-2C00-483D-A3F3-D958637FD422}
31-
EndGlobalSection
3230
EndGlobal
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<SolutionConfiguration>
2+
<FileVersion>1</FileVersion>
3+
<InferProjectReferencesUsingAssemblyNames>false</InferProjectReferencesUsingAssemblyNames>
4+
<AllowParallelTestExecution>true</AllowParallelTestExecution>
5+
<AllowTestsToRunInParallelWithThemselves>true</AllowTestsToRunInParallelWithThemselves>
6+
<FrameworkUtilisationTypeForNUnit>UseDynamicAnalysis</FrameworkUtilisationTypeForNUnit>
7+
<FrameworkUtilisationTypeForGallio>UseStaticAnalysis</FrameworkUtilisationTypeForGallio>
8+
<FrameworkUtilisationTypeForMSpec>UseStaticAnalysis</FrameworkUtilisationTypeForMSpec>
9+
<FrameworkUtilisationTypeForMSTest>UseStaticAnalysis</FrameworkUtilisationTypeForMSTest>
10+
<FrameworkUtilisationTypeForXUnit2>UseDynamicAnalysis</FrameworkUtilisationTypeForXUnit2>
11+
<NCrunchCacheStoragePath />
12+
<MetricsExclusionList>
13+
</MetricsExclusionList>
14+
</SolutionConfiguration>

0 commit comments

Comments
 (0)