Address comments · microsoft/VSConfigFinder@3b9130f (original) (raw)

`@@ -5,6 +5,9 @@

`

5

5

``

6

6

`namespace VSConfigFinder.Test

`

7

7

`{

`

``

8

`+

using Moq;

`

``

9

`+

using System.Text;

`

``

10

`+

using System.Text.Json;

`

8

11

`using Xunit;

`

9

12

``

10

13

`public class UtilitiesTests

`

`@@ -25,5 +28,97 @@ public void ValidateIsNotNullOrEmpty_NotNullOrEmpty_String_Succeeds()

`

25

28

`var str = "some string";

`

26

29

`Utilities.ValidateIsNotNullOrEmpty(str, nameof(str));

`

27

30

`}

`

``

31

+

``

32

`+

[Fact]

`

``

33

`+

public void CreateOutput_Creates_File_With_Expected_String()

`

``

34

`+

{

`

``

35

`+

var fileSystem = new Mock();

`

``

36

`+

var finalConfig = new VSConfig

`

``

37

`+

{

`

``

38

`+

Version = new Version("1.0"),

`

``

39

`+

Components = new[]

`

``

40

`+

{

`

``

41

`+

"Microsoft.VisualStudio.Component.NuGet",

`

``

42

`+

"Microsoft.VisualStudio.Component.Roslyn.Compiler",

`

``

43

`+

"Microsoft.Component.MSBuild",

`

``

44

`+

"Microsoft.NetCore.Component.Runtime.6.0"

`

``

45

`+

},

`

``

46

`+

};

`

``

47

+

``

48

`+

var jsonString = """

`

``

49

`+

{

`

``

50

`+

"Version": "1.0",

`

``

51

`+

"Components": [

`

``

52

`+

"Microsoft.VisualStudio.Component.NuGet",

`

``

53

`+

"Microsoft.VisualStudio.Component.Roslyn.Compiler",

`

``

54

`+

"Microsoft.Component.MSBuild",

`

``

55

`+

"Microsoft.NetCore.Component.Runtime.6.0"

`

``

56

`+

]

`

``

57

`+

}

`

``

58

`+

""";

`

``

59

+

``

60

`+

var options = new CommandLineOptions

`

``

61

`+

{

`

``

62

`+

FolderPath = "C:\input",

`

``

63

`+

CreateFile = true,

`

``

64

`+

ConfigOutputPath = "C:\output",

`

``

65

`+

};

`

``

66

+

``

67

`+

Utilities.CreateOutput(fileSystem.Object, finalConfig, options);

`

``

68

+

``

69

`+

var outputPath = Path.Combine(options.ConfigOutputPath, ".vsconfig");

`

``

70

`+

fileSystem.Verify(x => x.WriteAllText(outputPath, jsonString));

`

``

71

`+

}

`

``

72

+

``

73

`+

[Fact]

`

``

74

`+

public void ReadComponents_Reads_AllNestedDirectories_And_OutputsAllComponents()

`

``

75

`+

{

`

``

76

`+

var fileSystem = new Mock();

`

``

77

+

``

78

`+

var options = new CommandLineOptions

`

``

79

`+

{

`

``

80

`+

FolderPath = "C:\input",

`

``

81

`+

ConfigOutputPath = "C:\output",

`

``

82

`+

};

`

``

83

+

``

84

`+

// pathA

`

``

85

`+

var pathA = "C:\pathA";

`

``

86

`+

var pathAConfig = """

`

``

87

`+

{

`

``

88

`+

"Version": "1.0",

`

``

89

`+

"Components": [

`

``

90

`+

"Microsoft.VisualStudio.Component.NuGet",

`

``

91

`+

"Microsoft.Component.MSBuild",

`

``

92

`+

]

`

``

93

`+

}

`

``

94

`+

""";

`

``

95

`+

var pathAReader = new MemoryStream(Encoding.UTF8.GetBytes(pathAConfig));

`

``

96

+

``

97

`+

// pathB

`

``

98

`+

var pathB = "C:\pathB";

`

``

99

`+

var pathBConfig = """

`

``

100

`+

{

`

``

101

`+

"Version": "1.0",

`

``

102

`+

"Components": [

`

``

103

`+

"Microsoft.VisualStudio.Component.NuGet",

`

``

104

`+

"Microsoft.VisualStudio.Component.Roslyn.Compiler",

`

``

105

`+

]

`

``

106

`+

}

`

``

107

`+

""";

`

``

108

`+

var pathBReader = new MemoryStream(Encoding.UTF8.GetBytes(pathBConfig));

`

``

109

+

``

110

`+

fileSystem.Setup(x => x.GetFileSystemEntries(options.FolderPath, ".vsconfig", true)).Returns(new[] { pathA, pathB });

`

``

111

+

``

112

`+

fileSystem.Setup(x => x.OpenFile(pathA)).Returns(pathAReader);

`

``

113

`+

fileSystem.Setup(x => x.OpenFile(pathB)).Returns(pathBReader);

`

``

114

+

``

115

`+

var components = Utilities.ReadComponents(fileSystem.Object, options);

`

``

116

`+

Assert.Equal(3, components.Length);

`

``

117

`+

Assert.Collection(

`

``

118

`+

components,

`

``

119

`+

x => Assert.Equal("Microsoft.VisualStudio.Component.NuGet", x),

`

``

120

`+

x => Assert.Equal("Microsoft.Component.MSBuild", x),

`

``

121

`+

x => Assert.Equal("Microsoft.VisualStudio.Component.Roslyn.Compiler", x));

`

``

122

`+

}

`

28

123

`}

`

29

124

`}

`