public void ItShouldReturnAStarShipWithMegalightsWithAValueOf10()
        {
            var dto = new StarShipDTO("ship ship", "10", "1 day");

            var result        = this.mapper.Map(dto);
            int expectedValue = 10;

            Assert.IsNotNull(result.MegalightsPerHour);
            Assert.AreEqual(expectedValue, result.MegalightsPerHour);
        }
Ejemplo n.º 2
0
        private int?GetConsumables(StarShipDTO dto)
        {
            if (!this.IsStarShipValidForCalculations(dto))
            {
                return(null);
            }

            var consumables = string.Join("", dto.Consumables.Where(char.IsDigit));

            return(int.Parse(consumables));
        }
Ejemplo n.º 3
0
        private int?GetMegaliths(StarShipDTO dto)
        {
            if (!this.IsStarShipValidForCalculations(dto))
            {
                return(null);
            }

            var megalights = int.Parse(dto.MegalightsPerHour);

            return(megalights);
        }
Ejemplo n.º 4
0
        private static void ShowStarShips(StarShipDTO starShipDTO)
        {
            foreach (var starShipItemDTO in starShipDTO.StarShipItemDTO)
            {
                string stopsRequired = (starShipItemDTO.StopsRequired > -1)
                    ? starShipItemDTO.StopsRequired.ToString()
                    : "unknow";

                Console.WriteLine(string.Format("{0} | {1}", starShipItemDTO.Name, stopsRequired));
            }
        }
        public void ItShouldReturnAStarShipWithConsumablesWithAValueOf7Years()
        {
            var dto = new StarShipDTO("ship ship", "22", "7 years");

            var         result              = this.mapper.Map(dto);
            int         expectedDays        = 7;
            TimeMeasure expectedTimeMeasure = TimeMeasure.Year;


            Assert.IsNotNull(result.Consumables);
            Assert.AreEqual(expectedDays, result.Consumables);
            Assert.AreEqual(expectedTimeMeasure, result.ConsumablesTimeMeasure);
        }
        public void ItShouldReturnAStarShipObject()
        {
            string shipName    = "ship ship";
            string megaliths   = "10";
            string consumables = "1 day";

            var dto = new StarShipDTO(shipName, megaliths, consumables);

            var result = this.mapper.Map(dto);

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(StarShip));
        }
Ejemplo n.º 7
0
        public void ShouldReturnB_wingTransportAnd163StopsWhenTheDistanceEqual2MillionAnd500ThousandWhenPageEquals2()
        {
            string          url = GetUrl("page2.json");
            StarShipDTO     starShipDTOExpected     = CreateStarShip("page3.json", "B-wing", 163);
            StarShipItemDTO starShipItemDTOExpected = starShipDTOExpected.StarShipItemDTO.First();

            StarShipDTO starShipDTO = this.starShipService.GetStopsRequired("2500000", url);

            StarShipItemDTO starShipItemDTO = starShipDTO.StarShipItemDTO
                                              .Where(s => s.Name.Equals(starShipItemDTOExpected.Name)).FirstOrDefault();

            Assert.Equal(starShipDTOExpected.NextPage, starShipDTO.NextPage);
            Assert.Equal(starShipItemDTOExpected.Name, starShipItemDTO.Name);
            Assert.Equal(starShipItemDTOExpected.StopsRequired, starShipItemDTO.StopsRequired);
        }
Ejemplo n.º 8
0
        public void ShouldReturnRebelTransportAnd11StopsWhenTheDistanceEqual1MillionWhenPageEquals1()
        {
            string          url = GetUrl("page1.json");
            StarShipDTO     starShipDTOExpected     = CreateStarShip("page2.json", "Rebel transport", 11);
            StarShipItemDTO starShipItemDTOExpected = starShipDTOExpected.StarShipItemDTO.First();

            StarShipDTO starShipDTO = this.starShipService.GetStopsRequired("1000000", url);

            StarShipItemDTO starShipItemDTO = starShipDTO.StarShipItemDTO
                                              .Where(s => s.Name.Equals(starShipItemDTOExpected.Name)).FirstOrDefault();

            Assert.Equal(starShipDTOExpected.NextPage, starShipDTO.NextPage);
            Assert.Equal(starShipItemDTOExpected.Name, starShipItemDTO.Name);
            Assert.Equal(starShipItemDTOExpected.StopsRequired, starShipItemDTO.StopsRequired);
        }
Ejemplo n.º 9
0
        private StarShipDTO CreateStarShip(string nextPage, string starShipName, int stopsRequired)
        {
            StarShipDTO starShipDTO = new StarShipDTO();

            starShipDTO.NextPage = nextPage;

            StarShipItemDTO starShipItemDTO = new StarShipItemDTO();

            starShipItemDTO.Name          = starShipName;
            starShipItemDTO.StopsRequired = stopsRequired;

            starShipDTO.StarShipItemDTO.Add(starShipItemDTO);

            return(starShipDTO);
        }
Ejemplo n.º 10
0
        public void ShouldReturnNabooStarSkiffTransportAndNegative1StopsWhenTheDistanceEqual150ThousandAndConsumablesUnknowWhenPageEquals4()
        {
            string          url = GetUrl("page4.json");
            StarShipDTO     starShipDTOExpected     = CreateStarShip(null, "Naboo star skiff", -1);
            StarShipItemDTO starShipItemDTOExpected = starShipDTOExpected.StarShipItemDTO.First();

            StarShipDTO starShipDTO = this.starShipService.GetStopsRequired("150000", url);

            StarShipItemDTO starShipItemDTO = starShipDTO.StarShipItemDTO
                                              .Where(s => s.Name.Equals(starShipItemDTOExpected.Name)).FirstOrDefault();

            Assert.Equal(starShipDTOExpected.NextPage, starShipDTO.NextPage);
            Assert.Equal(starShipItemDTOExpected.Name, starShipItemDTO.Name);
            Assert.Equal(starShipItemDTOExpected.StopsRequired, starShipItemDTO.StopsRequired);
        }
Ejemplo n.º 11
0
        public void ShouldReturnRepublicAttackCruiserTransportAndNegative1StopsWhenTheDistanceEqual150ThousandAndMgltUnknowWhenPageEquals3()
        {
            string          url = GetUrl("page3.json");
            StarShipDTO     starShipDTOExpected     = CreateStarShip("page4.json", "Republic attack cruiser", -1);
            StarShipItemDTO starShipItemDTOExpected = starShipDTOExpected.StarShipItemDTO.First();

            StarShipDTO starShipDTO = this.starShipService.GetStopsRequired("150000", url);

            StarShipItemDTO starShipItemDTO = starShipDTO.StarShipItemDTO
                                              .Where(s => s.Name.Equals(starShipItemDTOExpected.Name)).FirstOrDefault();

            Assert.Equal(starShipDTOExpected.NextPage, starShipDTO.NextPage);
            Assert.Equal(starShipItemDTOExpected.Name, starShipItemDTO.Name);
            Assert.Equal(starShipItemDTOExpected.StopsRequired, starShipItemDTO.StopsRequired);
        }
Ejemplo n.º 12
0
        private TimeMeasure GetConsumablesTimeMeasure(StarShipDTO dto)
        {
            string day   = "day";
            string week  = "week";
            string month = "month";
            string year  = "year";

            if (!this.IsStarShipValidForCalculations(dto))
            {
                return(TimeMeasure.Unknown);
            }

            var timeMeasure = string.Join("", dto.Consumables.Where(char.IsLetter)).ToLower();

            if (timeMeasure.Contains(day))
            {
                return(TimeMeasure.Day);
            }

            if (timeMeasure.Contains(week))
            {
                return(TimeMeasure.Week);
            }

            if (timeMeasure.Contains(month))
            {
                return(TimeMeasure.Month);
            }

            if (timeMeasure.Contains(year))
            {
                return(TimeMeasure.Year);
            }

            throw new Exception(string.Format("Invalid time measure: {0}", timeMeasure));
        }