atlassian.net-sdk-v2.0 /Atlassian.Jira.Test/JiraTests.cs

Language C# Lines 138
MD5 Hash ca2cbb3bcd285b5b8aa4131ed4b890b0 Estimated Cost $2,865 (why?)
Repository https://bitbucket.org/yyo/atlassian.net-sdk-v2.0.git View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xunit;
using Moq;
using System.ServiceModel;
using Atlassian.Jira.Remote;

namespace Atlassian.Jira.Test
{
    public class JiraTests
    {
        public class GetIssuesFromFilter
        {
            [Fact]
            public void IfFilterNotFoundShouldThrowException()
            {
                var jira = TestableJira.Create();

                Assert.Throws(typeof(InvalidOperationException), () => jira.GetIssuesFromFilter("foo"));
            }

            [Fact]
            public void RetrievesFilterIdFromServer()
            {
                var jira = TestableJira.Create();
                jira.SoapService.Setup(s => s.GetFavouriteFilters(It.IsAny<string>()))
                                             .Returns(new RemoteFilter[1] { new RemoteFilter() { name="thefilter", id="123"}});
                jira.GetIssuesFromFilter("thefilter", 100, 200);

                jira.SoapService.Verify(s => s.GetIssuesFromFilterWithLimit(It.IsAny<string>(), "123", 100, 200));
            }

            [Fact]
            public void UsesDefaultsIfNoneProvided()
            {
                var jira = TestableJira.Create();
                jira.SoapService.Setup(s => s.GetFavouriteFilters(It.IsAny<string>()))
                                             .Returns(new RemoteFilter[1] { new RemoteFilter() { name = "thefilter", id = "123" } });
                jira.GetIssuesFromFilter("thefilter");

                jira.SoapService.Verify(s => s.GetIssuesFromFilterWithLimit(It.IsAny<string>(), "123", 0, 20));
            }
        }

        public class WithToken_Anonymous
        {
            [Fact]
            public void DoesNotRetrieveToken()
            {
                var jira = TestableJira.Create(user: null, pass: null);
                jira.SoapService.Setup(s => s.Login(It.IsAny<string>(), It.IsAny<string>())).Throws(new Exception("Unexpected call to login"));

                string innerToken = null;
                jira.WithToken(t => innerToken = t);
                Assert.Equal(String.Empty, innerToken);
            }

            [Fact]
            public void DoesNotRetrieveTokenIfMethodThrowsException()
            {
                var jira = TestableJira.Create(user: null, pass: null);
                jira.SoapService.Setup(s => s.Login(It.IsAny<string>(), It.IsAny<string>())).Throws(new Exception("Unexpected call to login"));

                string innerToken = null;
                 Assert.Throws(typeof(InvalidOperationException), () =>
                    jira.WithToken(t =>
                    {
                        innerToken = t;
                        throw new InvalidOperationException();
                    }));
                jira.WithToken(t => innerToken = t);
                Assert.Equal(String.Empty, innerToken);
            }
        }

        public class WithToken_UserAndPassword
        {
            [Fact]
            public void RetrievesTokenIfEmpty()
            {
                var jira = TestableJira.Create();
                jira.SoapService.Setup(s => s.Login(It.IsAny<string>(), It.IsAny<string>())).Returns("token");

                string innerToken = "";
                jira.WithToken(t => innerToken = t);
                Assert.Equal("token", innerToken);
            }

            [Fact]
            public void ReusesTokenIfNotEmpty()
            {
                var jira = TestableJira.Create();
                jira.SoapService.Setup(s => s.Login(It.IsAny<string>(), It.IsAny<string>())).ReturnsInOrder("token", new Exception("Unexpected call to login"));

                string innerToken = "";
                jira.WithToken(t => innerToken = t);
                jira.WithToken(t => innerToken = t);
                Assert.Equal("token", innerToken);
            }

            [Fact]
            public void RetrievesNewTokenIfMethodThrowsAuthException()
            {
                var jira = TestableJira.Create();
                jira.SoapService.Setup(s => s.Login(It.IsAny<string>(), It.IsAny<string>())).ReturnsInOrder("token1", "token2");

                string innerToken = "";
                jira.WithToken(t => innerToken = t); // retrieves original token
                jira.WithToken(t =>
                {
                    if (t == "token1")
                        throw new FaultException("com.atlassian.jira.rpc.exception.RemoteAuthenticationException: Invalid username or password.");
                    innerToken = t;
                });
                Assert.Equal("token2", innerToken);
            }

            [Fact]
            public void DoesNotRetrieveNewTokenIfMethodThrowsNonAuthException()
            {
                var jira = TestableJira.Create();
                jira.SoapService.Setup(s => s.Login(It.IsAny<string>(), It.IsAny<string>())).ReturnsInOrder("token1", new Exception("Unexpected call to login"));

                string innerToken = "";
                jira.WithToken(t => innerToken = t);

                Assert.Throws(typeof(InvalidOperationException), () =>
                    jira.WithToken(t =>
                    {
                        throw new InvalidOperationException();
                    }));
            }
        }
    }
}
Back to Top