diff --git a/Sharpasonne.Tests/Rules/SpaceIsEmptyRuleTests.cs b/Sharpasonne.Tests/Rules/SpaceIsEmptyRuleTests.cs new file mode 100644 index 0000000..64d21d0 --- /dev/null +++ b/Sharpasonne.Tests/Rules/SpaceIsEmptyRuleTests.cs @@ -0,0 +1,26 @@ +using Sharpasonne.GameActions; +using Sharpasonne.Rules; +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using Xunit; + +namespace Sharpasonne.Tests.Rules +{ + public class SpaceIsEmptyRuleTests + { + [Fact] + public void When_TileIsEmpty_Then_True() + { + Assert.True(new SpaceIsEmptyRule().Verify(new Engine(), new PlaceTileGameAction())); + } + + [Fact] + public void When_TileIsEmpty_Then_False() + { + var engine = new Engine(); + + Assert.True(new SpaceIsEmptyRule().Verify(engine, new PlaceTileGameAction())); + } + } +} diff --git a/Sharpasonne/Engine.cs b/Sharpasonne/Engine.cs index cd93b7c..ee8f8e5 100644 --- a/Sharpasonne/Engine.cs +++ b/Sharpasonne/Engine.cs @@ -2,6 +2,7 @@ using System.Collections; using System.Collections.Immutable; using System.Linq; +using System.Runtime.InteropServices; using JetBrains.Annotations; using Sharpasonne.Models; @@ -12,17 +13,22 @@ public class Engine { public Board Board { get; } = new Board(); + public Engine() + { + } + public Engine( [NotNull] IImmutableQueue gameActions, [NotNull] IImmutableDictionary> rules) { var nonGameActions = rules.Keys - .Where(k => !k.GetInterfaces().Any(i => i == typeof(IGameAction))) + .Where(type => !typeof(IGameAction).IsAssignableFrom(type)) .ToList(); + if (nonGameActions.Any()) { var typeNames = string.Join(", ", nonGameActions.Select(t => t.FullName)); - var message = $"'{typeNames}' don't implement {nameof(IGameAction)}"; + var message = $"'{typeNames}' does not implement {nameof(IGameAction)}"; throw new ArgumentOutOfRangeException(message); } } @@ -34,8 +40,4 @@ public Engine( }*/ } - - public interface IGameAction - { - } } diff --git a/Sharpasonne/GameActions/PlaceTileGameAction.cs b/Sharpasonne/GameActions/PlaceTileGameAction.cs new file mode 100644 index 0000000..1394f94 --- /dev/null +++ b/Sharpasonne/GameActions/PlaceTileGameAction.cs @@ -0,0 +1,9 @@ +using Sharpasonne; +using Sharpasonne.Models; + +namespace Sharpasonne.GameActions +{ + public class PlaceTileGameAction : IGameAction + { + } +} diff --git a/Sharpasonne/IGameAction.cs b/Sharpasonne/IGameAction.cs new file mode 100644 index 0000000..7a9c322 --- /dev/null +++ b/Sharpasonne/IGameAction.cs @@ -0,0 +1,6 @@ +namespace Sharpasonne +{ + public interface IGameAction + { + } +} \ No newline at end of file diff --git a/Sharpasonne/Rules/SpaceIsEmptyRule.cs b/Sharpasonne/Rules/SpaceIsEmptyRule.cs new file mode 100644 index 0000000..e1835a1 --- /dev/null +++ b/Sharpasonne/Rules/SpaceIsEmptyRule.cs @@ -0,0 +1,14 @@ +using Sharpasonne; +using Sharpasonne.Models; + +namespace Sharpasonne.Rules +{ + public class SpaceIsEmptyRule : IRule + { + public bool Verify(Engine engine, T gameAction) + where T : IGameAction + { + return true; + } + } +}