forked from microsoft/vstest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFilePatternParserTests.cs
More file actions
136 lines (112 loc) · 6.8 KB
/
FilePatternParserTests.cs
File metadata and controls
136 lines (112 loc) · 6.8 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using Microsoft.Extensions.FileSystemGlobbing;
using Microsoft.Extensions.FileSystemGlobbing.Abstractions;
using Microsoft.VisualStudio.TestPlatform.CommandLine;
using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using vstest.console.Internal;
namespace vstest.console.UnitTests.Internal;
[TestClass]
public class FilePatternParserTests
{
private readonly FilePatternParser _filePatternParser;
private readonly Mock<Matcher> _mockMatcherHelper;
private readonly Mock<IFileHelper> _mockFileHelper;
public FilePatternParserTests()
{
_mockMatcherHelper = new Mock<Matcher>();
_mockFileHelper = new Mock<IFileHelper>();
_filePatternParser = new FilePatternParser(_mockMatcherHelper.Object, _mockFileHelper.Object);
}
[TestMethod]
public void FilePatternParserShouldCorrectlySplitPatternAndDirectory()
{
var patternMatchingResult = new PatternMatchingResult(new List<FilePatternMatch>());
_mockMatcherHelper.Setup(x => x.Execute(It.IsAny<DirectoryInfoWrapper>())).Returns(patternMatchingResult);
_filePatternParser.GetMatchingFiles(TranslatePath(@"C:\Users\vanidhi\Desktop\a\c\*bc.dll"));
// Assert
_mockMatcherHelper.Verify(x => x.AddInclude(TranslatePath(@"*bc.dll")));
_mockMatcherHelper.Verify(x => x.Execute(It.Is<DirectoryInfoWrapper>(y => y.FullName.Equals(TranslatePath(@"C:\Users\vanidhi\Desktop\a\c")))));
}
[TestMethod]
public void FilePatternParserShouldCorrectlySplitPatternAndDirectoryWithAlternateSeparator()
{
var patternMatchingResult = new PatternMatchingResult(new List<FilePatternMatch>());
_mockMatcherHelper.Setup(x => x.Execute(It.IsAny<DirectoryInfoWrapper>())).Returns(patternMatchingResult);
_filePatternParser.GetMatchingFiles(TranslatePath(@"C:/Users/vanidhi/Desktop/a/c/*bc.dll"));
// Assert
_mockMatcherHelper.Verify(x => x.AddInclude(TranslatePath(@"*bc.dll")));
_mockMatcherHelper.Verify(x => x.Execute(It.Is<DirectoryInfoWrapper>(y => y.FullName.Equals(TranslatePath(@"C:\Users\vanidhi\Desktop\a\c")))));
}
[TestMethod]
public void FilePatternParserShouldCorrectlySplitWithArbitraryDirectoryDepth()
{
var patternMatchingResult = new PatternMatchingResult(new List<FilePatternMatch>());
_mockMatcherHelper.Setup(x => x.Execute(It.IsAny<DirectoryInfoWrapper>())).Returns(patternMatchingResult);
_filePatternParser.GetMatchingFiles(TranslatePath(@"C:\Users\vanidhi\**\c\*bc.txt"));
// Assert
_mockMatcherHelper.Verify(x => x.AddInclude(TranslatePath(@"**\c\*bc.txt")));
_mockMatcherHelper.Verify(x => x.Execute(It.Is<DirectoryInfoWrapper>(y => y.FullName.Equals(TranslatePath(@"C:\Users\vanidhi")))));
}
[TestMethod]
public void FilePatternParserShouldCorrectlySplitWithWildCardInMultipleDirectory()
{
var patternMatchingResult = new PatternMatchingResult(new List<FilePatternMatch>());
_mockMatcherHelper.Setup(x => x.Execute(It.IsAny<DirectoryInfoWrapper>())).Returns(patternMatchingResult);
_filePatternParser.GetMatchingFiles(TranslatePath(@"E:\path\to\project\tests\**.Tests\**\*.Tests.dll"));
// Assert
_mockMatcherHelper.Verify(x => x.AddInclude(TranslatePath(@"**.Tests\**\*.Tests.dll")));
_mockMatcherHelper.Verify(x => x.Execute(It.Is<DirectoryInfoWrapper>(y => y.FullName.Equals(TranslatePath(@"E:\path\to\project\tests")))));
}
[TestMethod]
public void FilePatternParserShouldCorrectlySplitWithMultipleWildCardInPattern()
{
var patternMatchingResult = new PatternMatchingResult(new List<FilePatternMatch>());
_mockMatcherHelper.Setup(x => x.Execute(It.IsAny<DirectoryInfoWrapper>())).Returns(patternMatchingResult);
_filePatternParser.GetMatchingFiles(TranslatePath(@"E:\path\to\project\tests\Tests*.Blame*.dll"));
// Assert
_mockMatcherHelper.Verify(x => x.AddInclude(TranslatePath(@"Tests*.Blame*.dll")));
_mockMatcherHelper.Verify(x => x.Execute(It.Is<DirectoryInfoWrapper>(y => y.FullName.Equals(TranslatePath(@"E:\path\to\project\tests")))));
}
[TestMethod]
public void FilePatternParserShouldCorrectlySplitWithMultipleWildCardInMultipleDirectory()
{
var patternMatchingResult = new PatternMatchingResult(new List<FilePatternMatch>());
_mockMatcherHelper.Setup(x => x.Execute(It.IsAny<DirectoryInfoWrapper>())).Returns(patternMatchingResult);
_filePatternParser.GetMatchingFiles(TranslatePath(@"E:\path\to\project\*tests\Tests*.Blame*.dll"));
// Assert
_mockMatcherHelper.Verify(x => x.AddInclude(TranslatePath(@"*tests\Tests*.Blame*.dll")));
_mockMatcherHelper.Verify(x => x.Execute(It.Is<DirectoryInfoWrapper>(y => y.FullName.Equals(TranslatePath(@"E:\path\to\project")))));
}
[TestMethod]
public void FilePatternParserShouldCheckIfFileExistsIfFullPathGiven()
{
var patternMatchingResult = new PatternMatchingResult(new List<FilePatternMatch>());
_mockFileHelper.Setup(x => x.Exists(TranslatePath(@"E:\path\to\project\tests\Blame.Tests\\abc.Tests.dll"))).Returns(true);
_mockMatcherHelper.Setup(x => x.Execute(It.IsAny<DirectoryInfoWrapper>())).Returns(patternMatchingResult);
var matchingFiles = _filePatternParser.GetMatchingFiles(TranslatePath(@"E:\path\to\project\tests\Blame.Tests\\abc.Tests.dll"));
// Assert
_mockFileHelper.Verify(x => x.Exists(TranslatePath(@"E:\path\to\project\tests\Blame.Tests\\abc.Tests.dll")));
Assert.IsTrue(matchingFiles.Contains(TranslatePath(@"E:\path\to\project\tests\Blame.Tests\\abc.Tests.dll")));
}
[TestMethod]
public void FilePatternParserShouldThrowCommandLineExceptionIfFileDoesNotExist()
{
var patternMatchingResult = new PatternMatchingResult(new List<FilePatternMatch>());
_mockFileHelper.Setup(x => x.Exists(TranslatePath(@"E:\path\to\project\tests\Blame.Tests\\abc.Tests.dll"))).Returns(false);
_mockMatcherHelper.Setup(x => x.Execute(It.IsAny<DirectoryInfoWrapper>())).Returns(patternMatchingResult);
Assert.ThrowsException<TestSourceException>(() => _filePatternParser.GetMatchingFiles(TranslatePath(@"E:\path\to\project\tests\Blame.Tests\\abc.Tests.dll")));
}
private static string TranslatePath(string path)
{
// RuntimeInformation has conflict when used
return Environment.OSVersion.Platform.ToString().StartsWith("Win")
? path
: Regex.Replace(path.Replace("\\", "/"), @"(\w)\:/", @"/mnt/$1/");
}
}