static void Main(string[] args)
        {
            var stopsCalculator = new StopsCalculator();

            Console.WriteLine("Space: The Final Frontier.");
            Console.WriteLine("Hi, This is Faheem, I need to plan my next Journey.");
            Console.Write("Enter distance to cover in mega lights (MGLT) e.g. 1000000: ");
            Int64 distanceToCover = Int64.Parse(Console.ReadLine());

            Console.WriteLine($"The distance to my distination is: {distanceToCover}");
            Console.WriteLine("Wait, I am planning itenary......");

            GridResultDTO result = stopsCalculator.CalculateStops(distanceToCover.ToString());

            Console.WriteLine(Environment.NewLine + "...Itenary Starts..." + Environment.NewLine);

            foreach (var item in result.ResultDTO)
            {
                Console.WriteLine("{0} :: {1} stops", item.Name, item.Value);
            }

            Console.WriteLine(Environment.NewLine + "...Itenary Ends..." + Environment.NewLine);

            Console.WriteLine("Press any key to termincate the program ");
            Console.Read();
        }
        public void Test_CalculateStops()
        {
            //Arrange
            GridResultDTO expectedGrid   = new GridResultDTO();
            ResultDTO     expectedResult = new ResultDTO
            {
                Name  = "Y-wing",
                Value = 74
            };

            expectedGrid.ResultDTO = new System.Collections.Generic.List <ResultDTO>
            {
                expectedResult
            };
            string input = "1000000";

            //Act
            GridResultDTO actualGrid   = new StopsCalculator().CalculateStops(input);
            ResultDTO     actualResult = new ResultDTO();

            foreach (var item in actualGrid.ResultDTO)
            {
                if (item.Name == "Y-wing")
                {
                    actualResult = item;
                    break;
                }
            }

            //Assert
            bool result = expectedResult.Equals(actualResult);
        }
Beispiel #3
0
        public ActionResult Result(FormCollection form)
        {
            GridResultDTO listResultDTO = Search(form["txtDistance"]);

            if (listResultDTO == null)
            {
                return(RedirectToAction("Index", "Home"));
            }

            return(View(listResultDTO));
        }
Beispiel #4
0
        public GridResultDTO GetById(int id)
        {
            var           data      = _VendorRepository.GetById(id);
            GridResultDTO VendorDTO = new GridResultDTO()
            {
                Id         = data.Id,
                VendorName = data.VendorName,
                Title      = data.Title,
                IsDeleted  = data.IsDeleted,
                Date       = data.Date,
                Tag        = _VendorRepository.GetAllTags(id).Select(y => new TagDTO
                {
                    Name = y.Name
                }).ToList()
            };

            return(VendorDTO);
        }
Beispiel #5
0
        public GridResultDTO Search(string MGLTView)
        {
            string  url          = "http://swapi.co/api/starships/?page=1"; // Need to move to config
            Rest    rest         = new Rest();
            GridDTO starshipsDTO = rest.SendRequestion(url);

            GridResultDTO gridResultDTO = new GridResultDTO();

            if (starshipsDTO == null)
            {
                return(gridResultDTO);
            }

            List <ResultDTO> listResultDTO = new List <ResultDTO>();

            AddResultDTO(MGLTView, listResultDTO, starshipsDTO);

            for (int i = 0; i < Convert.ToInt32(starshipsDTO.Count) / 10; i++)
            {
                if (!string.IsNullOrEmpty(starshipsDTO.Next))
                {
                    starshipsDTO = rest.SendRequestion(starshipsDTO.Next);
                    if (starshipsDTO != null)
                    {
                        AddResultDTO(MGLTView, listResultDTO, starshipsDTO);
                    }
                }
            }

            gridResultDTO.MGLTView  = MGLTView;
            gridResultDTO.Count     = starshipsDTO.Count;
            gridResultDTO.Next      = starshipsDTO.Next;
            gridResultDTO.Previous  = starshipsDTO.Previous;
            gridResultDTO.ResultDTO = listResultDTO;

            return(gridResultDTO);
        }