Example #1
0
        public void EnderecoInvalido()
        {
            var bootstrapper = new FakeBoostrapper();

            bootstrapper.AddressQuery = () =>
                                            {
                                                var fake = new Mock<IAddressQuery>();
                                                fake.Setup(c => c.Execute())
                                                    .Returns(() =>
                                                                 {
                                                                     throw new AddressNotFoundException(
                                                                         "Endereço inválido");
                                                                 });
                                                return fake.Object;
                                            };

            var browser = new Browser(bootstrapper);

            var query = new Query { Addresses = new List<Address>{new Address{Name = "Ebdereco invalido"}}, Type = RouteType.LessTraffic };

            var result = browser.Post("/", with =>
            {
                with.HttpRequest();
                with.JsonBody(query);
            });

            Assert.Equal(HttpStatusCode.InternalServerError, result.StatusCode);
        }
Example #2
0
 private Route GetRoute(Query query)
 {
     _addressFinder.Addresses = query.Addresses;
     _routefinder.RouteType = query.Type;
     _routefinder.Coordinates = _addressFinder.Execute();
     return _routefinder.Execute();
 }
Example #3
0
 private static bool NoQueryOrAdderessesFound(Query query)
 {
     return null == query || null == query.Addresses || !query.Addresses.Any();
 }
Example #4
0
        public void MenorDistancia()
        {
            var bootstrapper = new FakeBoostrapper();
            var browser = new Browser(bootstrapper);

            var query = new Query
            {
                Addresses = new List<Address>
                {
                    new Address
                    {
                        City = "São Paulo",
                        State = "SP",
                        Name = "Av. Paulista",
                        Number = "1000"
                    },
                    new Address
                    {
                        City = "São Paulo",
                        State = "SP",
                        Name = "Av. Paulista",
                        Number = "2000"
                    }
                },
                Type = RouteType.FastestRoute
            };
            var route =
                "{\"Time\":{\"Days\":0,\"Hours\":0,\"Minutes\":30,\"Seconds\":0,\"Milliseconds\":0},\"Distance\":1,\"FuelCost\":1,\"TotalCost\":1}";

            bootstrapper.RouteQuery = GetRoute1();

            var result = browser.Post("/", with =>
            {
                with.HttpRequest();
                with.JsonBody(query);
            });

            var output = result.Body.AsString();

            Assert.Equal(route, output);
        }
Example #5
0
        public void NenhumEnderecoInformado()
        {
            var bootstrapper = new FakeBoostrapper();
            var browser = new Browser(bootstrapper);

            var query = new Query { Addresses = new List<Address>(), Type = RouteType.LessTraffic };

            var result = browser.Post("/", with =>
            {
                with.HttpRequest();
                with.JsonBody(query);
            });

            Assert.Equal(HttpStatusCode.BadRequest, result.StatusCode);
        }
Example #6
0
        public void MenosTransito()
        {
            var bootstrapper = new FakeBoostrapper();
            var browser = new Browser(bootstrapper);

            var query = new Query {Addresses = new List<Address>{new Address(), new Address()}, Type = RouteType.LessTraffic};
            var route = "{\"Time\":{\"Days\":0,\"Hours\":0,\"Minutes\":40,\"Seconds\":0,\"Milliseconds\":0},\"Distance\":2,\"FuelCost\":2,\"TotalCost\":2}";

            bootstrapper.RouteQuery = GetRoute2();

            var result = browser.Post("/", with =>
            {
                with.HttpRequest();
                with.JsonBody(query);
            });

            var output = result.Body.AsString();

            Assert.Equal(route, output);
        }