public void Shoot_WHEN_InvokedWithAlreadyUsedField_THEN_ReturnsAlreadyShootStatus() { var mapRepoMock = new Mock <IRepository <Map> >(); var scoreRepositoryMock = new Mock <IRepository <Score> >(); scoreRepositoryMock.SetupGet(c => c.Entity).Returns(new Score()); var mapWithShips = new Map(10, 10); var ship = CreateShipWithCoordinates(); AssignShipToMap(mapWithShips, ship); mapRepoMock.SetupGet(c => c.Entity).Returns(mapWithShips); var battleService = new BattleService(mapRepoMock.Object, scoreRepositoryMock.Object); battleService.Shoot(0, 1); var result = battleService.Shoot(0, 1); result.LastShootStatus.Should().BeEquivalentTo(ShootStatus.AlreadyShoot); }
public void Shoot_WHEN_InvokedAndNoMapFound_THEN_ThrowsMapNotInitializedException() { var mapRepoMock = new Mock <IRepository <Map> >(); var scoreRepositoryMock = new Mock <IRepository <Score> >(); mapRepoMock.SetupGet(c => c.Entity).Returns((Map)null); var battleService = new BattleService(mapRepoMock.Object, scoreRepositoryMock.Object); var act = new Func <ShootResult>(() => battleService.Shoot(10, 2)); act.Should().ThrowExactly <MapNotInitializedException>(); }
public void Shoot_WHEN_InvokedWithOutOfRange_THEN_ThrowsOutOfRangeException() { var mapRepoMock = new Mock <IRepository <Map> >(); var scoreRepositoryMock = new Mock <IRepository <Score> >(); var mapWithShips = new Map(10, 10); mapRepoMock.SetupGet(c => c.Entity).Returns(mapWithShips); var battleService = new BattleService(mapRepoMock.Object, scoreRepositoryMock.Object); var act = new Func <ShootResult>(() => battleService.Shoot(10, 2)); act.Should().ThrowExactly <ArgumentOutOfRangeException>(); }
public void CannotHitEnemyPlainIfPositionIsWrong() { var mockPlain = new Mock <ICanGetHit>(); var service = new BattleService(); var position = new Position(2, 2); mockPlain.Setup(x => x.TakeHit(position)).Returns(false); var result = service.Shoot(mockPlain.Object, position); Assert.Equal(AttackResult.Miss, result); mockPlain.Verify(x => x.TakeHit(position), Times.Once); }