Skip to content

Commit

Permalink
Baseline porting of the codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Martinez committed Apr 21, 2018
1 parent d34f5a4 commit 28d03e4
Show file tree
Hide file tree
Showing 48 changed files with 8,725 additions and 1 deletion.
89 changes: 89 additions & 0 deletions .editorconfig
@@ -0,0 +1,89 @@
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference

# top-most .editorconfig file
root = true

# don't use tabs for indentation
[*]
indent_style = space

# code files
[*.{cs,csx,vb,vbx}]
indent_size = 4

# xml project files
[*.{csproj,vbproj,proj,projitems,shproj}]
indent_size = 2

# xml config files
[*.{props,targets,ruleset,config,nuspec,resx,vsixmanifest,vsct}]
indent_size = 2

# json files
[*.json]
indent_size = 2

# whitespace handling
trim_trailing_whitespace = true:error
insert_final_newline = false

# .net code style settings:
[*.{cs,vb}]
dotnet_sort_system_directives_first = false

# avoid "this." and "me." if not necessary
dotnet_style_qualification_for_field = false:error
dotnet_style_qualification_for_property = false:error
dotnet_style_qualification_for_method = false:error
dotnet_style_qualification_for_event = false:error

# use language keywords instead of framework type names for type references
dotnet_style_predefined_type_for_locals_parameters_members = true:error
dotnet_style_predefined_type_for_member_access = true:error

# suggest more modern language features when available
dotnet_style_object_initializer = true:suggestion
dotnet_style_collection_initializer = true:suggestion
dotnet_style_coalesce_expression = true:suggestion
dotnet_style_null_propagation = true:suggestion
dotnet_style_explicit_tuple_names = true:suggestion

# csharp code style settings:
[*.cs]

# prefer "var" everywhere
csharp_style_var_for_built_in_types = true:suggestion
csharp_style_var_when_type_is_apparent = true:suggestion
csharp_style_var_elsewhere = true:suggestion

# prefer method-like constructs to have a block body
csharp_style_expression_bodied_methods = false:none
csharp_style_expression_bodied_constructors = false:none
csharp_style_expression_bodied_operators = false:none

# prefer property-like constructs to have an expression-body
csharp_style_expression_bodied_properties = true:none
csharp_style_expression_bodied_indexers = true:none
csharp_style_expression_bodied_accessors = true:none

# suggest more modern language features when available
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
csharp_style_inlined_variable_declaration = true:suggestion
csharp_style_throw_expression = true:suggestion
csharp_style_conditional_delegate_call = true:suggestion

# newline settings
csharp_new_line_before_open_brace = all
csharp_new_line_before_else = true
csharp_new_line_before_catch = true
csharp_new_line_before_finally = true
csharp_new_line_before_members_in_object_initializers = false
csharp_new_line_before_members_in_anonymous_types = false

# space settings
csharp_space_after_cast = true
csharp_space_after_keywords_in_control_flow_statements = true
csharp_space_between_method_declaration_parameter_list_parentheses = true
csharp_space_between_method_call_parameter_list_parentheses = true
csharp_space_between_parentheses = control_flow_statements, expressions
63 changes: 63 additions & 0 deletions .gitattributes
@@ -0,0 +1,63 @@
###############################################################################
# Set default behavior to automatically normalize line endings.
###############################################################################
* text=auto

###############################################################################
# Set default behavior for command prompt diff.
#
# This is need for earlier builds of msysgit that does not have it on by
# default for csharp files.
# Note: This is only used by command line
###############################################################################
#*.cs diff=csharp

###############################################################################
# Set the merge driver for project and solution files
#
# Merging from the command prompt will add diff markers to the files if there
# are conflicts (Merging from VS is not affected by the settings below, in VS
# the diff markers are never inserted). Diff markers may cause the following
# file extensions to fail to load in VS. An alternative would be to treat
# these files as binary and thus will always conflict and require user
# intervention with every merge. To do so, just uncomment the entries below
###############################################################################
#*.sln merge=binary
#*.csproj merge=binary
#*.vbproj merge=binary
#*.vcxproj merge=binary
#*.vcproj merge=binary
#*.dbproj merge=binary
#*.fsproj merge=binary
#*.lsproj merge=binary
#*.wixproj merge=binary
#*.modelproj merge=binary
#*.sqlproj merge=binary
#*.wwaproj merge=binary

###############################################################################
# behavior for image files
#
# image files are treated as binary by default.
###############################################################################
#*.jpg binary
#*.png binary
#*.gif binary

###############################################################################
# diff behavior for common document formats
#
# Convert binary document formats to text before diffing them. This feature
# is only available from the command line. Turn it on by uncommenting the
# entries below.
###############################################################################
#*.doc diff=astextplain
#*.DOC diff=astextplain
#*.docx diff=astextplain
#*.DOCX diff=astextplain
#*.dot diff=astextplain
#*.DOT diff=astextplain
#*.pdf diff=astextplain
#*.PDF diff=astextplain
#*.rtf diff=astextplain
#*.RTF diff=astextplain
63 changes: 62 additions & 1 deletion README.md
@@ -1,5 +1,66 @@
# Microsoft Test Framework Extensions
This project provides extensions to the Microsoft Visual Studio Team Test unit testing framework. Features include alternatives to **ExpectedExceptionAttribute** and a fully extensible assertion application programming interface. The extensibility model is designed to allow swapping out the default **Assert** class and still maintain source code compatibility with the same intrinsic built-in functionality. You're then free to change, customize, or leverage the many built-in extensions.

# Contributing
## Example Usage
To switch from a typical assertion model to the extensible assertion model, simply have your test class inherit from the **UnitTest** base class. This isn't a requirement to make things work, but it's the simplest model for consumption out-of-the-box.

```c#
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

public class Person
{
public Person( string name ) => Name = name ?? throw new ArgumentNullException( nameof( name ), "The name cannot be null." );

public string Name { get; }
}

[TestClass]
public class PersonTest : UnitTest
{
[TestMethod]
public void ConstructorShouldNotAllowNullName()
{
Assert.ThrowsIfArgumentNull( ( string name ) => new Person( name ) )
.Verify( e => e.Message == "The name cannot be null." );
}
}
```

If you don't want to use a base class, simply add a property to your existing test class:

```c#
[TestClass]
public class PersonTest
{
Asserter Assert { get; } = new Asserter();

[TestMethod]
public void ConstructorShouldNotAllowNullName()
{
// arrange
var person = new Person( "Bob" );

// act
var result = person.Name;

// assert
Assert.AreEqual( "Bob", result );
}
}
```

## Features
The following outlines the features and extensions provided out-of-the-box:

* **Asserter** - Base assertion class and adapts over **Assert** for its default implemention
* **CollectionAsserter** - Collection assertion class and adapts over **CollectionAssert** for its default implemention
* **ExceptionAsserter** - Exception assertion class to further verify parameter names, messages, etc
* **IEnumerable<T>** - Extension methods to verify various implementations of collections and sequences
* **INotifyPropertyChanged** - Extension methods to verify implementations of the **INotifyPropertyChanged** interface
* **INotifyCollectionChanged** - Extension methods to verify implementations of the **INotifyCollectionChanged** interface

## Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
Expand Down
34 changes: 34 additions & 0 deletions after.mstestex.sln.targets
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<Import Project="build\signing.targets" />

<Target Name="AfterSolutionBuild" AfterTargets="Build">

<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<BuildProperties>Configuration=$(Configuration)</BuildProperties>
<BuildProperties Condition=" ('$(Platform)' != '') AND ('$(Platform)' != 'AnyCPU') AND ('$(Platform)' != 'Any CPU') ">$(BuildProperties);Platform=$(Platform)</BuildProperties>
</PropertyGroup>

<ItemGroup>
<Projects Include="src\**\*.csproj" />
</ItemGroup>

<MSBuild Projects="@(Projects)" Targets="GetTargetPath" Properties="$(BuildProperties)" UnloadProjectsOnCompletion="true">
<Output TaskParameter="TargetOutputs" ItemName="TargetFiles" />
</MSBuild>

<PropertyGroup>
<!-- transform list to pipe-separated values so we can forward it as a parameter using a build property -->
<SigningProperties>
SourceDir=$(MSBuildThisFileDirectory)\src;
FilesToSign=@(TargetFiles->'%(Identity)','|')
</SigningProperties>
</PropertyGroup>

<MSBuild Projects ="$(MSBuildThisFileFullPath)" Targets="WriteCodeSigningFileList" Properties="$(SigningProperties)" />

</Target>

</Project>
18 changes: 18 additions & 0 deletions build/code-analysis.props
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<PropertyGroup Label="Code Analysis">
<Features>IOperation</Features>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<CodeAnalysisRuleSet>$(MSBuildThisFileDirectory)code-analysis.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>

<ItemGroup Label="Code Analysis">
<AdditionalFiles Include="$(MSBuildThisFileDirectory)stylecop.json" Link="stylecop.json" Visible="false" />
</ItemGroup>

<ItemGroup Label="NuGet">
<PackageReference Include="StyleCop.Analyzers" Version="1.1.0-beta006" PrivateAssets="All" />
</ItemGroup>

</Project>
93 changes: 93 additions & 0 deletions build/code-analysis.ruleset
@@ -0,0 +1,93 @@
<?xml version="1.0" encoding="utf-8"?>
<RuleSet Name="Microsoft Managed Recommended Rules" Description="These rules focus on the most critical problems in your code, including potential security holes, application crashes, and other important logic and design errors. It is recommended to include this rule set in any custom rule set you create for your projects." ToolsVersion="10.0">
<Localization ResourceAssembly="Microsoft.VisualStudio.CodeAnalysis.RuleSets.Strings.dll" ResourceBaseName="Microsoft.VisualStudio.CodeAnalysis.RuleSets.Strings.Localized">
<Name Resource="MinimumRecommendedRules_Name" />
<Description Resource="MinimumRecommendedRules_Description" />
</Localization>
<Rules AnalyzerId="Microsoft.Analyzers.ManagedCodeAnalysis" RuleNamespace="Microsoft.Rules.Managed">
<Rule Id="CA1001" Action="Warning" />
<Rule Id="CA1009" Action="Warning" />
<Rule Id="CA1016" Action="Warning" />
<Rule Id="CA1033" Action="Warning" />
<Rule Id="CA1049" Action="Warning" />
<Rule Id="CA1060" Action="Warning" />
<Rule Id="CA1061" Action="Warning" />
<Rule Id="CA1063" Action="Warning" />
<Rule Id="CA1065" Action="Warning" />
<Rule Id="CA1301" Action="Warning" />
<Rule Id="CA1400" Action="Warning" />
<Rule Id="CA1401" Action="Warning" />
<Rule Id="CA1403" Action="Warning" />
<Rule Id="CA1404" Action="Warning" />
<Rule Id="CA1405" Action="Warning" />
<Rule Id="CA1410" Action="Warning" />
<Rule Id="CA1415" Action="Warning" />
<Rule Id="CA1821" Action="Warning" />
<Rule Id="CA1900" Action="Warning" />
<Rule Id="CA1901" Action="Warning" />
<Rule Id="CA2002" Action="Warning" />
<Rule Id="CA2100" Action="Warning" />
<Rule Id="CA2101" Action="Warning" />
<Rule Id="CA2108" Action="Warning" />
<Rule Id="CA2111" Action="Warning" />
<Rule Id="CA2112" Action="Warning" />
<Rule Id="CA2114" Action="Warning" />
<Rule Id="CA2116" Action="Warning" />
<Rule Id="CA2117" Action="Warning" />
<Rule Id="CA2122" Action="Warning" />
<Rule Id="CA2123" Action="Warning" />
<Rule Id="CA2124" Action="Warning" />
<Rule Id="CA2126" Action="Warning" />
<Rule Id="CA2131" Action="Warning" />
<Rule Id="CA2132" Action="Warning" />
<Rule Id="CA2133" Action="Warning" />
<Rule Id="CA2134" Action="Warning" />
<Rule Id="CA2137" Action="Warning" />
<Rule Id="CA2138" Action="Warning" />
<Rule Id="CA2140" Action="Warning" />
<Rule Id="CA2141" Action="Warning" />
<Rule Id="CA2146" Action="Warning" />
<Rule Id="CA2147" Action="Warning" />
<Rule Id="CA2149" Action="Warning" />
<Rule Id="CA2200" Action="Warning" />
<Rule Id="CA2202" Action="Warning" />
<Rule Id="CA2207" Action="Warning" />
<Rule Id="CA2212" Action="Warning" />
<Rule Id="CA2213" Action="Warning" />
<Rule Id="CA2214" Action="Warning" />
<Rule Id="CA2216" Action="Warning" />
<Rule Id="CA2220" Action="Warning" />
<Rule Id="CA2229" Action="Warning" />
<Rule Id="CA2231" Action="Warning" />
<Rule Id="CA2232" Action="Warning" />
<Rule Id="CA2235" Action="Warning" />
<Rule Id="CA2236" Action="Warning" />
<Rule Id="CA2237" Action="Warning" />
<Rule Id="CA2238" Action="Warning" />
<Rule Id="CA2240" Action="Warning" />
<Rule Id="CA2241" Action="Warning" />
<Rule Id="CA2242" Action="Warning" />
</Rules>
<Rules AnalyzerId="Microsoft.AnalyzerPowerPack.CSharp" RuleNamespace="Microsoft.AnalyzerPowerPack.CSharp">
<Rule Id="CA1033" Action="Warning" />
</Rules>
<Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers">
<Rule Id="SA1002" Action="None" />
<Rule Id="SA1003" Action="None" />
<Rule Id="SA1008" Action="None" />
<Rule Id="SA1009" Action="None" />
<Rule Id="SA1101" Action="None" />
<Rule Id="SA1127" Action="None" />
<Rule Id="SA1128" Action="None" />
<Rule Id="SA1201" Action="None" />
<Rule Id="SA1202" Action="None" />
<Rule Id="SA1204" Action="None" />
<Rule Id="SA1205" Action="None" />
<Rule Id="SA1208" Action="None" />
<Rule Id="SA1311" Action="None" />
<Rule Id="SA1400" Action="None" />
<Rule Id="SA1502" Action="None" />
<Rule Id="SA1516" Action="None" />
<Rule Id="SA1600" Action="None" />
</Rules>
</RuleSet>

0 comments on commit 28d03e4

Please sign in to comment.