Пример #1
0
        private static IEnumerable <TogglEntry> GetEntries(TogglEntry[] inputEntries, DateTime from, DateTime to)
        {
            Dictionary <string, string> headers = new Dictionary <string, string> {
                { "Set-Cookie", ValidFakeCookie }
            };
            MockHttpDataSource       source       = new MockHttpDataSource();
            TogglClient              client       = new TogglClient(FakeToken, source);
            ToggleClientStatusKeeper statusKeeper = new ToggleClientStatusKeeper(client);

            source.SetResponse(SessionUrl, "POST", new MockHttpResponse <TogglEntry[]>()
            {
                FakeHeaders = headers
            });

            client.LogIn();

            Assert.IsTrue(statusKeeper.IsLoggedIn);

            source.SetResponse(client.GetFormattedEntriesUrl(from, to), "GET", new MockHttpResponse <TogglEntry[]>()
            {
                FakeStatusCode     = HttpStatusCode.OK,
                FakeResponseObject = inputEntries
            });

            return(client.GetEntries(from, to));
        }
Пример #2
0
        private static ToggleClientStatusKeeper LoginWithHeaders(Dictionary <string, string> headers)
        {
            IHttpResponse response = new MockHttpResponse <TogglEntry[]>()
            {
                FakeHeaders = headers
            };
            MockHttpDataSource       source       = new MockHttpDataSource();
            TogglClient              client       = new TogglClient(FakeToken, source);
            ToggleClientStatusKeeper statusKeeper = new ToggleClientStatusKeeper(client);

            source.SetResponse(SessionUrl, "POST", response);
            client.LogIn();
            return(statusKeeper);
        }
Пример #3
0
        private static JiraClientStatusKeeper LoginWithHeaders(Dictionary <string, string> headers)
        {
            IHttpResponse response = new MockHttpResponse <TogglEntry[]>()
            {
                FakeHeaders = headers
            };
            MockHttpDataSource     source       = new MockHttpDataSource();
            JiraClient             client       = new JiraClient(FakeUsername, FakePassword, FakeServerUrl, source);
            JiraClientStatusKeeper statusKeeper = new JiraClientStatusKeeper(client);

            source.SetResponse(SessionUrl, "POST", response);
            client.LogIn();
            return(statusKeeper);
        }
Пример #4
0
        private static MockHttpDataSource GetLoggedInClient(out TogglClient client, out ToggleClientStatusKeeper statusKeeper)
        {
            Dictionary <string, string> headers = new Dictionary <string, string> {
                { "Set-Cookie", ValidFakeCookie }
            };
            MockHttpDataSource source = new MockHttpDataSource();

            client       = new TogglClient(FakeToken, source);
            statusKeeper = new ToggleClientStatusKeeper(client);

            source.SetResponse(SessionUrl, "POST", new MockHttpResponse <TogglEntry[]>()
            {
                FakeHeaders = headers
            });

            client.LogIn();

            Assert.IsTrue(statusKeeper.IsLoggedIn);
            return(source);
        }
Пример #5
0
        private static ToggleClientStatusKeeper LogInLogOutWithStatus(HttpStatusCode statusCode)
        {
            Dictionary <string, string> headers = new Dictionary <string, string> {
                { "Set-Cookie", ValidFakeCookie }
            };
            MockHttpDataSource       source       = new MockHttpDataSource();
            TogglClient              client       = new TogglClient(FakeToken, source);
            ToggleClientStatusKeeper statusKeeper = new ToggleClientStatusKeeper(client);

            source.SetResponse(SessionUrl, "POST", new MockHttpResponse <TogglEntry[]>()
            {
                FakeHeaders = headers
            });
            source.SetResponse(SessionUrl, "DELETE", new MockHttpResponse <TogglEntry[]>()
            {
                FakeStatusCode = statusCode
            });
            client.LogIn();
            client.LogOut();
            return(statusKeeper);
        }
Пример #6
0
        public void Logout_DataSourceTimeoutFailsLogout()
        {
            Dictionary <string, string> headers = new Dictionary <string, string> {
                { "Set-Cookie", ValidFakeCookie }
            };
            MockHttpDataSource       source       = new MockHttpDataSource();
            TogglClient              client       = new TogglClient(FakeToken, source);
            ToggleClientStatusKeeper statusKeeper = new ToggleClientStatusKeeper(client);

            source.SetResponse(SessionUrl, "POST", new MockHttpResponse <TogglEntry[]>()
            {
                FakeHeaders = headers
            });
            source.SetException(SessionUrl, "DELETE", new WebException("Timeout", WebExceptionStatus.Timeout));

            client.LogIn();
            client.LogOut();

            Assert.True(statusKeeper.IsLoggedIn);
            Assert.IsFalse(statusKeeper.LogoutSucceeded);
            Assert.IsTrue(statusKeeper.LogoutFailed);
            Assert.IsTrue(statusKeeper.EncounteredError);
        }