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());
        }
Exemplo n.º 3
0
        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));
        }
Exemplo n.º 4
0
        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));
        }
Exemplo n.º 5
0
        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));
        }
Exemplo n.º 6
0
        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());
        }
Exemplo n.º 7
0
        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());
        }
Exemplo n.º 8
0
        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);
     }
 }
Exemplo n.º 10
0
        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());
        }
Exemplo n.º 11
0
        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);
        }
Exemplo n.º 12
0
        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());
        }
Exemplo n.º 13
0
        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);
        }
Exemplo n.º 14
0
        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());
        }
Exemplo n.º 15
0
        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);
        }
Exemplo n.º 16
0
        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));
        }
Exemplo n.º 17
0
        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());
        }
Exemplo n.º 18
0
        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);
        }
Exemplo n.º 19
0
        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)));
 }
Exemplo n.º 22
0
 public void DoubleEdgePipeDeleted(IBlueprint blueprint, Coordinate position, DoubleEdgedPipe pipe)
 {
     objectTable.DeletePipe(position, pipe.FirstEdge, pipe.SecondEdge);
 }
Exemplo n.º 23
0
 public void DoubleEdgePipeAdded(IBlueprint blueprint, Coordinate position, DoubleEdgedPipe pipe)
 {
     CreatePipeObject(blueprint, position, pipe.FirstEdge, pipe.SecondEdge);
 }
Exemplo n.º 24
0
 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));
        }