コード例 #1
0
        public void GetConsumablesTest()
        {
            //// Arrange
            string name           = "test1";
            string mglt           = "100";
            string consumables    = "1 day";
            var    starshipEntity = new StarshipEntity(name, mglt, consumables);

            //// Act
            var starshipEntityConsumables = starshipEntity.GetConsumables();

            //// Assert
            Assert.AreEqual(consumables, starshipEntityConsumables);
        }
コード例 #2
0
        public void GetMGLTTest_MgltIsStringEmpty()
        {
            //// Arrange
            string name           = "test1";
            string mglt           = string.Empty;
            string consumables    = "1 day";
            var    starshipEntity = new StarshipEntity(name, mglt, consumables);

            //// Act
            var starshipEntityMGLT = starshipEntity.GetMGLT();

            //// Assert
            Assert.AreEqual(null, starshipEntityMGLT);
        }
コード例 #3
0
        public void StarshipEntityTest_ConsumablesIsNull()
        {
            //// Arrange
            string name        = "test1";
            string mglt        = "100";
            string consumables = null;

            //// Act
            var starshipEntity = new StarshipEntity(name, mglt, consumables);

            //// Assert
            Assert.AreEqual(name, starshipEntity.GetName());
            Assert.AreEqual(string.Empty, starshipEntity.GetConsumables());
            Assert.AreEqual(Convert.ToInt32(mglt), starshipEntity.GetMGLT());
        }
コード例 #4
0
        public void StarshipEntityTest_NameIsUnkown(string value)
        {
            //// Arrange
            string name        = value;
            string mglt        = "100";
            string consumables = "1 day";

            //// Act
            var starshipEntity = new StarshipEntity(name, mglt, consumables);

            //// Assert
            Assert.AreEqual(string.Empty, starshipEntity.GetName());
            Assert.AreEqual(consumables, starshipEntity.GetConsumables());
            Assert.AreEqual(Convert.ToInt32(mglt), starshipEntity.GetMGLT());
        }
コード例 #5
0
        public KeyValuePair <string, string> CalculateNumberOfResupplyStopsNeeded(StarshipEntity starship, int distance)
        {
            var totalHoursOfConsumables = _calculationService.GetConsumablesInHours(starship.GetConsumables());
            var totalHoursOfTravel      = _calculationService.GetTotalHoursToTravel(distance, starship.GetMGLT());

            if (totalHoursOfConsumables == null || totalHoursOfTravel == null)
            {
                return(new KeyValuePair <string, string>(starship.GetName(), "unknown"));
            }
            else
            {
                var numberOfStopsRequired = totalHoursOfTravel.Value / totalHoursOfConsumables.Value;

                return(new KeyValuePair <string, string>(starship.GetName(), numberOfStopsRequired.ToString()));
            }
        }
コード例 #6
0
        public void CalculateNumberOfResupplyStopsNeededTest_TotalHoursToTravelReturnsNull()
        {
            ////Arrange
            _calculationServiceMock.Setup(x => x.GetConsumablesInHours(It.IsAny <string>()))
            .Returns(10)
            .Verifiable();
            _calculationServiceMock.Setup(x => x.GetTotalHoursToTravel(It.IsAny <int>(), It.IsAny <int?>()))
            .Returns <int?>(null)
            .Verifiable();

            StarshipEntity starshipEntity = new StarshipEntity("Test1", string.Empty, string.Empty);

            ////Act
            var response = _starshipResupplyCalculation.CalculateNumberOfResupplyStopsNeeded(starshipEntity, 1000);

            ////Assert
            Assert.IsNotNull(response);
            Assert.AreEqual(starshipEntity.GetName(), response.Key);
            Assert.AreEqual("unknown", response.Value);
        }