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

Language C# Lines 91
MD5 Hash 553941b5417e6a046006536121c1200c Estimated Cost $1,755 (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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xunit;
using Atlassian.Jira.Remote;
using Moq;
using System.Linq.Expressions;
using Atlassian.Jira.Linq;

namespace Atlassian.Jira.Test
{
    public class JqlQueryProviderTest
    {
        private Mock<IJiraRemoteService> _soapClient;
        private Mock<IJqlExpressionVisitor> _visitor;

        private Jira CreateJiraInstance()
        {
            _visitor = new Mock<IJqlExpressionVisitor>();
            _soapClient = new Mock<IJiraRemoteService>();

            _visitor.Setup(t => t.Process(It.IsAny<Expression>())).Returns(new JqlData() { Expression = "dummy expression" });

            return new Jira(_visitor.Object, _soapClient.Object, null, "username", "password");
        }

        [Fact]
        public void Count_WithSoap()
        {
            var jira = CreateJiraInstance();
            _soapClient.Setup(r => r.GetIssuesFromJqlSearch(
                                        It.IsAny<string>(),
                                        It.IsAny<string>(),
                                        It.IsAny<int>())).Returns(new RemoteIssue[1] { new RemoteIssue() });

            Assert.Equal(1, jira.Issues.Count());
        }

        [Fact]
        public void Count_WithRest()
        {
            var jira = CreateJiraInstance();
            _visitor.Setup(t => t.Process(It.IsAny<Expression>())).Returns(new JqlData() { Expression = "dummy expression", ProcessCount = true  });
            jira.UseRestApi = true;
            _soapClient.Setup(r => r.GetIssueCountFromJqlSearch(It.IsAny<string>())).Returns(20);
            
            Assert.Equal(20, jira.Issues.Count());
        }

        [Fact]
        public void Skip_WithRest()
        {
            var jira = CreateJiraInstance();
            _visitor.Setup(t => t.Process(It.IsAny<Expression>())).Returns(new JqlData() { Expression = "dummy expression", StartAt = 1, MaxResults = 1 });
            _soapClient.Setup(s => s.GetJsonFromJqlSearch(It.IsAny<string>(), 1, 1, null)).Returns("{issues:[]}");

            jira.UseRestApi = true;

            jira.Issues.Skip(1).FirstOrDefault();

            _soapClient.Verify(s => s.GetJsonFromJqlSearch(It.IsAny<string>(), 1, 1, null));
        }

        [Fact]
        public void Skip_WithSoap_ShouldThrowException()
        {
            var jira = CreateJiraInstance();
            _visitor.Setup(t => t.Process(It.IsAny<Expression>())).Returns(new JqlData() { Expression = "dummy expression", StartAt = 1 });

            Assert.Throws(typeof(InvalidOperationException), () => jira.Issues.Skip(1).FirstOrDefault());
        }

        [Fact]
        public void First()
        {
            var jira = CreateJiraInstance();
            _soapClient.Setup(r => r.GetIssuesFromJqlSearch(
                                        It.IsAny<string>(),
                                        It.IsAny<string>(),
                                        It.IsAny<int>())).Returns(new RemoteIssue[] 
                                        { 
                                            new RemoteIssue() { summary = "foo"}, 
                                            new RemoteIssue() 
                                        });

            Assert.Equal("foo", jira.Issues.First().Summary);
        }
    }
}
Back to Top