Skip to content
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<IsPackable>false</IsPackable>
<AssemblyTitle>BBT.StrategyPattern.Tests</AssemblyTitle>
<Company>BBT Software AG</Company>
Expand All @@ -25,7 +25,7 @@
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
<PackageReference Include="FluentAssertions" Version="8.8.0" />
<PackageReference Include="Shouldly" Version="4.3.0" />
<PackageReference Include="Ninject" Version="3.3.6" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.2">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright © BBT Software AG. All rights reserved.

using BBT.StrategyPattern.Tests.Data;
using Shouldly;

namespace BBT.StrategyPattern.Tests.ExampleStrategyImpl
{
using BBT.StrategyPattern.Tests.Data;
using FluentAssertions;

public class AdditionStrategy : IOperatorStrategy
{
public double DoCalculate(CalculationInput calc)
Expand All @@ -14,7 +14,7 @@ public double DoCalculate(CalculationInput calc)

public bool IsResponsible(Operator criterion)
{
criterion.Should().NotBeNull();
criterion.ShouldNotBeNull();

return criterion.Operation == OperatorEnum.Addition;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright © BBT Software AG. All rights reserved.

using BBT.StrategyPattern.Tests.Data;

namespace BBT.StrategyPattern.Tests.ExampleStrategyImpl
{
using BBT.StrategyPattern.Tests.Data;

public interface IOperatorStrategy : IGenericStrategy<Operator>
{
double DoCalculate(CalculationInput calc);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright © BBT Software AG. All rights reserved.

using BBT.StrategyPattern.Tests.Data;
using Shouldly;

namespace BBT.StrategyPattern.Tests.ExampleStrategyImpl
{
using BBT.StrategyPattern.Tests.Data;
using FluentAssertions;

public class SubstractionStrategy : IOperatorStrategy
{
public double DoCalculate(CalculationInput calc)
Expand All @@ -14,7 +14,7 @@ public double DoCalculate(CalculationInput calc)

public bool IsResponsible(Operator criterion)
{
criterion.Should().NotBeNull();
criterion.ShouldNotBeNull();

return criterion.Operation == OperatorEnum.Subtraktion;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright © BBT Software AG. All rights reserved.

using System;
using System.Collections.Generic;
using Ninject;

namespace BBT.StrategyPattern.Tests.WithIoc
{
using System;
using System.Collections.Generic;
using Ninject;

public class NinjectStrategyLocator<T> : IStrategyLocator<T>
{
public NinjectStrategyLocator(IKernel kernel)
Expand Down
31 changes: 14 additions & 17 deletions src/BBT.StrategyPattern.Tests/WithIocTest.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// Copyright © BBT Software AG. All rights reserved.

using BBT.StrategyPattern.Tests.Data;
using BBT.StrategyPattern.Tests.ExampleStrategyImpl;
using BBT.StrategyPattern.Tests.WithIoc;
using Ninject;
using Shouldly;
using System;
using Xunit;

namespace BBT.StrategyPattern.Tests
{
using System;
using BBT.StrategyPattern.Tests.Data;
using BBT.StrategyPattern.Tests.ExampleStrategyImpl;
using BBT.StrategyPattern.Tests.WithIoc;
using FluentAssertions;
using Ninject;
using Xunit;

public class WithIocTest
{
[Fact]
Expand All @@ -34,10 +34,10 @@ public void WorksWithIocNinject()
IOperatorStrategy strategy;

strategy = kernel.Get<IGenericStrategyProvider<IOperatorStrategy, Operator>>().GetStrategy(op1);
strategy.DoCalculate(calc1).Should().Be(8);
strategy.DoCalculate(calc1).ShouldBe(8);

strategy = kernel.Get<IGenericStrategyProvider<IOperatorStrategy, Operator>>().GetStrategy(op2);
strategy.DoCalculate(calc1).Should().Be(2);
strategy.DoCalculate(calc1).ShouldBe(2);
}

[Fact]
Expand All @@ -58,10 +58,8 @@ public void MissingStrategies_ThrowsExpectedException()
var act = () => kernel.Get<IGenericStrategyProvider<IOperatorStrategy, Operator>>().GetStrategy(op2);

// Assert
act.Should()
.Throw<InvalidOperationException>()
.WithMessage("No strategies of type IOperatorStrategy are available from the locator.");

var ex = Should.Throw<InvalidOperationException>(act);
ex.Message.ShouldBe("No strategies of type IOperatorStrategy are available from the locator.");
}

[Fact]
Expand All @@ -85,9 +83,8 @@ public void MissingStrategyForCriteria_ThrowsExpectedException()
var act = () => kernel.Get<IGenericStrategyProvider<IOperatorStrategy, Operator>>().GetStrategy(op2);

// Assert
act.Should()
.Throw<InvalidOperationException>()
.WithMessage("No strategy of type IOperatorStrategy available from the locator being responsible for criterion of type Operator.");
var ex = Should.Throw<InvalidOperationException>(act);
ex.Message.ShouldBe("No strategy of type IOperatorStrategy available from the locator being responsible for criterion of type Operator.");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright © BBT Software AG. All rights reserved.

using System.Collections.Generic;
using BBT.StrategyPattern.Tests.ExampleStrategyImpl;

namespace BBT.StrategyPattern.Tests.WithoutIoc
{
using System.Collections.Generic;
using BBT.StrategyPattern.Tests.ExampleStrategyImpl;

public class MemoryOperatorStrategyLocator : IStrategyLocator<IOperatorStrategy>
{
public IEnumerable<IOperatorStrategy> GetAllStrategies()
Expand Down
16 changes: 8 additions & 8 deletions src/BBT.StrategyPattern.Tests/WithoutIocTest.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Copyright © BBT Software AG. All rights reserved.

using BBT.StrategyPattern.Tests.Data;
using BBT.StrategyPattern.Tests.ExampleStrategyImpl;
using BBT.StrategyPattern.Tests.WithoutIoc;
using Shouldly;
using Xunit;

namespace BBT.StrategyPattern.Tests
{
using BBT.StrategyPattern.Tests.Data;
using BBT.StrategyPattern.Tests.ExampleStrategyImpl;
using BBT.StrategyPattern.Tests.WithoutIoc;
using FluentAssertions;
using Xunit;

public class WithoutIocTest
{
[Fact]
Expand All @@ -23,10 +23,10 @@ public void GenericStrategyWorksInMemory()
IOperatorStrategy strategy;

strategy = strategyProvider.GetStrategy(op1);
strategy.DoCalculate(calc1).Should().Be(8);
strategy.DoCalculate(calc1).ShouldBe(8);

strategy = strategyProvider.GetStrategy(op2);
strategy.DoCalculate(calc1).Should().Be(2);
strategy.DoCalculate(calc1).ShouldBe(2);
}
}
}
31 changes: 0 additions & 31 deletions src/BBT.StrategyPattern.sln

This file was deleted.

4 changes: 4 additions & 0 deletions src/BBT.StrategyPattern.slnx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<Solution>
<Project Path="BBT.StrategyPattern.Tests/BBT.StrategyPattern.Tests.csproj" />
<Project Path="BBT.StrategyPattern/BBT.StrategyPattern.csproj" />
</Solution>
2 changes: 1 addition & 1 deletion src/BBT.StrategyPattern/BBT.StrategyPattern.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net6.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net10.0</TargetFrameworks>
<AssemblyTitle>BBT.StrategyPattern</AssemblyTitle>
<CodeAnalysisRuleSet>..\BBT.StrategyPattern.ruleset</CodeAnalysisRuleSet>
<DocumentationFile>bin\$(Configuration)\BBT.StrategyPattern.xml</DocumentationFile>
Expand Down
6 changes: 3 additions & 3 deletions src/BBT.StrategyPattern/GenericStrategyProvider.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright © BBT Software AG. All rights reserved.

using System;
using System.Linq;

namespace BBT.StrategyPattern
{
using System;
using System.Linq;

/// <summary>
/// Generic implementation of <see cref="IGenericStrategyProvider{TStrategy,TCriterion}"/>.
/// </summary>
Expand All @@ -31,12 +31,12 @@
var strategies = this.strategyLocator.GetAllStrategies();

// If no strategies for TStrategy can be found.
if (!strategies.Any())

Check warning on line 34 in src/BBT.StrategyPattern/GenericStrategyProvider.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Possible multiple enumerations of 'IEnumerable' collection. Consider using an implementation that avoids multiple enumerations. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1851)

Check warning on line 34 in src/BBT.StrategyPattern/GenericStrategyProvider.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Possible multiple enumerations of 'IEnumerable' collection. Consider using an implementation that avoids multiple enumerations. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1851)
{
throw new InvalidOperationException($"No strategies of type {typeof(TStrategy).Name} are available from the locator.");
}

var strategy = strategies.SingleOrDefault(x => x.IsResponsible(criterion));

Check warning on line 39 in src/BBT.StrategyPattern/GenericStrategyProvider.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Possible multiple enumerations of 'IEnumerable' collection. Consider using an implementation that avoids multiple enumerations. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1851)

Check warning on line 39 in src/BBT.StrategyPattern/GenericStrategyProvider.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Possible multiple enumerations of 'IEnumerable' collection. Consider using an implementation that avoids multiple enumerations. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1851)

// If no strategy responsible for TCriterion can be found.
if (strategy == null)
Expand Down
4 changes: 2 additions & 2 deletions src/BBT.StrategyPattern/IStrategyLocator.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright © BBT Software AG. All rights reserved.

using System.Collections.Generic;

namespace BBT.StrategyPattern
{
using System.Collections.Generic;

/// <summary>
/// Defines how strategies are located.
/// </summary>
Expand Down
Loading