Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial commit #3

Merged
merged 33 commits into from
Nov 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions nuspec/nuget/BBT.StructureTools.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
<copyright>Copyright © BBT Software AG</copyright>
<tags>copy compare convert</tags>
<releaseNotes>https://github.com/bbtsoftware/BBT.StructureTools/releases/tag/1.0.0</releaseNotes>
<dependencies>
<dependency id="BBT.Maybe" version="2.0.0" />
<dependency id="BBT.StrategyPattern" version="1.0.0" />
</dependencies>
</metadata>
<files>
<file src="netstandard2.0\BBT.StructureTools.dll" target="lib\netstandard2.0" />
Expand Down
6 changes: 3 additions & 3 deletions setup.cake
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ BuildParameters.SetParameters(
appVeyorAccountName: "BBTSoftwareAG",
shouldPublishMyGet: false,
shouldRunCodecov: true,
shouldDeployGraphDocumentation: false);
shouldDeployGraphDocumentation: false,
shouldRunDupFinder: false);

BuildParameters.PrintParameters(Context);

ToolSettings.SetToolSettings(
context: Context,
dupFinderExcludePattern: new string[] { BuildParameters.RootDirectoryPath + "/src/BBT.StructureTools.Tests/*.cs" },
testCoverageFilter: "+[*]* -[xunit.*]* -[*.Tests]* -[Shouldly]*",
testCoverageFilter: "+[*]* -[xunit.*]* -[*.Tests]* -[FluentAssertions]* -[BBT.MaybePattern]* -[BBT.StrategyPattern]*",
testCoverageExcludeByAttribute: "*.ExcludeFromCodeCoverage*",
testCoverageExcludeByFile: "*/*Designer.cs;*/*.g.cs;*/*.g.i.cs");

Expand Down
4 changes: 4 additions & 0 deletions src/BBT.StructureTools.Tests.ruleset
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,9 @@
<Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers">
<Rule Id="SA1118" Action="None" />
<Rule Id="SA1652" Action="None" />
<Rule Id="SA1600" Action="None" />
<Rule Id="SA1124" Action="None" />
<Rule Id="SA1201" Action="None" />
<Rule Id="SA0001" Action="None" />
</Rules>
</RuleSet>
12 changes: 12 additions & 0 deletions src/BBT.StructureTools.Tests/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Runtime.InteropServices;
using Xunit;

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("e03aad10-b9e8-401c-9a10-d74d814bf0a6")]

[assembly: CollectionBehavior(CollectionBehavior.CollectionPerAssembly)]
14 changes: 12 additions & 2 deletions src/BBT.StructureTools.Tests/BBT.StructureTools.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
Expand All @@ -21,11 +21,21 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
<PackageReference Include="Shouldly" Version="3.0.2" />
<PackageReference Include="Moq" Version="4.13.1" />
<PackageReference Include="Ninject" Version="3.3.4" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="FluentAssertions" Version="5.9.0">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.4">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
namespace BBT.StructureTools.Tests.Compare
{
using System.Collections.Generic;
using BBT.StructureTools.Compare;
using BBT.StructureTools.Compare.Exclusions;
using BBT.StructureTools.Compare.Helper;
using BBT.StructureTools.Tests.Compare.Intention;
using BBT.StructureTools.Tests.TestTools;
using FluentAssertions;
using Ninject;
using Xunit;

/// <summary>
/// Test for Comparer infrastructure with object attributes.
/// </summary>
public class ComparerWithObjectAttributeTests
{
#region Members, Setup
marco-bertschi marked this conversation as resolved.
Show resolved Hide resolved
private readonly IComparer<TestClass, ITestCompareIntention> testcandidate;

public ComparerWithObjectAttributeTests()
{
var kernel = TestIoContainer.Initialize();

kernel.Bind<ICompareRegistrations<TestClass, ITestCompareIntention>>().To<TestClassCompareRegistrations>();

this.testcandidate = kernel.Get<IComparer<TestClass, ITestCompareIntention>>();
}

#endregion

[Fact]
public void Equals_WhenSameInstance_MustReturnTrue()
{
// Arrange
var testClass = new TestClass
{
// Explicit instance init on purpose
TestAttribute1 = new TestAttribute(),
};

// Act
var result = this.testcandidate.Equals(testClass, testClass);

// Assert
result.Should().BeTrue();
}

[Fact]
public void Equals_WhenSameInstanceAndObjectAttributeNull_MustReturnTrue()
{
// Arrange
var testClass = new TestClass
{
// Explicit null init on purpose
TestAttribute1 = null,
};

// Act
var result = this.testcandidate.Equals(testClass, testClass);

// Assert
result.Should().BeTrue();
}

[Fact]
public void Equals_WhenAttributeObjectsEqual_MustReturnTrue()
{
// Arrange
var testAttribute = new TestAttribute();
var testClassA = new TestClass { TestAttribute1 = testAttribute };
var testClassB = new TestClass { TestAttribute1 = testAttribute };

// Act
var result = this.testcandidate.Equals(testClassA, testClassB);

// Assert
result.Should().BeTrue();
}

[Fact]
public void Equals_WhenAttributeObjectsNotEqual_MustReturnFalse()
{
// Arrange
var testAttribute = new TestAttribute();
var testAttribute2 = new TestAttribute();
var testClassA = new TestClass { TestAttribute1 = testAttribute };
var testClassB = new TestClass { TestAttribute1 = testAttribute2 };

// Act
var result = this.testcandidate.Equals(testClassA, testClassB);

// Assert
result.Should().BeFalse();
}

[Fact]
public void Equals_WhenAttributeObjectsNotEqualButNotRegistered_MustReturnTrue()
{
// Arrange
var testAttribute = new TestAttribute();
var testClassA = new TestClass { TestAttribute2 = testAttribute };
var testClassB = new TestClass { TestAttribute2 = testAttribute };

// Act
var result = this.testcandidate.Equals(testClassA, testClassB);

// Assert
result.Should().BeTrue();
}

[Fact]
public void Equals_WhenAttributeObjectsNotEqualButExcluded_MustReturnTrue()
{
// Arrange
var testAttribute = new TestAttribute();
var testAttribute2 = new TestAttribute();
var testClassA = new TestClass { TestAttribute1 = testAttribute };
var testClassB = new TestClass { TestAttribute1 = testAttribute2 };
var comparerExclusions = new List<IComparerExclusion>
{
new PropertyComparerExclusion<TestClass>(
x => x.TestAttribute1),
};

// Act
var result = this.testcandidate.Equals(testClassA, testClassB, System.Array.Empty<IBaseAdditionalProcessing>(), comparerExclusions);

// Assert
result.Should().BeTrue();
}

#region private test classes and test class helpers
private class TestClass
{
public TestAttribute TestAttribute1 { get; set; }

public TestAttribute TestAttribute2 { get; set; }
}

private class TestAttribute
{
}

private class TestClassCompareRegistrations : ICompareRegistrations<TestClass, ITestCompareIntention>
{
public void DoRegistrations(IEqualityComparerHelperRegistration<TestClass> registrations)
{
registrations.Should().NotBeNull();

registrations.RegisterAttribute(x => x.TestAttribute1);
}
}
#endregion
}
}
Loading