public void CheckMultilineExpressionEvaluation() { // Setup var package = new Package <BenderMakesUpdateHimself, Issue>() { Items = new[] { new Issue { Key = "T-1" } }, Reaction = new BenderMakesUpdateHimself { UrlPattern = "http://any", BodyPattern = @" ""datetime"":[{ ""<<c#( new System.DateTime(2020, 03, 20) + System.TimeSpan.FromDays( (new System.DateTime(2020, 03, 20)).Hour < 16 ? 0 : System.DateTime.Today.DayOfWeek == System.DayOfWeek.Friday ? 3 : 1 ) ) .ToString(""yyyy-MM-dd"")#>>"" }]" } }; var converter = new IssuePackageConverter(string.Empty); // Experiment var result = converter.ToHttpRequests(new[] { package }); // Check results Assert.AreEqual( @" ""datetime"":[{ ""2020-03-20"" }]", // Expected result.Single().Body // Actual ); }
public void CheckExpressionsEvaluationInUrlAndBody() { // Setup var package = new Package <BenderMakesUpdateHimself, Issue>() { Items = new[] { new Issue { Key = "T-1" } }, Reaction = new BenderMakesUpdateHimself { UrlPattern = "{{@jiraRoot}}/rest/api/<<c# \"{{@jiraRoot}}\".Contains(\"jiraeu\") ? \"2\" : \"1\" #>>/issue/{{@issueKey}}/transitions", BodyPattern = "datetime: \"<<c# new System.DateTime(2019, 03, 18).ToString(\"yyyy-MM-dd\") #>>\"" } }; var converter1 = new IssuePackageConverter("http://jiraeu"); var converter2 = new IssuePackageConverter("http://jira"); // Experiment var result1 = converter1.ToHttpRequests(new[] { package }); var result2 = converter2.ToHttpRequests(new[] { package }); // Check results Assert.AreEqual( "http://jiraeu/rest/api/2/issue/T-1/transitions", // Expected result1.Single().Uri.ToString() // Actual ); Assert.AreEqual( "http://jira/rest/api/1/issue/T-1/transitions", // Expected result2.Single().Uri.ToString() // Actual ); Assert.AreEqual( "datetime: \"2019-03-18\"", // Expected result1.Single().Body // Actual ); }
public void CheckSeveralExpressionsToEvaluateInOneBody() { // Setup var converter = new IssuePackageConverter("https://jira.example.com"); var package = new Package <BenderMakesUpdateHimself, Issue> { // JQL: issueFunction in issueFieldMatch('', labels, 'linkTo=') Items = new[] { new Issue { Key = "BUG-2", Labels = "linkTo=TASK-1", } }, Reaction = new BenderMakesUpdateHimself { UrlPattern = "{{@jiraRoot}}/rest/api/2/issue/{{@issueKey}}", BodyPattern = @" { ""update"": { ""issueLinks"": [ { ""add"": { ""type"": { ""name"": ""Relate"" }, ""outwardIssue"": { ""key"": ""<<c# System.Text.RegularExpressions.Regex.Match(issue.Labels, ""linkTo=(.+-\\d+)"").Groups[1].Value #>>"" } } } ], ""labels"": [ { ""remove"": ""<<c# System.Text.RegularExpressions.Regex.Match(issue.Labels, ""linkTo=.+-\\d+"").Value #>>"" } ] } } " } }; // Experiment var actualRequest = converter.ToHttpRequests(new[] { package }).Single(); // Check results var expectedUrl = "https://jira.example.com/rest/api/2/issue/BUG-2"; var expectedBody = @" { ""update"": { ""issueLinks"": [ { ""add"": { ""type"": { ""name"": ""Relate"" }, ""outwardIssue"": { ""key"": ""TASK-1"" } } } ], ""labels"": [ { ""remove"": ""linkTo=TASK-1"" } ] } } "; Assert.AreEqual(expectedUrl, actualRequest.Uri.ToString()); Assert.AreEqual(expectedBody, actualRequest.Body); }