Ejemplo n.º 1
0
        public void ReactsToThrottle()
        {
            var settings = new HarvestApiSettings()
              {
            BaseUri = HttpServer.BaseUri,
            Password = "******",
            UserName = "******"
              };
              ProjectsApi api = new ProjectsApi(settings);

              var projectsTask = api.GetProjects();
              using (var req = HttpServer.HandleRequest(verbose: true))
              {
            Assert.True(req.RawRequest.AcceptTypes.Contains("application/json"), "accept types: " + req.RawRequest.AcceptTypes.ToListString());
            req.ResponseBodyText = string.Empty;
            req.StatusCode = HttpStatusCode.ServiceUnavailable;
              }

              try
              {
            var count = projectsTask.Result.Count;
            Assert.Fail("should have failed at this point");
              }
              catch(HarvestThrottleException)
              {
            Console.WriteLine("Throttle exception thrown");
              }
              catch (AggregateException ae)
              {
            Assert.True(ae.InnerExceptions.Any(x => x is HarvestThrottleException), "expecting a throttle exception");
              }
        }
Ejemplo n.º 2
0
        protected HarvestApiSettings GetSettings()
        {
            var settings = new HarvestApiSettings()
              {
            BaseUri = HttpServer.BaseUri,
            Password = "******",
            UserName = "******",
              };

              return settings;
        }
Ejemplo n.º 3
0
        public void UsesJson()
        {
            var settings = new HarvestApiSettings()
              {
            BaseUri = HttpServer.BaseUri,
            Password = "******",
            UserName = "******"
              };
              var api = new ProjectsApi(settings);

              var projectsTask = api.GetProjects();
              using (var req = HttpServer.HandleRequest(verbose: true))
              {
            Assert.True(req.RawRequest.AcceptTypes.Contains("application/json"), "accept types: " + req.RawRequest.AcceptTypes.ToListString());
            req.ResponseBodyText = Encoding.UTF8.GetString(Properties.Resources.AllProjects);
              }
        }
Ejemplo n.º 4
0
        public void UsesBasicAuthentication()
        {
            var settings = new HarvestApiSettings()
                       {
                         BaseUri = HttpServer.BaseUri,
                         Password = "******",
                         UserName = "******"
                       };
              ProjectsApi api = new ProjectsApi(settings);

              var projectsTask = api.GetProjects();
              using(var req = HttpServer.HandleRequest(verbose:true))
              {
            var authenticationHeader = req.RawRequest.Headers["Authorization"];
            Assert.NotNull(authenticationHeader);
              }
        }