public async Task GetJiraWorkspaceEpicDetailsAsync_ResultsFound_ReturnsListOfSchemaDatabaseModels()
        {
            // Arrange
            var queryModel  = new JiraWorkspaceQueryModel();
            var resultModel = new JiraWorkspaceResultMasterModel
            {
                Issues = new List <JiraWorkspaceResultModel>
                {
                    new JiraWorkspaceResultModel
                    {
                        ApiCustomFields = new Dictionary <JiraApiCustomFieldTypeEnum, string>
                        {
                            { JiraApiCustomFieldTypeEnum.IR_JIRACUSTOMFIELDREF1, "IR_JIRACUSTOMFIELDREF1" }
                        }
                    }
                }
            };

            _jiraAccess.Setup(x => x.GetJiraWorkspaceEpicDetailsAsync(It.IsAny <JiraWorkspaceQueryModel>()))
            .ReturnsAsync(resultModel);

            // Act
            JiraController controller = new JiraController(_jiraAccess.Object);
            var            result     = await controller.GetJiraWorkspaceEpicDetailsAsync(queryModel);

            // Assert
            var resultValue = result.Value as ApiOkResponse;

            resultValue.Result.Should().BeOfType <JiraWorkspaceResultMasterModel>();
            (resultValue.Result.As <JiraWorkspaceResultMasterModel>()).Issues.First().ApiCustomFields.Should().HaveCount(1);
        }
        public async Task GetJiraWorkspaceDetailsAsync_AccessMethodThrowsError_LogErrorEventOccursAndErrorStatusCodeReturnedNoExceptionThrown()
        {
            // Arrange
            var queryModel       = new JiraWorkspaceQueryModel();
            var exceptionToThrow = new Exception("exception");

            _jiraAccess.Setup(x => x.GetJiraWorkspaceDetailsAsync(It.IsAny <JiraWorkspaceQueryModel>()))
            .ThrowsAsync(exceptionToThrow);

            JiraController controller = new JiraController(_jiraAccess.Object);

            // Set up our Error Handling middleware as a wrapper (the same way it will wrap all incoming Requests)
            var middleware = new ErrorWrappingMiddleware(async(innerHttpContext) =>
            {
                var result = await controller.GetJiraWorkspaceDetailsAsync(queryModel);
            }, _logger.Object);

            var context = new DefaultHttpContext();

            context.Response.Body = new MemoryStream();

            //Act
            await middleware.Invoke(context);

            context.Response.Body.Seek(0, SeekOrigin.Begin);
            var reader      = new StreamReader(context.Response.Body);
            var streamText  = reader.ReadToEnd();
            var objResponse = JsonConvert.DeserializeObject <ApiResponse>(streamText);

            //Assert
            _logger.Verify(x =>
                           x.LogError(exceptionToThrow, It.IsAny <string>()), Times.Once);

            objResponse
            .Should()
            .BeEquivalentTo(new ApiResponse(HttpStatusCode.InternalServerError, "exception"));

            context.Response.StatusCode
            .Should()
            .Be((int)HttpStatusCode.InternalServerError);
        }
Ejemplo n.º 3
0
        public void CreateAndCommentJiraTicket()
        {
            string loc      = Assembly.GetExecutingAssembly().Location;
            string location = Path.GetDirectoryName(loc);

            ConfigController cfg = new ConfigController(location);

            if (cfg.LoadConfig())
            {
                JiraController jc = jc = new JiraController(
                    cfg.Get("Jira", "User", "Unknow"),
                    cfg.Get("Jira", "Pwd", "???"),
                    cfg.Get("Jira", "Url", "https://localhost/"),
                    cfg.Get("Jira", "Assignee", string.Empty)
                    );
                JiraResponce responce = jc.CreateTicket("ICR", "Critical", "The test title", "The test Body", JiraIssueTypeConst.Bug);
                Assert.IsNotNull(responce.id);
                responce = jc.AddComment(responce.key, "Test add comment to created ticket");
                Assert.IsNotNull(responce.id);
            }
        }
        private async Task ResumeAfterIncidentCommentFormDialog(IDialogContext context, IAwaitable <AddIncidentCommentQuery> result)
        {
            try
            {
                AddIncidentCommentQuery query = await result;
                if (query.TicketId == null)
                {
                    query.TicketId = ticketNumber.Entity;
                }

                JiraController jc      = new JiraController();
                bool           isAdded = jc.AddComment(query, query.TicketId.Replace(" ", ""));

                string message = isAdded ? "Comment added successfully to incident " + query.TicketId.Replace(" ", "") + "." : "There was an error while adding your worklog item. Please contact your administrator";

                await context.PostAsync(message);
            }
            catch (FormCanceledException ex)
            {
                string reply;

                if (ex.InnerException == null)
                {
                    reply = "You have canceled the operation.";
                }
                else
                {
                    reply = $"Oops! Something went wrong :( Technical Details: {ex.InnerException.Message}";
                }

                await context.PostAsync(reply);
            }
            finally
            {
                context.Done <object>(null);
            }
        }
Ejemplo n.º 5
0
        private async Task ResumeAfterChooseGetTicket(IDialogContext context, IAwaitable <string> choice)
        {
            try
            {
                JiraController jira = new JiraController();

                if (await choice == LuisBot.Enums.Support.GetTicketOptions.GetLastComment.GetStringValue())
                {
                    JiraGetCommentModel ticket = jira.GetLastTicketComment(ticketnumber);
                    await context.PostAsync(ticket.body);
                }
                else if (await choice == LuisBot.Enums.Support.GetTicketOptions.GetUrl.GetStringValue())
                {
                    JiraGetCommentModel ticket = jira.GetLastTicketComment(ticketnumber);
                    await context.PostAsync(ticket.self);
                }
                else if (await choice == LuisBot.Enums.Support.GetTicketOptions.GetResolution.GetStringValue())
                {
                    JiraGetResolutionModel ticket = jira.GetTicketResolution(ticketnumber);
                    await context.PostAsync($"The resolution of your ticket is: {ticket.resolution}.");
                }
                else if (await choice == LuisBot.Enums.Support.GetTicketOptions.GetStatus.GetStringValue())
                {
                    JiraGetStatusModel ticket = jira.GetTicketStatus(ticketnumber);
                    await context.PostAsync($"Your status ticket is: {ticket.status}.");
                }
            }
            catch (Exception ex)
            {
                await context.PostAsync($"There was an error. Please contact your administrator. - {ex.Message}");
            }
            finally
            {
                PromptDialog.Confirm(context, this.CallChooseTicketAgain, "Do you want to know anything else about this ticket?");
                //context.Done<object>(null);
            }
        }
Ejemplo n.º 6
0
        private void InitializeJiraTaskList()
        {
            // Add columns
            var gridView = new GridView();

            jiraTaskList.View = gridView;
            var width = this.Width - 100;

            gridView.Columns.Add(new GridViewColumn
            {
                Header = "Task To Follow",
                DisplayMemberBinding = new Binding("DevTask"),
                Width = width * .15
            });
            gridView.Columns.Add(new GridViewColumn
            {
                Header = "My Task",
                DisplayMemberBinding = new Binding("MyTask"),
                Width = width * .15
            });
            gridView.Columns.Add(new GridViewColumn
            {
                Header = "Status",
                Width  = width * .1,
                DisplayMemberBinding = new Binding("Status")
            });
            gridView.Columns.Add(new GridViewColumn
            {
                Header       = "Name",
                CellTemplate = GetDataTemplate("TaskName"),
                Width        = width * .25
                               //DisplayMemberBinding = new Binding("TaskName")
            });
            gridView.Columns.Add(new GridViewColumn
            {
                Header       = "Description",
                CellTemplate = GetDataTemplate("TaskDescription"),
                Width        = width * .35
                               //new TextBlock() { TextWrapping = TextWrapping.Wrap })
            });

            // Populate list
            jc = new JiraController();
            jiraTaskList.ItemsSource = //jc.ParseJiraTasks();
                                       new List <JiraIssue>()
            {
                new JiraIssue {
                    DevTask = "XWESVC-123", MyTask = "XWESVC-124", Status = "Test", TaskDescription = "Stuff", TaskName = "Things"
                },
                new JiraIssue
                {
                    DevTask         = "XWESVC-955",
                    MyTask          = "XWESVC-322",
                    Status          = "Beta",
                    TaskDescription = "Here will be a ridiculously long task description just for fun and we shall see how it works and if it word wraps and such and things and stuff and yeah..................You should do things Here will be a ridiculously long task description just for fun and we shall see how it works and if it word wraps and such and things and stuff and yeah..................You should do things Here will be a ridiculously long task description just for fun and we shall see how it works and if it word wraps and such and things and stuff and yeah..................You should do things Here will be a ridiculously long task description just for fun and we shall see how it works and if it word wraps and such and things and stuff and yeah..................You should do things Here will be a ridiculously long task description just for fun and we shall see how it works and if it word wraps and such and things and stuff and yeah..................You should do things Here will be a ridiculously long task description just for fun and we shall see how it works and if it word wraps and such and things and stuff and yeah..................You should do things Here will be a ridiculously long task description just for fun and we shall see how it works and if it word wraps and such and things and stuff and yeah..................You should do things",
                    TaskName        = "Here is a very long task name that is hopefully longer than the default size for this particular column"
                }
            };
            //var thingie = jiraTaskList.Items[0] as ListViewItem;
            //jiraTaskList.Style = new Style()
            //{
            //    Triggers =
            //    {
            //        new DataTrigger {Setters = {new Setter(BackgroundProperty, Brushes.Aqua)}, Value = "Test"}
            //    },
            //    Resources = new ResourceDictionary()
            //};
        }
Ejemplo n.º 7
0
 public MainWindow()
 {
     jc = new JiraController();
     InitializeComponent();
     InitializeJiraTaskList();
 }
Ejemplo n.º 8
0
        public async Task Jira(IDialogContext context, LuisResult result)
        {
            EntityRecommendation ticketNumber;

            EntityRecommendation actionRequested;

            result.TryFindEntity("JiraTicketActionRequested", out actionRequested);

            EntityRecommendation projectRequested;

            result.TryFindEntity("JiraProjectRequested", out projectRequested);

            EntityRecommendation actionDate;

            result.TryFindEntity("JiraActionDate", out actionDate);

            JiraController jc = new JiraController();

            if (actionRequested != null)
            {
                if ((actionRequested.Entity.ToUpper().Equals("UPDATE") || actionRequested.Entity.ToUpper().Equals("COMMENT")))
                {
                    if (result.TryFindEntity("JiraTicketNumber", out ticketNumber))
                    {
                        ticketNumber.Type = "TicketId";
                    }

                    if (ticketNumber != null)
                    {
                        //JiraGetCommentModel jcm = jc.GetLastTicketComment(ticketNumber.Entity.Replace(" ", ""));

                        //await context.PostAsync("Last comment was made by " + jcm.author.displayName + " on " + Convert.ToDateTime(jcm.created).ToString("dd/MM/yyyy HH:mm:ss") + ": " + jcm.body);
                    }
                    else
                    {
                        await context.PostAsync("Please provide a ticket number. Example: 'What is the last update on ticket TAR-282?'");
                    }
                }
                else if ((actionRequested.Entity.ToUpper().Equals("GET") || actionRequested.Entity.ToUpper().Equals("RETURN") || actionRequested.Entity.ToUpper().Equals("HOW MANY TICKETS") || actionRequested.Entity.ToUpper().Equals("HOW MANY INCIDENTS")) &&
                         projectRequested != null && projectRequested.Entity != null)
                {
                    string dateFrom = actionDate != null ? actionDate.Entity : null;

                    string count = jc.GetProjectTicketCount(projectRequested.Entity, dateFrom);

                    await context.PostAsync(count);
                }
                else if (actionRequested.Entity.ToUpper().Equals("ADD WORKLOG"))
                {
                    if (result.TryFindEntity("JiraTicketNumber", out ticketNumber))
                    {
                        ticketNumber.Type = "TicketId";
                    }

                    context.Call(new AddIncidentWorklogDialog(ticketNumber), this.ResumeAfterDialog);
                }
                else if (actionRequested.Entity.ToUpper().Contains("ADD") && actionRequested.Entity.ToUpper().Contains("COMMENT"))
                {
                    if (result.TryFindEntity("JiraTicketNumber", out ticketNumber))
                    {
                        ticketNumber.Type = "TicketId";
                    }

                    context.Call(new AddIncidentCommentDialog(ticketNumber), this.ResumeAfterDialog);
                }
            }
        }