public void CheckThatHashCodesForDifferentDoubleEdgedPipeAreDifferent() { var pipe1 = new DoubleEdgedPipe(EdgeType.LEFT, EdgeType.UP); var pipe2 = new DoubleEdgedPipe(EdgeType.UP, EdgeType.DOWN); Assert.AreNotEqual(pipe1.GetHashCode(), pipe2.GetHashCode()); }
public void CheckThatHashCodesForSameDoubleEdgedPipeAreEqual() { var pipe1 = new DoubleEdgedPipe(EdgeType.DOWN, EdgeType.UP); var pipe2 = new DoubleEdgedPipe(EdgeType.UP, EdgeType.DOWN); Assert.AreEqual(pipe1.GetHashCode(), pipe2.GetHashCode()); }
public void CheckThatDoubleEdgedPipeCannotBeDeletedFromInexistentBlock() { var position = new Coordinate(5, 4); var pipe = new DoubleEdgedPipe(EdgeType.DOWN, EdgeType.UP); mockBlock.Setup(x => x.HasShipComponent()).Returns(false); Assert.IsFalse(blueprintBuilder.DeleteDoubleEdgedPipe(position, pipe)); }
public void CheckThatInexistentDoubleEdgedPipeAndWithNoConnectingPipesThatCanComposeItCannotBeDeleted() { var position = new Coordinate(5, 4); var pipe = new DoubleEdgedPipe(EdgeType.UP, EdgeType.DOWN); blocks.Set(position, mockBlock.Object); Assert.IsFalse(blueprintBuilder.DeleteDoubleEdgedPipe(position, pipe)); }
public void CheckIfDoubleEdgedPipeIsDeletedCorrectly() { var position = new Coordinate(2, 3); var pipe = new DoubleEdgedPipe(EdgeType.DOWN, EdgeType.UP); var key = new PipePosition(position, pipe.FirstEdge, pipe.SecondEdge); doubleEdgedPipes.Add(key, mockPipe.Object); blueprintBuilderViewModel.DoubleEdgePipeDeleted(mockBlueprint.Object, position, pipe); Assert.IsFalse(doubleEdgedPipes.ContainsKey(key)); }
public void CannotAddDoubleEdgedPipeIfBlockInexistent() { var position = new Coordinate(5, 4); var pipe = new DoubleEdgedPipe(EdgeType.DOWN, EdgeType.UP); mockBlock.Setup(x => x.HasShipComponent()).Returns(false); Assert.IsFalse(blueprintBuilder.AddDoubleEdgedPipe(position, pipe.FirstEdge, pipe.SecondEdge)); Assert.AreEqual(0, mockBlock.Object.PipesWithBothEdges.Count()); }
public void CheckIfExistingDoubleEdgedPipeIsDeletedSuccessfully() { var position = new Coordinate(5, 4); var pipe = new DoubleEdgedPipe(EdgeType.DOWN, EdgeType.UP); blocks.Set(position, mockBlock.Object); blocks.Get(position).AddPipe(pipe); Assert.IsTrue(blueprintBuilder.DeleteDoubleEdgedPipe(position, pipe)); Assert.AreEqual(0, mockBlock.Object.PipesWithBothEdges.Count()); }
public void CheckThatPlacingDoubleEdgedPipeCallsObserver() { var position = new Coordinate(3, 4); var pipe = new DoubleEdgedPipe(EdgeType.RIGHT, EdgeType.DOWN); blueprint.PlaceBlock(position, mockBlock.Object); blueprint.PlacePipe(position, pipe); mockObserver.Verify(obs => obs.DoubleEdgePipeAdded(It.IsAny <IBlueprint>(), position, pipe), Times.Once()); mockBlock.Verify(block => block.AddPipe(pipe), Times.Once()); }
private void AddOrDeletePipe(Coordinate position, DoubleEdgedPipe pipe) { if (PipeExists(position, pipe) || PipeExists(position, pipe.FirstEdge) && PipeExists(position, pipe.SecondEdge)) { blueprintBuilder.DeleteDoubleEdgedPipe(position, pipe); } else { blueprintBuilder.AddDoubleEdgedPipe(position, pipe.FirstEdge, pipe.SecondEdge); } }
public void CheckThatRemovingShipComponentCallsObserver() { var position = new Coordinate(3, 4); var pipe = new DoubleEdgedPipe(EdgeType.RIGHT, EdgeType.DOWN); blueprint.PlaceBlock(position, mockBlock.Object); blueprint.PlacePipe(position, pipe); blueprint.PlaceShipComponent(position, mockShipComponent.Object); blueprint.RemoveShipComponent(position); mockObserver.Verify(obs => obs.ShipComponentAdded(It.IsAny <IBlueprint>(), position), Times.Once()); mockObserver.Verify(obs => obs.ShipComponentDeleted(It.IsAny <IBlueprint>(), position), Times.Once()); }
public void CanAddDoubleEdgedPipeIfNothingOnBlock() { var position = new Coordinate(5, 4); var pipe = new DoubleEdgedPipe(EdgeType.DOWN, EdgeType.UP); blocks.Set(position, mockBlock.Object); mockBlock.Setup(x => x.HasShipComponent()).Returns(false); Assert.IsTrue(blueprintBuilder.AddDoubleEdgedPipe(position, pipe.FirstEdge, pipe.SecondEdge)); Assert.AreEqual(1, mockBlock.Object.PipesWithBothEdges.Count()); Assert.AreEqual(EdgeType.DOWN, doubleEdgedPipes[0].FirstEdge); Assert.AreEqual(EdgeType.UP, doubleEdgedPipes[0].SecondEdge); }
public void CheckThatTryingToDeleteInexistentDoubleEdgedPipeButWithConnectingPipesThatCanComposeItDeletesTheConnectingPipes() { var position = new Coordinate(5, 4); var pipe1 = new ConnectingPipe(EdgeType.DOWN); var pipe2 = new ConnectingPipe(EdgeType.UP); var pipe = new DoubleEdgedPipe(EdgeType.UP, EdgeType.DOWN); blocks.Set(position, mockBlock.Object); blocks.Get(position).AddPipe(pipe1); blocks.Get(position).AddPipe(pipe2); Assert.IsTrue(blueprintBuilder.DeleteDoubleEdgedPipe(position, pipe)); Assert.AreEqual(0, mockBlock.Object.PipesWithOneEdge.Count()); }
public void TryingToAddDoubleEdgedPipeOnBlockWithShipComponentResultsInAddingTwoConnectingPipes() { var position = new Coordinate(5, 4); var pipe = new DoubleEdgedPipe(EdgeType.DOWN, EdgeType.UP); blocks.Set(position, mockBlock.Object); mockBlock.Setup(x => x.HasShipComponent()).Returns(true); Assert.IsTrue(blueprintBuilder.AddDoubleEdgedPipe(position, pipe.FirstEdge, pipe.SecondEdge)); Assert.AreEqual(0, mockBlock.Object.PipesWithBothEdges.Count()); Assert.AreEqual(2, mockBlock.Object.PipesWithOneEdge.Count()); Assert.AreEqual(EdgeType.DOWN, mockBlock.Object.PipesWithOneEdge.First().Edge); Assert.AreEqual(EdgeType.UP, mockBlock.Object.PipesWithOneEdge.Skip(1).First().Edge); }
public void CheckThatDeletingBlockDoubleEdgedPipesAlsoDeletesTheDoubleEdgedPipes() { var position = new Coordinate(5, 4); var pipe = new DoubleEdgedPipe(EdgeType.DOWN, EdgeType.UP); blocks.Set(position, mockBlock.Object); blocks.Get(position).AddPipe(pipe); mockBlock.Setup(x => x.HasShipComponent()).Returns(false); Assert.IsTrue(blueprintBuilder.DeleteBlock(position)); Assert.AreEqual(null, blocks[4, 5]); Assert.AreEqual(0, mockBlock.Object.PipesWithBothEdges.Count()); mockBlock.Verify(x => x.DeletePipe(It.IsAny <DoubleEdgedPipe>()), Times.Once()); }
public void CanAddDoubleEdgedPipeIfAnotherDoubleEdgedPipeAlreadyExistsAndDoesNotIntersect() { var position = new Coordinate(5, 4); var pipe1 = new DoubleEdgedPipe(EdgeType.DOWN, EdgeType.UP); var pipe2 = new DoubleEdgedPipe(EdgeType.DOWN, EdgeType.RIGHT); blocks.Set(position, mockBlock.Object); mockBlock.Setup(x => x.HasShipComponent()).Returns(false); doubleEdgedPipes.Add(pipe1); Assert.IsTrue(blueprintBuilder.AddDoubleEdgedPipe(position, pipe2.FirstEdge, pipe2.SecondEdge)); Assert.AreEqual(2, mockBlock.Object.PipesWithBothEdges.Count()); Assert.AreEqual(EdgeType.DOWN, doubleEdgedPipes[1].FirstEdge); Assert.AreEqual(EdgeType.RIGHT, doubleEdgedPipes[1].SecondEdge); }
public void CreateCurvedPipeObjectWithCorrectCurve() { var position = new Coordinate(2, 3); var pipe = new DoubleEdgedPipe(EdgeType.DOWN, EdgeType.UP); tiles.Set(position, mockTile.Object); ICurve curve = null; mockPipeFactory.Setup(factory => factory.Create(It.IsAny <ICurve>())) .Returns(mockPipe.Object) .Callback <ICurve>(curveParam => curve = curveParam); blueprintBuilderViewModel.DoubleEdgePipeAdded(mockBlueprint.Object, position, pipe); Assert.AreEqual(new Vector2(0, -1), curve.GetPoint(0)); Assert.AreEqual(new Vector2(0, 1), curve.GetPoint(1)); }
public void AfterTryingToAddDoubleEdgedPipeThatIntersectsWithExistingDoubleEdgedPipeNeitherWillBeFoundInDoubleEdgedPipesList() { var position = new Coordinate(5, 4); var pipe1 = new DoubleEdgedPipe(EdgeType.DOWN, EdgeType.UP); var pipe2 = new DoubleEdgedPipe(EdgeType.LEFT, EdgeType.RIGHT); blocks.Set(position, mockBlock.Object); mockBlock.Setup(x => x.HasShipComponent()).Returns(false); mockBlock.Setup(block => block.AddShipComponent(It.IsAny <EmptyShipComponent>())).Callback(() => mockBlock.Setup(x => x.HasShipComponent()).Returns(true)); doubleEdgedPipes.Add(pipe1); Assert.IsTrue(blueprintBuilder.AddDoubleEdgedPipe(position, pipe2.FirstEdge, pipe2.SecondEdge)); Assert.AreEqual(0, mockBlock.Object.PipesWithBothEdges.Count()); Assert.AreEqual(4, mockBlock.Object.PipesWithOneEdge.Count()); Assert.AreEqual(EdgeType.DOWN, mockBlock.Object.PipesWithOneEdge.First().Edge); mockBlock.Verify(x => x.AddShipComponent(It.IsAny <EmptyShipComponent>()), Times.Once()); }
public void CreateCurvedPipeObjectAtCorrectPosition() { var position = new Coordinate(2, 3); var pipe = new DoubleEdgedPipe(EdgeType.DOWN, EdgeType.UP); tiles.Set(position, mockTile.Object); var location = new Vector2(1, 3); var scale = new Vector2(4, 5); mockTile.SetupGet(tile => tile.Position).Returns(location); mockTile.SetupGet(tile => tile.Scale).Returns(scale); mockPipeFactory.Setup(factory => factory.Create(It.IsAny <ICurve>())).Returns(mockPipe.Object); blueprintBuilderViewModel.DoubleEdgePipeAdded(mockBlueprint.Object, position, pipe); Assert.AreEqual(location, doubleEdgedPipes[new PipePosition(position, EdgeType.DOWN, EdgeType.UP)].Position); Assert.AreEqual(scale, doubleEdgedPipes[new PipePosition(position, EdgeType.DOWN, EdgeType.UP)].Scale); }
public void DeleteAlreadyCreatedPipe() { var position = new Coordinate(2, 3); var edge = new CoordinatePair(position, new Coordinate(2, 4)); var otherEdge = new CoordinatePair(position, new Coordinate(2, 2)); doubleEdgedPipes.Add(new DoubleEdgedPipe(EdgeType.DOWN, EdgeType.UP)); mockBlueprintBuilder.Setup(builder => builder.GetBlock(position)).Returns(mockBlock.Object); DoubleEdgedPipe pipeParameter = null; mockBlueprintBuilder .Setup(builder => builder.DeleteDoubleEdgedPipe(position, It.IsAny <DoubleEdgedPipe>())) .Callback <Coordinate, DoubleEdgedPipe>((coord, param) => pipeParameter = param); pipeBuildController.SelectedLink = edge; pipeBuildController.SelectPipeLink(otherEdge); Assert.AreEqual(EdgeType.UP, pipeParameter.FirstEdge); Assert.AreEqual(EdgeType.DOWN, pipeParameter.SecondEdge); }
public void CheckThatIsEqualToForDoubleEdgedPipeForConnectingPipesReturnsTrue() { var pipe = new DoubleEdgedPipe(EdgeType.DOWN, EdgeType.UP); Assert.IsTrue(doubleEdgedPipe.IsEqualTo(pipe)); }
private bool PipeExists(Coordinate position, DoubleEdgedPipe pipe) { return(blueprintBuilder.GetBlock(position).PipesWithBothEdges.Any(blockPipe => blockPipe.IsEqualTo(pipe))); }
public void DoubleEdgePipeDeleted(IBlueprint blueprint, Coordinate position, DoubleEdgedPipe pipe) { objectTable.DeletePipe(position, pipe.FirstEdge, pipe.SecondEdge); }
public void DoubleEdgePipeAdded(IBlueprint blueprint, Coordinate position, DoubleEdgedPipe pipe) { CreatePipeObject(blueprint, position, pipe.FirstEdge, pipe.SecondEdge); }
public void DoubleEdgePipeDeleted(IBlueprint blueprint, Coordinate position, DoubleEdgedPipe pipe) { throw new NotImplementedException(); }
public void Init() { doubleEdgedPipe = new DoubleEdgedPipe(EdgeType.UP, EdgeType.DOWN); }
public void CheckThatIsEqualToForDoubleEdgedPipeForConnectingPipesReturnsFalse() { var pipe = new DoubleEdgedPipe(EdgeType.UP, EdgeType.LEFT); Assert.IsFalse(doubleEdgedPipe.IsEqualTo(pipe)); }