-
Notifications
You must be signed in to change notification settings - Fork 5
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
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
dd5a8cd
level file
nullorvoid 7556495
Merge branch 'develop' into feature/level
nullorvoid f0579fc
level comments and set up, as well as some fixes
nullorvoid 765a07c
added level and tests, updated some interfaces to allow for this change
nullorvoid 026c3ac
removed unused references
nullorvoid a9fb55f
updated based on feedback
nullorvoid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.