Example #1
0
        public void CalculateTotalDamage_SetTwoWeaponsInDifferentSlots_GivesSummationOfWeaponsDamagePower()
        {
            using (var mock = AutoMock.GetLoose())
            {
                // Arrange
                var raven = Battleship.CreateBattleship("Raven");
                mock.Mock <IWeapon>().Setup(x => x.KineticDamage).Returns(500);
                mock.Mock <IWeapon>().Setup(x => x.ThermalDamage).Returns(500);
                mock.Mock <IWeapon>().Setup(x => x.ElectromagneticDamage).Returns(500);
                mock.Mock <IWeapon>().Setup(x => x.ExplosiveDamage).Returns(500);
                mock.Mock <IWeapon>().Setup(x => x.Type).Returns(WeaponType.Large);

                var cannon  = mock.Create <IWeapon>();
                var cannon2 = mock.Create <IWeapon>();

                raven.InstallWeapon(cannon, 3);
                raven.InstallWeapon(cannon2, 4);

                // Act
                uint result = raven.CalculateTotalDamage();

                // Assert
                Assert.AreEqual(4000, result);
            }
        }
Example #2
0
        public void RemoveWeapon_RemoveWeaponFromSlot()
        {
            using (var mock = AutoMock.GetLoose())
            {
                //Arrange
                var reven = Battleship.CreateBattleship("Reven");

                //Act
                reven.RemoveWeapon(3);
                Assert.IsNull(reven.WeaponSlots[3]);
                //shipMock.VerifyAll();
            }
        }
Example #3
0
        public void InstallWeapon_SetweaponInSlot_SetsweaponInCorrectSlot()
        {
            using (var mock = AutoMock.GetLoose())
            {
                //Arrange
                var reven  = Battleship.CreateBattleship("Reven");
                var cannon = Weapon.CreateWeapon("Cannon", WeaponType.Large);

                //Act
                reven.InstallWeapon(cannon, 3);
                Assert.AreEqual(cannon, reven.WeaponSlots[3]);
            }
        }
Example #4
0
        public void SetFormationRow_ValidInput_SetShipRowWithSpecifiedQuantity()
        {
            using (var mock = AutoMock.GetLoose())
            {
                //Arrange
                BattleFormation formation = new BattleFormation("formation 1");
                var             ship      = Battleship.CreateBattleship("Reven");
                //var shipMock = mock.Mock<Ship>();
                //var ship = shipMock.Object;
                //Act
                formation.SetFormationRow(ship, 100, 2);

                //Assert
                Assert.AreSame(formation.Rows[2].SelectedShip, ship);
            }
        }
Example #5
0
        public void CreateBattleship_GivenProperNameOfShip_CreatesCorrectShip()
        {
            using (var mock = AutoMock.GetLoose())
            {
                // Arrange

                // Act
                var raven = Battleship.CreateBattleship("Raven");

                // Assert
                Assert.Multiple(() =>
                {
                    Assert.AreEqual("Raven", raven.Name, "Name mismatch.");
                    Assert.AreEqual(8, raven.WeaponSlots.Length, "Weapon slot mismatch");
                });
            }
        }
Example #6
0
        public void CreateBattleship_GivenInvalidShipname_ThrowsException()
        {
            using (var mock = AutoMock.GetLoose())
            {
                // Arrange

                // Act


                // Assert
                Assert.Multiple(() =>
                {
                    var ex = Assert.Throws <Exception>(() => Battleship.CreateBattleship("Raven2"),
                                                       "Expected exception is missing");
                    Assert.AreEqual("Invalid ship name", ex.Message, "Wrong error message");
                });
            }
        }
Example #7
0
        public void InstallWeapon_InvalidWeapon_ThrowsException()
        {
            using (var mock = AutoMock.GetLoose())
            {
                var raven  = Battleship.CreateBattleship("Raven");
                var cannon = Weapon.CreateWeapon("Cannon", WeaponType.Doomsday);
                //var cannon = mock.Create<IWeapon>();


                raven.InstallWeapon(cannon, 3);


                // Assert
                Assert.Multiple(() =>
                {
                    var ex = Assert.Throws <Exception>(() => raven.InstallWeapon(cannon, 3),
                                                       "Expected exception is missing");
                    Assert.AreEqual("Invalid ship name", ex.Message, "Wrong error message");
                });
            }
        }