Exemplo n.º 1
0
        public void Init()
        {
            blocks            = new IBlock[9, 10];
            blueprint         = new Blueprint(blocks);
            mockBlock         = new Mock <IBlock>();
            mockShipComponent = new Mock <IShipComponent>();

            mockBlockFactories = new Mock <IList <IFactory <IBlock> > >();
            Mock <IFactory <IBlock> > mockBlockFactory = new Mock <IFactory <IBlock> >();

            mockBlockFactory.Setup(b => b.Create()).Returns(mockBlock.Object);
            mockBlockFactories.SetupGet(m => m[0]).Returns(mockBlockFactory.Object);

            mockShipComponentFactory      = new Mock <IFactory <IShipComponent, IConstBlock> >();
            mockEmptyShipComponentFactory = new Mock <IFactory <IShipComponent, IConstBlock> >();
            blueprintBuilder             = new BlueprintBuilder(blueprint, mockBlockFactories.Object, mockShipComponentFactory.Object, mockEmptyShipComponentFactory.Object);
            doubleEdgedPipes             = new List <DoubleEdgedPipe>();
            oneEdgedPipes                = new List <ConnectingPipe>();
            mockBlockRestrictor          = new Mock <IBlockRestrictor>();
            mockBlueprintBuilderObserver = new Mock <IBlueprintBuilderObserver>();
            blueprintBuilder.AttachObserver(mockBlueprintBuilderObserver.Object);

            mockBlock.SetupGet(x => x.PipesWithBothEdges).Returns(doubleEdgedPipes);
            mockBlock.SetupGet(x => x.PipesWithOneEdge).Returns(oneEdgedPipes);
            mockBlock.Setup(block => block.AddPipe(It.IsAny <ConnectingPipe>())).Callback <ConnectingPipe>(p => oneEdgedPipes.Add(p));
            mockBlock.Setup(block => block.AddPipe(It.IsAny <DoubleEdgedPipe>())).Callback <DoubleEdgedPipe>(p => doubleEdgedPipes.Add(p));
            mockBlock.Setup(block => block.DeletePipe(It.IsAny <ConnectingPipe>())).Callback <ConnectingPipe>(p => oneEdgedPipes.Remove(p));
            mockBlock.Setup(block => block.DeletePipe(It.IsAny <DoubleEdgedPipe>())).Callback <DoubleEdgedPipe>(p => doubleEdgedPipes.Remove(p));
        }
Exemplo n.º 2
0
        public void CanAttachObserverToBuilderThroughBlueprintBuilder()
        {
            var mockObserver = new Mock <IBlueprintBuilderObserver>();

            blueprintBuilder.AttachObserver(mockObserver.Object);
            blueprint.PlaceBlock(new Coordinate(2, 3), mockBlock.Object);
            mockObserver.Verify(observer => observer.BlockCreated(blueprint, new Coordinate(2, 3)));
        }