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

Level code and updated interfaces to accomodate #14

Merged
merged 6 commits into from
Aug 24, 2016
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
3 changes: 3 additions & 0 deletions Tests/Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@
<Compile Include="Management\TileChangeManagerTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TwoDimension\AreaTests.cs" />
<Compile Include="TwoDimension\CreationTests.cs" />
<Compile Include="TwoDimension\EntityTests.cs" />
<Compile Include="TwoDimension\LevelTests.cs" />
<Compile Include="TwoDimension\PositionTests.cs" />
<Compile Include="TwoDimension\TileTests.cs" />
</ItemGroup>
<ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions Tests/TwoDimension/AreaTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ public void PositionSet()
Assert.That(() => area.SetPosition(null, mockPosition.Object), Throws.ArgumentNullException);
Assert.That(() => area.SetPosition(mockLevel.Object, null), Throws.ArgumentNullException);

// TODO: Issue 13 (https://github.com/Wizcorp/TileSystem/issues/13)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the issues directly in the code :D we have to be careful to remove those kind of comments when we close the issue

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I hope that each one will be a pull request when it's fixed, also the task manager in visual studio is pretty nice for this kind of thing.


// Test Set Position Works
Assert.That(() => area.SetPosition(mockLevel.Object, mockPosition.Object), Throws.Nothing);

Expand Down
138 changes: 138 additions & 0 deletions Tests/TwoDimension/CreationTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
using Moq;

using NUnit.Framework;

using TileSystem.Interfaces.Base;
using TileSystem.Interfaces.TwoDimension;
using TileSystem.Implementation.TwoDimension;
using TileSystem.Interfaces.Creation;

namespace Tests.TwoDimension
{
[TestFixture]
[Category("TwoDimension")]
public class CreationTests
{
[Test]
public void CreateArea()
{
// Create mock factories
var mockAreaFactory = new Mock<IAreaFactory>();
var mockTileFactory = new Mock<ITileFactory>();
var mockEntityFactory = new Mock<IEntityFactory>();

// Create a mock position that will be used with the area set position
var mockPosition2D = new Mock<IPosition2D>();

// Set up area factory so it will have a mock area to invoke without throwing in the create area
mockAreaFactory.Setup(factory => factory.CreateArea(null, null)).Returns(new Mock<IArea>().Object);

// Create level with mock factories
Level level = new Level(mockAreaFactory.Object, mockTileFactory.Object, mockEntityFactory.Object);

bool createdCalled = false;

// Register added event and make sure it is called
level.AreaCreated += (sender, args) =>
{
createdCalled = true;
};

// Test Null
Assert.That(() => level.CreateArea(null, mockPosition2D.Object, null, null), Throws.ArgumentNullException);

// Test Null
Assert.That(() => level.CreateArea(level, null, null, null), Throws.ArgumentNullException);

// Assert add event was not called
Assert.IsFalse(createdCalled);

// Test Create Works
Assert.That(() => level.CreateArea(level, mockPosition2D.Object, null, null), Throws.Nothing);

// Assert add event was called
Assert.IsTrue(createdCalled);
}

[Test]
public void CreateTile()
{
// Create mock factories
var mockAreaFactory = new Mock<IAreaFactory>();
var mockTileFactory = new Mock<ITileFactory>();
var mockEntityFactory = new Mock<IEntityFactory>();

// Create a mock position that will be used with the tile set position
var mockPosition2D = new Mock<IPosition2D>();
// Create a mock area that will be used with tile set position
var mockArea = new Mock<IArea>();

// Set up tile factory so it will have a mock tile to invoke without throwing in the create tile
mockTileFactory.Setup(factory => factory.CreateTile(null, null)).Returns(new Mock<ITile>().Object);

// Create level with mock factories
Level level = new Level(mockAreaFactory.Object, mockTileFactory.Object, mockEntityFactory.Object);

bool createdCalled = false;

// Register added event and make sure it is called
level.TileCreated += (sender, args) =>
{
createdCalled = true;
};

// Test Null
Assert.That(() => level.CreateTile(null, mockPosition2D.Object, null, null), Throws.ArgumentNullException);

// Test Null
Assert.That(() => level.CreateTile(mockArea.Object, null, null, null), Throws.ArgumentNullException);

// Assert add event was not called
Assert.IsFalse(createdCalled);

// Test Create Works
Assert.That(() => level.CreateTile(mockArea.Object, mockPosition2D.Object, null, null), Throws.Nothing);

// Assert add event was called
Assert.IsTrue(createdCalled);
}

[Test]
public void CreateEntity()
{
// Create mock factories
var mockAreaFactory = new Mock<IAreaFactory>();
var mockTileFactory = new Mock<ITileFactory>();
var mockEntityFactory = new Mock<IEntityFactory>();

// Create a mock tile that will be used with entity set parent
var mockTile = new Mock<ITile>();

// Set up entity factory so it will have a mock entity to invoke without throwing in the create entity
mockEntityFactory.Setup(factory => factory.CreateEntity(null, null)).Returns(new Mock<IEntity>().Object);

// Create level with mock factories
Level level = new Level(mockAreaFactory.Object, mockTileFactory.Object, mockEntityFactory.Object);

bool createdCalled = false;

// Register added event and make sure it is called
level.EntityCreated += (sender, args) =>
{
createdCalled = true;
};

// Test Null
Assert.That(() => level.CreateEntity(null, null, null), Throws.ArgumentNullException);

// Assert add event was not called
Assert.IsFalse(createdCalled);

// Test Create Works
Assert.That(() => level.CreateEntity(mockTile.Object, null, null), Throws.Nothing);

// Assert add event was called
Assert.IsTrue(createdCalled);
}
}
}
8 changes: 4 additions & 4 deletions Tests/TwoDimension/EntityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void EntityDestroyTileRemove()
var mockTile = new Mock<ITile>();

// Set Tile Parent
entity.SetParent(mockTile.Object);
entity.SetTile(mockTile.Object);

// Destroy
entity.Destroy();
Expand All @@ -70,15 +70,15 @@ public void EntityDestroyTileRemove()
}

[Test]
public void SetParent()
public void SetTile()
{
Entity entity = new Entity();
var mockTile = new Mock<ITile>();

// Test Null
Assert.That(() => entity.SetParent(null), Throws.ArgumentNullException);
Assert.That(() => entity.SetTile(null), Throws.ArgumentNullException);
// Test Set Parent Works
Assert.That(() => entity.SetParent(mockTile.Object), Throws.Nothing);
Assert.That(() => entity.SetTile(mockTile.Object), Throws.Nothing);

Assert.AreSame(entity.Tile, mockTile.Object);
}
Expand Down
126 changes: 126 additions & 0 deletions Tests/TwoDimension/LevelTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
using Moq;

using NUnit.Framework;

using TileSystem.Interfaces.Base;
using TileSystem.Interfaces.TwoDimension;
using TileSystem.Implementation.TwoDimension;
using TileSystem.Interfaces.Creation;

namespace Tests.TwoDimension
{
[TestFixture]
[Category("TwoDimension")]
public class LevelTests
{
[Test]
public void LevelFactoryConstructor()
{
// Create mock factories
var mockAreaFactory = new Mock<IAreaFactory>();
var mockTileFactory = new Mock<ITileFactory>();
var mockEntityFactory = new Mock<IEntityFactory>();

// Test Area Null
Assert.That(() => new Level(null, mockTileFactory.Object, mockEntityFactory.Object), Throws.ArgumentNullException);

// Test Tile Null
Assert.That(() => new Level(mockAreaFactory.Object, null, mockEntityFactory.Object), Throws.ArgumentNullException);

// Test Entity Null
Assert.That(() => new Level(mockAreaFactory.Object, mockTileFactory.Object, null), Throws.ArgumentNullException);

// Test Create Works
Assert.That(() => new Level(mockAreaFactory.Object, mockTileFactory.Object, mockEntityFactory.Object), Throws.Nothing);
}

[Test]
public void AreaAdd()
{
Level level = new Level();
var mockArea = new Mock<IArea>();

bool addCalled = false;

// Register added event and make sure it is called
level.AreaAdded += (sender, args) =>
{
addCalled = true;
};

// Test Null
Assert.That(() => level.Add(null), Throws.ArgumentNullException);

// Assert add event was not called
Assert.IsFalse(addCalled);

// Test Add Works
Assert.That(() => level.Add(mockArea.Object), Throws.Nothing);

// Assert add event was called
Assert.IsTrue(addCalled);

// Reset before next test
addCalled = false;

// Test duplicate fails
Assert.That(() => level.Add(mockArea.Object), Throws.ArgumentException);

// Assert add event was not called
Assert.IsFalse(addCalled);
}

[Test]
public void AreaRemove()
{
Level level = new Level();
var mockArea = new Mock<IArea>();

bool removeCalled = false;

// Register removed event and make sure it is called
level.AreaRemoved += (sender, args) =>
{
removeCalled = true;
};

// Add Area
level.Add(mockArea.Object);

// Test Null
Assert.That(() => level.Remove(null), Throws.ArgumentNullException);

// Assert remove event was not called
Assert.IsFalse(removeCalled);

// Test Remove (true removing the object)
Assert.That(level.Remove(mockArea.Object), Is.True);

// Assert remove event was called
Assert.IsTrue(removeCalled);

// Reset before next test
removeCalled = false;

// Test Remove (false not removing the object)
Assert.That(level.Remove(mockArea.Object), Is.False);

// Assert remove event was not called
Assert.IsFalse(removeCalled);
}

[Test]
public void PositionGet()
{
// TODO: Issue 15 (https://github.com/Wizcorp/TileSystem/issues/15)
Assert.Fail();
}

[Test]
public void PositionGetNeighbours()
{
// TODO: Issue 15 (https://github.com/Wizcorp/TileSystem/issues/15)
Assert.Fail();
}
}
}
34 changes: 34 additions & 0 deletions Tests/TwoDimension/PositionTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using NUnit.Framework;

using TileSystem.Interfaces.TwoDimension;
using TileSystem.Implementation.TwoDimension;

namespace Tests.TwoDimension
{
[TestFixture]
[Category("TwoDimension")]
public class PositionTests
{
[Test]
public void PositionConstructor()
{
int x = 0;
int y = 0;

// Test Area Null
Assert.That(() => new Position2D(x, y), Throws.Nothing);

// Create position and check x,y
IPosition2D pos = new Position2D(x, y);
Assert.AreEqual(x, pos.X);
Assert.AreEqual(y, pos.Y);
}

[Test]
public void CompareTo()
{
// TODO: Issue 11 (https://github.com/Wizcorp/TileSystem/issues/11)
Assert.Fail();
}
}
}
Loading