Skip to content

Commit

Permalink
Merge pull request #5 from microsoft/dev/sknam/create-output
Browse files Browse the repository at this point in the history
Create output from the runner and add unit tests
  • Loading branch information
jlee671 authored Feb 14, 2023
2 parents 3156247 + 4ea06ef commit 63975c5
Show file tree
Hide file tree
Showing 8 changed files with 276 additions and 22 deletions.
142 changes: 142 additions & 0 deletions VSConfigFinder.Test/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
file_header_template = <copyright file="{fileName}" company="Microsoft Corporation">\nCopyright (C) Microsoft Corporation. All rights reserved.\nLicensed under the MIT license. See LICENSE.txt in the project root for license information.\n</copyright>

# All files
[*]
indent_style = space
dotnet_style_operator_placement_when_wrapping = beginning_of_line
tab_width = 4
indent_size = 4
end_of_line = crlf
csharp_indent_labels = one_less_than_current
dotnet_style_coalesce_expression = true:suggestion
dotnet_style_null_propagation = true:suggestion
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
dotnet_style_prefer_auto_properties = true:silent
dotnet_style_object_initializer = true:suggestion
dotnet_style_collection_initializer = true:suggestion
dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
dotnet_style_prefer_conditional_expression_over_assignment = true:silent
csharp_using_directive_placement = inside_namespace:error
csharp_prefer_simple_using_statement = true:suggestion
csharp_prefer_braces = true:silent
csharp_style_namespace_declarations = block_scoped:silent
csharp_style_prefer_method_group_conversion = true:silent
csharp_style_prefer_top_level_statements = true:silent
csharp_style_expression_bodied_methods = false:silent
csharp_style_expression_bodied_constructors = false:silent
csharp_style_expression_bodied_operators = false:silent
csharp_style_expression_bodied_properties = true:silent
csharp_style_expression_bodied_indexers = true:silent
csharp_style_expression_bodied_accessors = true:silent
csharp_style_expression_bodied_lambdas = true:silent
csharp_style_expression_bodied_local_functions = false:silent
csharp_style_allow_embedded_statements_on_same_line_experimental = true:silent
csharp_style_allow_blank_lines_between_consecutive_braces_experimental = true:silent
csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = true:silent
csharp_style_allow_blank_line_after_token_in_conditional_expression_experimental = true:silent
csharp_style_allow_blank_line_after_token_in_arrow_expression_clause_experimental = true:silent
csharp_new_line_before_open_brace = all
csharp_style_throw_expression = true:suggestion
csharp_prefer_simple_default_expression = true:suggestion
csharp_style_prefer_null_check_over_type_check = true:suggestion
csharp_style_prefer_local_over_anonymous_function = true:suggestion
csharp_style_prefer_index_operator = true:suggestion
csharp_style_prefer_range_operator = true:suggestion
csharp_style_implicit_object_creation_when_type_is_apparent = true:suggestion
csharp_style_prefer_tuple_swap = true:suggestion
csharp_style_prefer_utf8_string_literals = true:suggestion
csharp_style_inlined_variable_declaration = true:suggestion
csharp_style_deconstructed_variable_declaration = true:suggestion
csharp_style_unused_value_assignment_preference = discard_variable:suggestion
csharp_style_unused_value_expression_statement_preference = discard_variable:silent
csharp_prefer_static_local_function = true:suggestion
csharp_style_prefer_readonly_struct = true:suggestion
csharp_style_conditional_delegate_call = true:suggestion
csharp_style_prefer_switch_expression = true:suggestion
csharp_style_prefer_pattern_matching = true:silent
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
csharp_style_prefer_not_pattern = true:suggestion
csharp_style_prefer_extended_property_pattern = true:suggestion
csharp_style_var_for_built_in_types = true:silent
csharp_style_var_when_type_is_apparent = true:silent
csharp_style_var_elsewhere = true:silent

# Xml files
[*.xml]
indent_size = 2

[*.{cs,vb}]
#### Naming styles ####

# Naming rules

dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion
dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface
dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i

dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.types_should_be_pascal_case.symbols = types
dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case

dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members
dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case

# Symbol specifications

dotnet_naming_symbols.interface.applicable_kinds = interface
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.interface.required_modifiers =

dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.types.required_modifiers =

dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.non_field_members.required_modifiers =

# Naming styles

dotnet_naming_style.begins_with_i.required_prefix = I
dotnet_naming_style.begins_with_i.required_suffix =
dotnet_naming_style.begins_with_i.word_separator =
dotnet_naming_style.begins_with_i.capitalization = pascal_case

dotnet_naming_style.pascal_case.required_prefix =
dotnet_naming_style.pascal_case.required_suffix =
dotnet_naming_style.pascal_case.word_separator =
dotnet_naming_style.pascal_case.capitalization = pascal_case

dotnet_naming_style.pascal_case.required_prefix =
dotnet_naming_style.pascal_case.required_suffix =
dotnet_naming_style.pascal_case.word_separator =
dotnet_naming_style.pascal_case.capitalization = pascal_case
dotnet_style_allow_multiple_blank_lines_experimental = true:silent
dotnet_style_allow_statement_immediately_after_block_experimental = true:silent

# Diagnostics

# CS8603: Possible null reference return.
dotnet_diagnostic.CS8603.severity = error
dotnet_style_namespace_match_folder = true:suggestion
dotnet_style_prefer_conditional_expression_over_return = true:silent
dotnet_style_explicit_tuple_names = true:suggestion
dotnet_style_prefer_inferred_tuple_names = true:suggestion
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
dotnet_style_prefer_compound_assignment = true:suggestion
dotnet_style_prefer_simplified_interpolation = true:suggestion
dotnet_style_readonly_field = true:suggestion
dotnet_style_predefined_type_for_locals_parameters_members = true:silent
dotnet_style_predefined_type_for_member_access = true:silent
dotnet_style_require_accessibility_modifiers = for_non_interface_members:silent
dotnet_code_quality_unused_parameters = all:warning
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:silent
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:silent
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:silent
dotnet_style_parentheses_in_other_operators = never_if_unnecessary:silent
dotnet_style_qualification_for_field = false:silent
dotnet_style_qualification_for_property = false:silent
dotnet_style_qualification_for_method = false:silent
dotnet_style_qualification_for_event = false:silent
29 changes: 29 additions & 0 deletions VSConfigFinder.Test/UtilitiesTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// <copyright file="UtilitiesTests.cs" company="Microsoft Corporation">
// Copyright (C) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt in the project root for license information.
// </copyright>

namespace VSConfigFinder.Test
{
using Xunit;

public class UtilitiesTests
{
[Fact]
public void ValidateIsNotNullOrEmpty_NullOrEmpty_String_Throws_AppropriateException()
{
string? nullStr = null;
Assert.Throws<ArgumentNullException>(() => Utilities.ValidateIsNotNullOrEmpty(nullStr!, nameof(nullStr)));

var emptyStr = string.Empty;
Assert.Throws<ArgumentException>(() => Utilities.ValidateIsNotNullOrEmpty(emptyStr, nameof(emptyStr)));
}

[Fact]
public void ValidateIsNotNullOrEmpty_NotNullOrEmpty_String_Succeeds()
{
var str = "some string";
Utilities.ValidateIsNotNullOrEmpty(str, nameof(str));
}
}
}
36 changes: 36 additions & 0 deletions VSConfigFinder.Test/VSConfigFinder.Test.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\VSConfigFinder\VSConfigFinder.csproj" />
</ItemGroup>

<ItemGroup>
<EditorConfigFiles Remove="C:\Users\sknam\source\repos\VSConfigFinder\VSConfigFinder.Test\.editorconfig" />
</ItemGroup>

<ItemGroup>
<None Include="C:\Users\sknam\source\repos\VSConfigFinder\VSConfigFinder.Test\.editorconfig" />
</ItemGroup>

</Project>
8 changes: 7 additions & 1 deletion VSConfigFinder.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.6.33405.23
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VSConfigFinder", "VSConfigFinder\VSConfigFinder.csproj", "{0F9FDAD0-EF20-4EAE-B37E-2E49975CFED1}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VSConfigFinder", "VSConfigFinder\VSConfigFinder.csproj", "{0F9FDAD0-EF20-4EAE-B37E-2E49975CFED1}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{7E2E70F6-1FBA-48EA-920A-9B4032D280C3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VSConfigFinder.Test", "VSConfigFinder.Test\VSConfigFinder.Test.csproj", "{A146B74D-CC67-4ABC-92E6-346784A7D115}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -17,6 +19,10 @@ Global
{0F9FDAD0-EF20-4EAE-B37E-2E49975CFED1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0F9FDAD0-EF20-4EAE-B37E-2E49975CFED1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0F9FDAD0-EF20-4EAE-B37E-2E49975CFED1}.Release|Any CPU.Build.0 = Release|Any CPU
{A146B74D-CC67-4ABC-92E6-346784A7D115}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A146B74D-CC67-4ABC-92E6-346784A7D115}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A146B74D-CC67-4ABC-92E6-346784A7D115}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A146B74D-CC67-4ABC-92E6-346784A7D115}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
2 changes: 1 addition & 1 deletion VSConfigFinder/CommandLine/VSConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace VSConfigFinder
/// <summary>
/// The class object that defines a .vsconfig file.
/// </summary>
internal class VSConfig
public class VSConfig
{
/// <summary>
/// Gets or sets the version of the .vsconfig file.
Expand Down
23 changes: 18 additions & 5 deletions VSConfigFinder/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,32 @@ public static void Main(string[] args)

private static void Run(CommandLineOptions options)
{
Console.WriteLine("Hello! I succeeded!");
Console.WriteLine($"--createFile: {options.CreateFile}");
Console.WriteLine($"--configOutputPath: {options.ConfigOutputPath}");

// Run
if (options.CreateFile)
{
options.ConfigOutputPath ??= Directory.GetCurrentDirectory();
}

// TODO: Replace this with the output from the runner
var finalConfig = new VSConfig()
{
Version = new Version("1.0"),
Components = new string[]
{
"Microsoft.VisualStudio.Component.NuGet",
"Microsoft.VisualStudio.Component.Roslyn.Compiler",
"Microsoft.Component.MSBuild",
"Microsoft.NetCore.Component.Runtime.6.0",
},
};

// Output
Utilities.CreateOutput(finalConfig, options);
}

private static void HandleParseError(IEnumerable<Error> errors)
{
Console.WriteLine("Oops, failed");
Console.WriteLine("Please make sure that you have provided the correct arguments. Try --help to see all the available arguments and explanations.");
}
}
}
52 changes: 40 additions & 12 deletions VSConfigFinder/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,13 @@
namespace VSConfigFinder
{
using System.Diagnostics.CodeAnalysis;
using System.Text;
using System.Text.Json;

internal class Utilities
public class Utilities
{
private static readonly string[] AcceptedOutputOptions = new[] { "config", "commandline" };

public static void ValidateOutputParameter([NotNull] string s, string paramName)
{
ValidateIsNotNullOrEmpty(s, paramName);

if (!AcceptedOutputOptions.Contains(s))
{
throw new ArgumentException($"The --output parameter accepts only two options: {string.Join(",", AcceptedOutputOptions)}.");
}
}
private static readonly string ConfigExtension = ".vsconfig";
private static readonly string Add = "--add";

public static void ValidateIsNotNullOrEmpty([NotNull] string s, string paramName)
{
Expand All @@ -42,5 +35,40 @@ public static void IsNotEmpty([NotNull] string s, string paramName)
throw new ArgumentException("The string is empty.", paramName);
}
}

public static void CreateOutput(VSConfig finalConfig, CommandLineOptions options)
{
if (options.CreateFile)
{
// Create a file
var serializerOptions = new JsonSerializerOptions { WriteIndented = true };
var jsonString = JsonSerializer.Serialize(finalConfig, serializerOptions);
var outputPath = Path.Combine(options.ConfigOutputPath!, ConfigExtension);

File.WriteAllText(outputPath, jsonString);
Console.WriteLine($"Successfully created the final .vsconfig at {outputPath}");
}
else
{
// output to a command line
var output = CreateCommandLineOutput(finalConfig);
Console.WriteLine(output);
}
}

private static string CreateCommandLineOutput(VSConfig finalConfig)
{
var output = new StringBuilder(Add + " ");

foreach (var component in finalConfig.Components)
{
if (!string.IsNullOrEmpty(component))
{
output.AppendFormat("{0} ", component);
}
}

return output.ToString();
}
}
}
6 changes: 3 additions & 3 deletions VSConfigFinder/VSConfigFinder.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
</PropertyGroup>

<ItemGroup>
<EditorConfigFiles Remove="C:\Users\sknam\source\repos\VSConfigFinder\VSConfigFinder\.editorconfig" />
<PackageReference Include="CommandLineParser" Version="2.9.1" />
</ItemGroup>

<ItemGroup>
<None Include="C:\Users\sknam\source\repos\VSConfigFinder\VSConfigFinder\.editorconfig" />
<EditorConfigFiles Remove="C:\Users\sknam\source\repos\VSConfigFinder\VSConfigFinder\.editorconfig" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.9.1" />
<None Include="C:\Users\sknam\source\repos\VSConfigFinder\VSConfigFinder\.editorconfig" />
</ItemGroup>

</Project>

0 comments on commit 63975c5

Please sign in to comment.