Example #1
0
        public string[] Get(string source, string destination)
        {
            var request      = new GetShortestPath.Request(source, destination);
            var shortestPath = new GetShortestPath(dbContext).Handle(request);

            return(shortestPath);
        }
Example #2
0
        public async Task GetShortestPath()
        {
            // arrange
            //serviceRepository.Setup(m => m.Query())
            //                               .Returns<IQueryable<Service>>(p => p);

            //routeRepository.Setup(m => m.Query())
            //.Returns<IQueryable<Route>>(p => p);

            //var serviceDbSetMock = Builder<Service>.CreateListOfSize(9).Build().ToAsyncDbSetMock();
            //serviceRepository.Setup(m => m.Query()).Returns(serviceDbSetMock.Object);

            //var routeDbSetMock = Builder<Route>.CreateListOfSize(11).Build().ToAsyncDbSetMock();
            //routeRepository.Setup(m => m.Query()).Returns(routeDbSetMock.Object);

            _handler = new ServiceHandler(serviceRepository.Object, routeRepository.Object);

            var comand = new GetShortestPath(1, 2);

            var result = await _handler.Handle(comand, GetCancelationToken(TimeSpan.FromSeconds(1)).Token);

            Assert.NotNull(result);

            var objectResult = result as Response;

            Assert.NotNull(objectResult);
        }
Example #3
0
        public Task <Response> Handle(GetShortestPath request, CancellationToken cancellationToken)
        {
            var response = new Response();
            var result   = serviceRepository.Query().ToList();

            if (!result.Any(x => x.Id == request.StartId))
            {
                response.AddError("Initial Service does not exist.");

                return(Task.FromResult(response));
            }

            if (!result.Any(x => x.Id == request.DestinationId))
            {
                response.AddError("End Service does not exist.");

                return(Task.FromResult(response));
            }

            result.ForEach(x =>
            {
                x.AddRoutes(routeRepository.Query().Where(r => r.ServiceOriginId == x.Id).ToList());
            });

            var path = new List <int>()
            {
                request.StartId
            };

            SearchPath(request.StartId, request.DestinationId, ref path, ref result);

            return(Task.FromResult(new Response(path)));
        }
 public void FromTorontoPearsonAirportToOHareAirport_ShouldThrowExceptionNoRoute()
 {
     Assert.Throws <BusinessException>(() =>
     {
         try
         {
             var result = new GetShortestPath(dbContext).Handle(new GetShortestPath.Request("YYZ", "ORD"));
         }
         catch (Exception exception)
         {
             Assert.True(exception is BusinessException && exception.Equals(BusinessException.NO_ROUTE));
             throw;
         }
     });
 }
        public void FromTorontoPearsonAirportToVancouverAirportTo()
        {
            var result = new GetShortestPath(dbContext).Handle(new GetShortestPath.Request("YYZ", "YVR"));

            Assert.Equal("YYZ -> JFK -> LAX -> YVR", string.Join(" -> ", result));
        }
        public void FromTorontoPearsonAirportToJohnKennedyAirport()
        {
            var result = new GetShortestPath(dbContext).Handle(new GetShortestPath.Request("YYZ", "JFK"));

            Assert.Equal("YYZ -> JFK", string.Join(" -> ", result));
        }