示例#1
0
        public void Setup()
        {
            var mShip = new Mock <Ship>(It.IsAny <Constraints.ShipType>());

            mShip.Object.Coordinates = new List <Coordinates>();
            ship = new Lazy <Ship>(() => mShip.Object);

            var miShip = new Mock <IShip>();

            miShip.Setup(s => s.Attack(It.IsAny <string>(), It.IsAny <IMissile>())).Returns(It.IsAny <bool>);

            Ship shipMock = new Ship(It.IsAny <Constraints.ShipType>());

            shipMock.Coordinates = new List <Coordinates>();

            miShip.Setup(s => s.Ship).Returns(() => shipMock).Callback(() => { shipMock = ship.Value; });

            var iShip = new Lazy <IShip>(() => miShip.Object);

            ships = new List <IShip>()
            {
                iShip.Value, iShip.Value
            };

            player = new Mock <Player>(It.IsAny <string>()).Object;
            IShip intShip = new ShipP();

            intShip.Ship = shipMock;

            var shipFactory = new Mock <IShipFactory>();

            shipFactory.Setup(s => s.Create(It.IsAny <Constraints.ShipType>())).Returns(() => intShip).Callback(() => { intShip = iShip.Value; });
            this.ShipFactory = shipFactory;
        }
        public void Setup()
        {
            var mShip = new Mock <Ship>(It.IsAny <Constraints.ShipType>());

            mShip.Object.Coordinates = new List <Coordinates>();
            ship = new Lazy <Ship>(() => mShip.Object);

            var miShip = new Mock <IShip>();

            miShip.Setup(s => s.Attack(It.IsAny <string>(), It.IsAny <IMissile>())).Returns(It.IsAny <bool>);

            Ship shipMock = new Ship(It.IsAny <Constraints.ShipType>());

            shipMock.Coordinates = new List <Coordinates>();

            miShip.Setup(s => s.Ship).Returns(() => shipMock).Callback(() => { shipMock = ship.Value; });

            var iShip = new Lazy <IShip>(() => miShip.Object);

            ships = new List <IShip>()
            {
                iShip.Value, iShip.Value
            };

            player = new Mock <Player>(It.IsAny <string>()).Object;
            IShip intShip = new ShipP();

            intShip.Ship = shipMock;

            var shipFactory = new Mock <IShipFactory>();

            shipFactory.Setup(s => s.Create(It.IsAny <Constraints.ShipType>())).Returns(() => intShip).Callback(() => { intShip = iShip.Value; });
            this.ShipFactory = shipFactory;

            var playerService = new Mock <IPlayerService>();

            Players = new List <Player>();

            var missileService = new Mock <IMissileFactory>();

            playerService.SetupGet(p => p.Players).Returns(Players);
            playerService.Setup(p => p.CreatePlayer(It.IsAny <string>(), It.IsAny <IEnumerable <IShip> >(), It.IsAny <string[]>(), It.IsAny <IMissile>()))
            .Callback((string Name, IEnumerable <IShip> paramShips, string[] targets) =>
            {
                Players.Add(new Player(Name, missileService.Object.CreateMissile(Constraints.MissileType.Range))
                {
                    Ships   = paramShips,
                    Targets = targets
                });;
            });
            playerService.Setup(p => p.Play()).Returns("Player-2 won the battle");

            playerService.Setup(p => p.PlayerTurn(player, It.IsAny <int>(), ships));
            this.PlayerService = playerService;

            var battleshipService = new BattleshipService(PlayerService.Object, ShipFactory.Object, null);

            this.BattleshipService = battleshipService;
        }