Пример #1
0
        public void Minify_Test_Simple()
        {
            const string query    = @"

select *
/*
    This is a list of all the things
    we should be selecting instead of *
    It is also a multiline comment
*/
from Bananas
    inner join Apples
        -- This next bit is not valid syntax
        on stuff


";
            const string expected = @"select *
from Bananas
inner join Apples
on stuff
";
            var          result   = QueryUtilities.Minify(query);

            Assert.AreEqual(expected, result);
        }
Пример #2
0
        public void Preprocess_Keeps_True_Value()
        {
            const string query    = @"
select *
/* Utilitron.If: testFlag */
this text should not be removed
/* Utilitron.EndIf */
from Bananas
";
            const string expected = @"
select *
/* Utilitron.If: testFlag */
this text should not be removed
/* Utilitron.EndIf */
from Bananas
";

            var flags = new Dictionary <string, bool>
            {
                { "testFlag", true },
            };

            var result = QueryUtilities.Preprocess(flags, query);

            Assert.AreEqual(expected, result);
        }
Пример #3
0
        public void Minify_Handles_Unicode_Newline()
        {
            const string query    = "select *\u2028\u2028\u2028from Bananas";
            const string expected = "select *\u2028from Bananas";
            var          result   = QueryUtilities.Minify(query);

            Assert.AreEqual(expected, result);
        }
Пример #4
0
        public void GetEmbeddedQuery_Strips_UTF8_BOM()
        {
            const string expected = "UTF8BOM";

            var utf8Bom = Encoding.UTF8.GetString(Encoding.UTF8.GetPreamble());

            var result = QueryUtilities.GetEmbeddedQuery("Utf8Bom", typeof(RepositoryAncestor));

            Assert.IsFalse(result.StartsWith(utf8Bom, StringComparison.Ordinal));
            Assert.AreEqual(expected, result);
        }
        public void ConvertTreeQueryToQueryHandlesMoreThanOneDisplayField()
        {
            // Arrange
            Mock <ITfsQuery> treeQuery = new Mock <ITfsQuery>();

            treeQuery.Setup(q => q.DisplayFieldList).Returns(TestHelper.CreateMockFieldDefinitions("[System.Id]", "[System.Title]"));

            // Act
            string convertedQueryString = QueryUtilities.ConvertTreeQueryToQueryForItem(treeQuery.Object);

            // Assert
            Assert.AreEqual <string>("SELECT [System.Id], [System.Title] FROM WorkItems", convertedQueryString, "Multiple fields not being handled correctly");
        }
        public void ConvertTreeQueryToQueryForItemConstructsAQueryStringFromWorkItems()
        {
            // Arrange
            // select [System.Id] from WorkItemLinks
            Mock <ITfsQuery> treeQuery = new Mock <ITfsQuery>();

            treeQuery.Setup(q => q.DisplayFieldList).Returns(TestHelper.CreateMockFieldDefinitions("[System.Id]"));

            // Act
            string convertedQueryString = QueryUtilities.ConvertTreeQueryToQueryForItem(treeQuery.Object);

            // Assert
            Assert.AreEqual <string>("SELECT [System.Id] FROM WorkItems", convertedQueryString);
        }
Пример #7
0
        public void Minify_Handles_Nested_Multiline_Comment()
        {
            const string query    = @"
select *
/*
    This is a list of all the things
    we should be selecting instead of *
    It is also a multiline comment
    /*
        This is a multiline comment inside a multiline comment.
    */
*/
from Bananas
";
            const string expected = @"select *
from Bananas
";
            var          result   = QueryUtilities.Minify(query);

            Assert.AreEqual(expected, result);
        }
Пример #8
0
        public void GetEmbeddedQuery_Includes_Included_Queries()
        {
            const string newline = @"
";

            const string expected = @"before first include
/* Utilitron.Include: ./../RepositoryAncestorQueries/IncludeQueryInner.sql */
include query
after first include
before second include
/* Utilitron.Include: /Utilitron/Tests/Data/RepositoryAncestorQueries/IncludeQueryInner.sql */
include query
after second include";

            if (Environment.NewLine != newline)
            {
                Assert.Inconclusive($"Environment.NewLine is not {string.Join(string.Empty, newline.Select(x => ((int) x).ToString("X4")))}.");
            }

            var result = QueryUtilities.GetEmbeddedQuery("IncludeQueryOuter", typeof(RepositoryAncestor));

            Assert.AreEqual(expected, result);
        }
Пример #9
0
        public void Preprocess_Throws_InvlaidOperationException_If_Missing_Flag()
        {
            const string query    = @"
select *
/* Utilitron.If: testFlag */
this text should not be removed
/* Utilitron.EndIf */
from Bananas
";
            const string expected = @"
select *
/* Utilitron.If: testFlag */
this text should not be removed
/* Utilitron.EndIf */
from Bananas
";

            var flags = new Dictionary <string, bool>();

            var result = QueryUtilities.Preprocess(flags, query);

            Assert.AreEqual(expected, result);
        }
 public void ConvertTreeQueryToQueryForItemTestsArgumentForNull()
 {
     TestHelper.TestForArgumentNullException(() => QueryUtilities.ConvertTreeQueryToQueryForItem(null), "query");
 }
Пример #11
0
 public void Minify_Throws_ArgumentNullException_If_Query_Is_Null()
 {
     QueryUtilities.Minify(null);
 }
Пример #12
0
 public void GetEmbeddedQuery_Throws_InvalidOperationException_If_Includes_Become_Recursive()
 {
     QueryUtilities.GetEmbeddedQuery("IncludeQueryRecursive", typeof(RepositoryAncestor));
 }