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

Add tests for Castle Windsor #31

Closed
wants to merge 2 commits into from
Closed
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
3 changes: 0 additions & 3 deletions src/BBT.StructureTools.Tests/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
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
Expand All @@ -8,5 +7,3 @@

// 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)]
10 changes: 6 additions & 4 deletions src/BBT.StructureTools.Tests/BBT.StructureTools.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,23 @@
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
</PropertyGroup>
<ItemGroup>
<None Remove="Compare\ve-B655.tmp" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Castle.Windsor" Version="5.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
<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="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.15.1" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,39 @@
using BBT.StructureTools.Compare.Exclusions;
using BBT.StructureTools.Compare.Helper;
using BBT.StructureTools.Tests.Compare.Intention;
using BBT.StructureTools.Tests.TestTools;
using BBT.StructureTools.Tests.TestTools.IoC;
using FluentAssertions;
using Ninject;
using Xunit;
using NUnit.Framework;

/// <summary>
/// Test for Comparer infrastructure with object attributes.
/// </summary>
[TestFixture]
[TestFixtureSource(typeof(IocTestFixtureSource), "IocContainers")]
public class ComparerWithObjectAttributeTests
{
#region Members, Setup
private readonly IComparer<TestClass, ITestCompareIntention> testcandidate;

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

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

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

#endregion

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

// Act
Expand All @@ -46,7 +47,7 @@ public void Equals_WhenSameInstance_MustReturnTrue()
result.Should().BeTrue();
}

[Fact]
[Test]
public void Equals_WhenSameInstanceAndObjectAttributeNull_MustReturnTrue()
{
// Arrange
Expand All @@ -63,11 +64,11 @@ public void Equals_WhenSameInstanceAndObjectAttributeNull_MustReturnTrue()
result.Should().BeTrue();
}

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

Expand All @@ -78,12 +79,12 @@ public void Equals_WhenAttributeObjectsEqual_MustReturnTrue()
result.Should().BeTrue();
}

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

Expand All @@ -94,11 +95,11 @@ public void Equals_WhenAttributeObjectsNotEqual_MustReturnFalse()
result.Should().BeFalse();
}

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

Expand All @@ -109,12 +110,12 @@ public void Equals_WhenAttributeObjectsNotEqualButNotRegistered_MustReturnTrue()
result.Should().BeTrue();
}

[Fact]
[Test]
public void Equals_WhenAttributeObjectsNotEqualButExcluded_MustReturnTrue()
{
// Arrange
var testAttribute = new TestAttribute();
var testAttribute2 = new TestAttribute();
var testAttribute = new TestObjProperty();
var testAttribute2 = new TestObjProperty();
var testClassA = new TestClass { TestAttribute1 = testAttribute };
var testClassB = new TestClass { TestAttribute1 = testAttribute2 };
var comparerExclusions = new List<IComparerExclusion>
Expand All @@ -133,12 +134,12 @@ public void Equals_WhenAttributeObjectsNotEqualButExcluded_MustReturnTrue()
#region private test classes and test class helpers
private class TestClass
{
public TestAttribute TestAttribute1 { get; set; }
public TestObjProperty TestAttribute1 { get; set; }

public TestAttribute TestAttribute2 { get; set; }
public TestObjProperty TestAttribute2 { get; set; }
}

private class TestAttribute
private class TestObjProperty
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,43 @@
using BBT.StructureTools.Compare.Exclusions;
using BBT.StructureTools.Compare.Helper;
using BBT.StructureTools.Tests.Compare.Intention;
using BBT.StructureTools.Tests.TestTools;
using BBT.StructureTools.Tests.TestTools.IoC;
using FluentAssertions;
using Ninject;
using Xunit;
using NUnit.Framework;

[TestFixture]
[TestFixtureSource(typeof(IocTestFixtureSource), "IocContainers")]
public class ComparerWithObjectAttributeWithDistinguishedComparerIntTests
{
#region Members, Setup

private static IComparer<TestAttribute, ITestCompareIntention> distinguishedComparer;
private static IComparer<TestWithProperties, ITestCompareIntention> distinguishedComparer;
private readonly IComparer<TestClass, ITestCompareIntention> testcandidate;

public ComparerWithObjectAttributeWithDistinguishedComparerIntTests()
public ComparerWithObjectAttributeWithDistinguishedComparerIntTests(IIocContainer iocContainer)
{
var kernel = TestIoContainer.Initialize();
iocContainer.Initialize();

kernel.Bind<ICompareRegistrations<TestClass, ITestCompareIntention>>().To<TestClassCompareRegistrations>();
kernel.Bind<ICompareRegistrations<TestAttribute, ITestCompareIntention>>().To<TestAttributeCompareRegistrations>();
iocContainer.RegisterSingleton<ICompareRegistrations<TestClass, ITestCompareIntention>, TestClassCompareRegistrations>();
iocContainer.RegisterSingleton<ICompareRegistrations<TestWithProperties, ITestCompareIntention>, TestAttributeCompareRegistrations>();

distinguishedComparer = kernel.Get<IComparer<TestAttribute, ITestCompareIntention>>();
this.testcandidate = kernel.Get<IComparer<TestClass, ITestCompareIntention>>();
distinguishedComparer = iocContainer.GetInstance<IComparer<TestWithProperties, ITestCompareIntention>>();
this.testcandidate = iocContainer.GetInstance<IComparer<TestClass, ITestCompareIntention>>();
}

#endregion

/// <summary>
/// Tests IComparer.Equals.
/// </summary>
[Fact]
[Test]
public void Equals_WhenSameInstance_MustReturnTrue()
{
// Arrange
var testClass = new TestClass
{
// Explicit instance init on purpose
TestAttribute = new TestAttribute(),
TestAttribute = new TestWithProperties(),
};

// Act
Expand All @@ -54,7 +55,7 @@ public void Equals_WhenSameInstance_MustReturnTrue()
/// <summary>
/// Tests IComparer.Equals.
/// </summary>
[Fact]
[Test]
public void Equals_WhenSameInstanceAndObjectAttributeNull_MustReturnTrue()
{
// Arrange
Expand All @@ -74,11 +75,11 @@ public void Equals_WhenSameInstanceAndObjectAttributeNull_MustReturnTrue()
/// <summary>
/// Tests IComparer.Equals.
/// </summary>
[Fact]
[Test]
public void Equals_WhenAttributeObjectsEqual_MustReturnTrue()
{
// Arrange
var testAttribute = new TestAttribute();
var testAttribute = new TestWithProperties();
var testClassA = new TestClass { TestAttribute = testAttribute };
var testClassB = new TestClass { TestAttribute = testAttribute };

Expand All @@ -92,12 +93,12 @@ public void Equals_WhenAttributeObjectsEqual_MustReturnTrue()
/// <summary>
/// Tests IComparer.Equals.
/// </summary>
[Fact]
[Test]
public void Equals_WhenBaseModelAttributeObjectsNotEqualButHaveSameValue_MustReturnTrue()
{
// Arrange
var testAttribute = new TestAttribute();
var testAttribute2 = new TestAttribute();
var testAttribute = new TestWithProperties();
var testAttribute2 = new TestWithProperties();
var testClassA = new TestClass { TestAttribute = testAttribute };
var testClassB = new TestClass { TestAttribute = testAttribute2 };

Expand All @@ -111,12 +112,12 @@ public void Equals_WhenBaseModelAttributeObjectsNotEqualButHaveSameValue_MustRet
/// <summary>
/// Tests IComparer.Equals.
/// </summary>
[Fact]
[Test]
public void Equals_WhenBaseModelAttributeObjectsNotEqualAndHaveDifferentValue_MustReturnFalse()
{
// Arrange
var testAttribute = new TestAttribute { TestValue1 = 55 };
var testAttribute2 = new TestAttribute();
var testAttribute = new TestWithProperties { TestValue1 = 55 };
var testAttribute2 = new TestWithProperties();
var testClassA = new TestClass { TestAttribute = testAttribute };
var testClassB = new TestClass { TestAttribute = testAttribute2 };

Expand All @@ -130,12 +131,12 @@ public void Equals_WhenBaseModelAttributeObjectsNotEqualAndHaveDifferentValue_Mu
/// <summary>
/// Tests IComparer.Equals.
/// </summary>
[Fact]
[Test]
public void Equals_WhenAttributeObjectsNotEqualButNotRegistered_MustReturnTrue()
{
// Arrange
var testAttribute = new TestAttribute() { TestValue2 = 2 };
var testAttribute2 = new TestAttribute() { TestValue2 = 1 };
var testAttribute = new TestWithProperties() { TestValue2 = 2 };
var testAttribute2 = new TestWithProperties() { TestValue2 = 1 };
var testClassA = new TestClass { TestAttribute = testAttribute };
var testClassB = new TestClass { TestAttribute = testAttribute2 };

Expand All @@ -149,12 +150,12 @@ public void Equals_WhenAttributeObjectsNotEqualButNotRegistered_MustReturnTrue()
/// <summary>
/// Tests IComparer.Equals.
/// </summary>
[Fact]
[Test]
public void Equals_WhenAttributeObjectsNotEqualButExcluded_MustReturnTrue()
{
// Arrange
var testAttribute = new TestAttribute() { TestValue1 = 2 };
var testAttribute2 = new TestAttribute() { TestValue1 = 1 };
var testAttribute = new TestWithProperties() { TestValue1 = 2 };
var testAttribute2 = new TestWithProperties() { TestValue1 = 1 };
var testClassA = new TestClass { TestAttribute = testAttribute };
var testClassB = new TestClass { TestAttribute = testAttribute2 };
var comparerExclusions = new List<IComparerExclusion>
Expand All @@ -174,19 +175,19 @@ public void Equals_WhenAttributeObjectsNotEqualButExcluded_MustReturnTrue()

private class TestClass
{
public TestAttribute TestAttribute { get; set; }
public TestWithProperties TestAttribute { get; set; }
}

private class TestAttribute
private class TestWithProperties
{
public int TestValue1 { get; set; }

public int TestValue2 { get; set; }
}

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

Expand Down
Loading