public static int CalculateLeanKitPriority(GitHubPulls.Pull issue)
        {
            const int lkPriority = 1;             // default to 1 - Normal

            // LK Priority: 0 = Low, 1 = Normal, 2 = High, 3 = Critical
            // else just set it to default of Normal
            return(lkPriority);
        }
        public static long?CalculateLeanKitAssignedUserId(long boardId, GitHubPulls.Pull pull, ILeanKitApi leanKit)
        {
            if (pull == null)
            {
                return(null);
            }

            if (pull.Base != null && pull.Base.User != null && !string.IsNullOrEmpty(pull.Base.User.Login))
            {
                var lkUser = leanKit.GetBoard(boardId).BoardUsers.FirstOrDefault(x => x != null &&
                                                                                 (((!string.IsNullOrEmpty(x.EmailAddress)) && x.EmailAddress.ToLowerInvariant() == pull.Base.User.Login.ToLowerInvariant()) ||
                                                                                  ((!string.IsNullOrEmpty(x.FullName)) && x.FullName.ToLowerInvariant() == pull.Base.User.Login.ToLowerInvariant()) ||
                                                                                  ((!string.IsNullOrEmpty(x.UserName)) && x.UserName.ToLowerInvariant() == pull.Base.User.Login.ToLowerInvariant())));
                if (lkUser != null)
                {
                    return(lkUser.Id);
                }
            }

            return(null);
        }
		protected override void OnArrange()
		{
			base.OnArrange();

			MockLeanKitApi.Setup(x => x.GetBoard(It.IsAny<long>())).Returns(_testBoard);

			var serializer = new JsonSerializer<List<GitHubPulls.Pull>>();

			var pull1 = new GitHubPulls.Pull()
			{
				Id = 1,
				Number = 1,
				State = "Open",
				Body = "New Pull 1",
				Title = "New Pull 1"
			};

			var pull2 = new GitHubPulls.Pull()
			{
				Id = 2,
				Number = 2,
				State = "Open",
				Body = "New Pull 2",
				Title = "New Pull 2"
			};

			var pull3 = new GitHubPulls.Pull()
			{
				Id = 3,
				Number = 3,
				State = "Open",
				Body = "New Pull 3",
				Title = "New Pull 3"
			};

			var restResponse1 = new RestResponse()
			{
				Content = serializer.SerializeToString(new List<GitHubPulls.Pull>() {pull1}),
				StatusCode = HttpStatusCode.OK
			};

			MockRestClient.Setup(
				x => x.Execute(It.Is<RestRequest>(y => y.Resource.Contains("/1/pulls") && y.Method == Method.GET)))
				.Returns(restResponse1);
			MockLeanKitApi.Setup(x => x.GetCardByExternalId(1, It.IsAny<string>())).Returns((Card) null);
			MockLeanKitApi.Setup(x => x.AddCard(1, It.IsAny<Card>(), It.IsAny<string>())).Returns(_testCardAddResult1);

			MockRestClient.Setup(
				x => x.Execute(It.Is<RestRequest>(y => y.Resource.Contains("/2/pulls") && y.Method == Method.GET)))
				.Returns(restResponse1);
			MockLeanKitApi.Setup(x => x.GetCardByExternalId(2, It.IsAny<string>())).Returns((Card) null);
			MockLeanKitApi.Setup(x => x.AddCard(2, It.IsAny<Card>(), It.IsAny<string>())).Returns(_testCardAddResult1);

			var restResponse3 = new RestResponse()
			{
				Content = serializer.SerializeToString(new List<GitHubPulls.Pull>() {pull1, pull2, pull3}),
				StatusCode = HttpStatusCode.OK
			};

			MockRestClient.Setup(
				x => x.Execute(It.Is<RestRequest>(y => y.Resource.Contains("/3/pulls") && y.Method == Method.GET)))
				.Returns(restResponse3);
			MockLeanKitApi.Setup(x => x.GetCardByExternalId(3, It.IsAny<string>())).Returns((Card) null);
			MockLeanKitApi.Setup(x => x.AddCard(3, It.IsAny<Card>(), It.IsAny<string>())).Returns(_testCardAddResult1);

			MockRestClient.Setup(
				x => x.Execute(It.Is<RestRequest>(y => y.Resource.Contains("/4/pulls") && y.Method == Method.GET)))
				.Returns(restResponse1);
			MockLeanKitApi.Setup(x => x.GetCardByExternalId(4, It.IsAny<string>()))
				.Returns(new Card() {Id = 4, ExternalSystemName = "GitHub"});
			MockLeanKitApi.Setup(x => x.AddCard(4, It.IsAny<Card>(), It.IsAny<string>())).Returns(_testCardAddResult1);

			MockRestClient.Setup(
				x => x.Execute(It.Is<RestRequest>(y => y.Resource.Contains("/5/pulls") && y.Method == Method.GET)))
				.Returns(restResponse1);
			MockLeanKitApi.Setup(x => x.GetCardByExternalId(5, It.IsAny<string>()))
				.Returns(new Card() {Id = 5, ExternalSystemName = "GitHubber"});
			MockLeanKitApi.Setup(x => x.AddCard(5, It.IsAny<Card>(), It.IsAny<string>())).Returns(_testCardAddResult1);
		}
		protected override void OnArrange()
		{
			base.OnArrange();

			MockLeanKitApi.Setup(x => x.GetBoard(It.IsAny<long>())).Returns(_testBoard);

			var serializer = new JsonSerializer<GitHubPulls.Pull>();

			var pull1 = new GitHubPulls.Pull()
			{
				Id = 1,
				Number = 1,
				State = "Open"
			};

			var restResponse1 = new RestResponse()
			{
				Content = serializer.SerializeToString(pull1),
				StatusCode = HttpStatusCode.OK
			};

			MockRestClient.Setup(
				x => x.Execute(It.Is<RestRequest>(y => y.Resource.Contains("pulls/1") && y.Method == Method.GET)))
				.Returns(restResponse1);
			MockRestClient.Setup(
				x => x.Execute(It.Is<RestRequest>(y => y.Resource.Contains("pulls/1") && y.Method == Method.PATCH)))
				.Returns(restResponse1);

			var pull2 = new GitHubPulls.Pull()
			{
				Id = 2,
				Number = 2,
				State = "Closed"
			};

			var restResponse2 = new RestResponse()
			{
				Content = serializer.SerializeToString(pull2),
				StatusCode = HttpStatusCode.OK
			};

			MockRestClient.Setup(
				x => x.Execute(It.Is<RestRequest>(y => y.Resource.Contains("pulls/2") && y.Method == Method.GET)))
				.Returns(restResponse2);
			MockRestClient.Setup(
				x => x.Execute(It.Is<RestRequest>(y => y.Resource.Contains("pulls/2") && y.Method == Method.PATCH)))
				.Returns(restResponse2);

			var errorSerializer = new JsonSerializer<GitHubPulls.ErrorMessage>();
			var errorResponse = new RestResponse()
			{
				Content = errorSerializer.SerializeToString(new GitHubPulls.ErrorMessage() {Message = "Error"}),
				StatusCode = HttpStatusCode.NotFound
			};

			MockRestClient.Setup(
				x => x.Execute(It.Is<RestRequest>(y => y.Resource.Contains("pulls/3") && y.Method == Method.GET)))
				.Returns(errorResponse);
			MockRestClient.Setup(
				x => x.Execute(It.Is<RestRequest>(y => y.Resource.Contains("pulls/3") && y.Method == Method.PATCH)))
				.Returns(errorResponse);
		}
		protected override void OnArrange()
		{
			base.OnArrange();

			MockLeanKitApi.Setup(x => x.GetBoard(It.IsAny<long>())).Returns(_testBoard);

			var serializer = new JsonSerializer<GitHubPulls.Pull>();

			var pull1 = new GitHubPulls.Pull()
			{
				Id = 1,
				Number = 1,
				Title = "Pull 1",
				Body = "Pull 1",
				State = "Open"
			};

			var restResponse1 = new RestResponse()
			{
				Content = serializer.SerializeToString(pull1),
				StatusCode = HttpStatusCode.OK
			};

			MockRestClient.Setup(
				x => x.Execute(It.Is<RestRequest>(y => y.Resource.Contains("pulls/1") && y.Method == Method.GET)))
				.Returns(restResponse1);
			MockRestClient.Setup(
				x => x.Execute(It.Is<RestRequest>(y => y.Resource.Contains("pulls/1") && y.Method == Method.PATCH)))
				.Returns(restResponse1);

			var pull2 = new GitHubPulls.Pull()
			{
				Id = 2,
				Number = 2,
				Title = "Pull 2",
				Body = "Pull 2",
				State = "Open"
			};

			var restResponse2 = new RestResponse()
			{
				Content = serializer.SerializeToString(pull2),
				StatusCode = HttpStatusCode.OK
			};

			MockRestClient.Setup(
				x => x.Execute(It.Is<RestRequest>(y => y.Resource.Contains("pulls/2") && y.Method == Method.GET)))
				.Returns(restResponse2);
			MockRestClient.Setup(
				x => x.Execute(It.Is<RestRequest>(y => y.Resource.Contains("pulls/2") && y.Method == Method.PATCH)))
				.Returns(restResponse2);

			var pull3 = new GitHubPulls.Pull()
			{
				Id = 3,
				Number = 3,
				Title = "Pull 3",
				Body = "Pull 3",
				State = "Open"
			};

			var restResponse3 = new RestResponse()
			{
				Content = serializer.SerializeToString(pull3),
				StatusCode = HttpStatusCode.OK
			};

			MockRestClient.Setup(
				x => x.Execute(It.Is<RestRequest>(y => y.Resource.Contains("pulls/3") && y.Method == Method.GET)))
				.Returns(restResponse3);
			MockRestClient.Setup(
				x => x.Execute(It.Is<RestRequest>(y => y.Resource.Contains("pulls/3") && y.Method == Method.PATCH)))
				.Returns(restResponse3);

			var pull4 = new GitHubPulls.Pull()
			{
				Id = 4,
				Number = 4,
				Title = "Pull 4",
				Body = "Pull 4",
				State = "Open"
			};

			var restResponse4 = new RestResponse()
			{
				Content = serializer.SerializeToString(pull4),
				StatusCode = HttpStatusCode.OK
			};

			MockRestClient.Setup(
				x => x.Execute(It.Is<RestRequest>(y => y.Resource.Contains("pulls/4") && y.Method == Method.GET)))
				.Returns(restResponse4);
			MockRestClient.Setup(
				x => x.Execute(It.Is<RestRequest>(y => y.Resource.Contains("pulls/4") && y.Method == Method.PATCH)))
				.Returns(restResponse4);
		}
 public static long?LeanKitAssignedUser(this GitHubPulls.Pull pull, long boardId, ILeanKitApi leanKit)
 {
     return(CalculateLeanKitAssignedUserId(boardId, pull, leanKit));
 }
        public static CardType CalculateLeanKitCardType(BoardMapping project, GitHubPulls.Pull pull)
        {
            var defaultCardType = project.ValidCardTypes.FirstOrDefault(x => x.IsDefault);

            return(defaultCardType);
        }
 public static CardType LeanKitCardType(this GitHubPulls.Pull pull, BoardMapping project)
 {
     return(CalculateLeanKitCardType(project, pull));
 }
 public static int LeanKitPriority(this GitHubPulls.Pull pull)
 {
     return(CalculateLeanKitPriority(pull));
 }