-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
1,033 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
############################### | ||
# Core EditorConfig Options # | ||
############################### | ||
|
||
root = true | ||
|
||
# All files | ||
[*] | ||
indent_style = space | ||
indent_size = 4 | ||
insert_final_newline = true | ||
charset = utf-8-bom | ||
end_of_line = crlf | ||
trim_trailing_whitespace = true | ||
|
||
# Code files | ||
[*.{cs,csx,vb,vbx}] | ||
|
||
[*.{csproj,json}] | ||
indent_size = 2 | ||
|
||
############################### | ||
# .NET Coding Conventions # | ||
############################### | ||
|
||
[*.{cs,vb}] | ||
# Organize usings | ||
dotnet_sort_system_directives_first = true | ||
|
||
# this. preferences | ||
dotnet_style_qualification_for_field = false:none | ||
dotnet_style_qualification_for_property = false:none | ||
dotnet_style_qualification_for_method = false:none | ||
dotnet_style_qualification_for_event = false:none | ||
|
||
# Language keywords vs BCL types preferences | ||
dotnet_style_predefined_type_for_locals_parameters_members = true:none | ||
dotnet_style_predefined_type_for_member_access = true:none | ||
|
||
# Parentheses preferences | ||
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:silent | ||
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:silent | ||
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:silent | ||
dotnet_style_parentheses_in_other_operators = never_if_unnecessary:silent | ||
|
||
# Modifier preferences | ||
dotnet_style_require_accessibility_modifiers = for_non_interface_members:none | ||
dotnet_style_readonly_field = true:suggestion | ||
|
||
# Expression-level preferences | ||
dotnet_style_object_initializer = true:suggestion | ||
dotnet_style_collection_initializer = true:suggestion | ||
dotnet_style_explicit_tuple_names = true:suggestion | ||
dotnet_style_null_propagation = true:suggestion | ||
dotnet_style_coalesce_expression = true:suggestion | ||
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:silent | ||
dotnet_style_prefer_inferred_tuple_names = true:suggestion | ||
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion | ||
dotnet_style_prefer_auto_properties = true:silent | ||
dotnet_style_prefer_conditional_expression_over_assignment = true:silent | ||
dotnet_style_prefer_conditional_expression_over_return = true:silent | ||
|
||
############################### | ||
# Naming Conventions # | ||
############################### | ||
|
||
# Style Definitions | ||
dotnet_naming_style.pascal_case_style.capitalization = pascal_case | ||
dotnet_naming_style.prefix_underscore.capitalization = camel_case | ||
dotnet_naming_style.prefix_underscore.required_prefix = _ | ||
|
||
# Use PascalCase for constant fields | ||
dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = suggestion | ||
dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields | ||
dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style | ||
dotnet_naming_symbols.constant_fields.applicable_kinds = field | ||
dotnet_naming_symbols.constant_fields.applicable_accessibilities = * | ||
dotnet_naming_symbols.constant_fields.required_modifiers = const | ||
|
||
#dotnet_naming_symbols.properties.applicable_kinds = property | ||
#dotnet_naming_symbols.properties.applicable_accessibilities = * | ||
#dotnet_naming_rule.properties_should_be_pascal_case.severity = error | ||
#dotnet_naming_rule.properties_should_be_pascal_case.symbols = properties | ||
#dotnet_naming_rule.properties_should_be_pascal_case.style = pascal_case_style | ||
|
||
dotnet_naming_symbols.private_fields.applicable_kinds = field | ||
dotnet_naming_symbols.private_fields.applicable_accessibilities = private | ||
dotnet_naming_rule.private_fields_with_underscore.symbols = private_fields | ||
dotnet_naming_rule.private_fields_with_underscore.style = prefix_underscore | ||
dotnet_naming_rule.private_fields_with_underscore.severity = suggestion | ||
|
||
|
||
|
||
############################### | ||
# C# Code Style Rules # | ||
############################### | ||
|
||
[*.cs] | ||
# var preferences | ||
csharp_style_var_for_built_in_types = true:none | ||
csharp_style_var_when_type_is_apparent = true:none | ||
csharp_style_var_elsewhere = true:none | ||
|
||
# Expression-bodied members | ||
csharp_style_expression_bodied_methods = false:none | ||
csharp_style_expression_bodied_constructors = false:none | ||
csharp_style_expression_bodied_operators = false:none | ||
csharp_style_expression_bodied_properties = true:none | ||
csharp_style_expression_bodied_indexers = true:none | ||
csharp_style_expression_bodied_accessors = true:none | ||
|
||
# Pattern-matching preferences | ||
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion | ||
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion | ||
|
||
# Null-checking preferences | ||
csharp_style_throw_expression = true:suggestion | ||
csharp_style_conditional_delegate_call = true:suggestion | ||
|
||
# Modifier preferences | ||
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:suggestion | ||
|
||
# Expression-level preferences | ||
csharp_prefer_braces = true:none | ||
csharp_style_deconstructed_variable_declaration = true:suggestion | ||
csharp_prefer_simple_default_expression = true:suggestion | ||
csharp_style_pattern_local_over_anonymous_function = true:suggestion | ||
csharp_style_inlined_variable_declaration = true:suggestion | ||
|
||
############################### | ||
# C# Formatting Rules # | ||
############################### | ||
|
||
# New line preferences | ||
csharp_new_line_before_open_brace = none | ||
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 = true | ||
csharp_new_line_before_members_in_anonymous_types = true | ||
csharp_new_line_between_query_expression_clauses = true | ||
|
||
# Indentation preferences | ||
csharp_indent_case_contents = true | ||
csharp_indent_switch_labels = true | ||
csharp_indent_labels = flush_left | ||
|
||
# Space preferences | ||
csharp_space_after_cast = false | ||
csharp_space_after_keywords_in_control_flow_statements = true | ||
csharp_space_between_method_call_parameter_list_parentheses = false | ||
csharp_space_between_method_declaration_parameter_list_parentheses = false | ||
csharp_space_between_parentheses = false | ||
csharp_space_before_colon_in_inheritance_clause = true | ||
csharp_space_after_colon_in_inheritance_clause = true | ||
csharp_space_around_binary_operators = before_and_after | ||
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false | ||
csharp_space_between_method_call_name_and_opening_parenthesis = false | ||
csharp_space_between_method_call_empty_parameter_list_parentheses = false | ||
|
||
# Wrapping preferences | ||
csharp_preserve_single_line_statements = true | ||
csharp_preserve_single_line_blocks = true | ||
|
||
################################## | ||
# Visual Basic Code Style Rules # | ||
################################## | ||
|
||
[*.vb] | ||
# Modifier preferences | ||
visual_basic_preferred_modifier_order = Partial,Default,Private,Protected,Public,Friend,NotOverridable,Overridable,MustOverride,Overloads,Overrides,MustInherit,NotInheritable,Static,Shared,Shadows,ReadOnly,WriteOnly,Dim,Const,WithEvents,Widening,Narrowing,Custom,Async:suggestion |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<Project> | ||
<PropertyGroup> | ||
<LangVersion>latest</LangVersion> | ||
</PropertyGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
# TestAA | ||
[![Build status](https://ci.appveyor.com/api/projects/status/8a7wlfjt9oedlmy5/branch/master?svg=true)](https://ci.appveyor.com/project/inasync/testaa/branch/master) | ||
[![NuGet](https://img.shields.io/nuget/v/Inasync.TestAA.svg)](https://www.nuget.org/packages/Inasync.TestAA/) | ||
|
||
***TestAA*** は Arrange-Act-Assert(AAA)パターンによるテストの記述をサポートする為のシンプルなライブラリです。 | ||
|
||
|
||
## Target Frameworks | ||
- .NET Standard 2.0+ | ||
- .NET Standard 1.0+ | ||
- .NET Framework 4.5+ | ||
|
||
|
||
## Description | ||
***TestAA*** は AAA パターンのうち Act-Assert の記述を直接的に補助します。 | ||
|
||
基本的な使い方は下記の通りです: | ||
```cs | ||
TestAA | ||
.Act(テスト対象コード) | ||
.Assert(テスト対象コードの戻り値の検証, 例外の検証, その他の検証); | ||
``` | ||
|
||
Arrange に相当する処理は `TestAA.Act()` の呼び出しより前に記述します。 | ||
```cs | ||
// Arrange | ||
// ... | ||
// Act | ||
TestAA.Act(...) | ||
``` | ||
|
||
`Act()` の引数には、テスト対象となるメソッドまたはコードのラムダ式やデリゲートを渡して下さい。テストの対象ではないメソッドまたはコードも含めますと、そこから発生した例外がテスト対象コードから生じたものとして扱われてしまい、正しい検証が行えなくなります。 | ||
```cs | ||
TestAA.Act(() => { /* ここでテスト対象のメソッドを呼ぶ */ }) | ||
``` | ||
|
||
`Assert()` で `Act()` の結果を検証します。第1引数で `Act()` に渡されたテスト対象コードの戻り値を検証し、第2引数で `Act()` で生じた例外を検証(または例外が生じなかった事を検証)します。 | ||
```cs | ||
.Act(() => int.Parse("123")) | ||
.Assert( | ||
@return: ret => { /* ここで戻り値の検証 */ }, | ||
exception: ex => { /* ここで例外の検証 */ }, | ||
others: () => { /* ここで上記以外の検証。不要なら省略 */ } | ||
); | ||
``` | ||
|
||
|
||
## Usage | ||
```cs | ||
public void IntParseTest() { | ||
// Success | ||
TestAA.Act(() => int.Parse("123")).Assert( | ||
ret => ret.Is(123), | ||
ex => ex?.GetType().Is(null) | ||
); | ||
|
||
// FormatException | ||
TestAA.Act(() => int.Parse("abc")).Assert( | ||
ret => { }, | ||
ex => ex?.GetType().Is(typeof(FormatException)) | ||
); | ||
} | ||
``` | ||
|
||
下記は *MSTest* を利用した、より実践的な例です: | ||
```cs | ||
[DataTestMethod] | ||
[DataRow(0, null, null, typeof(ArgumentNullException))] | ||
[DataRow(1, "123", 123, null)] | ||
[DataRow(2, "abc", null, typeof(FormatException))] | ||
public void IntParseTest(int testNumber, string input, int expected, Type expectedExceptionType) { | ||
var msg = "No." + testNumber; | ||
|
||
TestAA.Act(() => int.Parse(input)).Assert( | ||
ret => Assert.AreEqual(expected, ret, msg), | ||
ex => Assert.AreEqual(expectedExceptionType, ex?.GetType(), msg) | ||
); | ||
} | ||
``` | ||
または | ||
```cs | ||
[TestMethod] | ||
public void IntParseTest() { | ||
Action TestCase(int testNumber, string input, int expected, Type expectedExceptionType = null) => () => { | ||
var msg = "No." + testNumber; | ||
|
||
TestAA.Act(() => int.Parse(input)).Assert( | ||
ret => Assert.AreEqual(expected, ret, msg), | ||
ex => Assert.AreEqual(expectedExceptionType, ex?.GetType(), msg) | ||
); | ||
}; | ||
|
||
foreach (var action in new[] { | ||
TestCase( 0, null , expected: 0 , expectedExceptionType: typeof(ArgumentNullException)), | ||
TestCase( 1, "abc", expected: 0 , expectedExceptionType: typeof(FormatException)), | ||
TestCase( 2, "123", expected: 123), | ||
}) { action(); } | ||
} | ||
``` | ||
|
||
|
||
## Licence | ||
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 15 | ||
VisualStudioVersion = 15.0.28307.852 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Inasync.TestAA", "src\Inasync.TestAA\Inasync.TestAA.csproj", "{1FA4FF51-C027-40EA-AAEA-199F2548A1A4}" | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Inasync.TestAA.Tests", "tests\Inasync.TestAA.Tests\Inasync.TestAA.Tests.csproj", "{25B86BC7-A35F-48E6-9255-DCE43263B194}" | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{7D0CB7FE-9D55-4FAF-9C3B-1688A3961B0C}" | ||
ProjectSection(SolutionItems) = preProject | ||
.editorconfig = .editorconfig | ||
.gitignore = .gitignore | ||
appveyor.yml = appveyor.yml | ||
Directory.Build.props = Directory.Build.props | ||
LICENSE = LICENSE | ||
README.md = README.md | ||
EndProjectSection | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{1FA4FF51-C027-40EA-AAEA-199F2548A1A4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{1FA4FF51-C027-40EA-AAEA-199F2548A1A4}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{1FA4FF51-C027-40EA-AAEA-199F2548A1A4}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{1FA4FF51-C027-40EA-AAEA-199F2548A1A4}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{25B86BC7-A35F-48E6-9255-DCE43263B194}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{25B86BC7-A35F-48E6-9255-DCE43263B194}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{25B86BC7-A35F-48E6-9255-DCE43263B194}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{25B86BC7-A35F-48E6-9255-DCE43263B194}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {93DA389C-05BA-4585-80A7-F081E7B73A80} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
version: ci-{build}-{branch} | ||
image: Visual Studio 2017 | ||
configuration: Release | ||
nuget: | ||
project_feed: true | ||
before_build: | ||
- cmd: nuget restore | ||
build: | ||
publish_nuget: true | ||
verbosity: minimal | ||
deploy: | ||
- provider: GitHub | ||
auth_token: | ||
secure: eHI+nPFCmnPOdRRPRhGQBso/RlA5seuhkPBRgOMbGWDHzNWw+Us1FJrR7TTBLVR0 | ||
on: | ||
appveyor_repo_tag: true | ||
- provider: NuGet | ||
api_key: | ||
secure: zUlOhbjj+3Jsywco3QlyLXz4zSXS9fqQdEWTOCpmwzEl5cBLHFSrYnOR8xnNaSaB | ||
on: | ||
appveyor_repo_tag: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>netstandard2.0;netstandard1.0;net45</TargetFrameworks> | ||
<GenerateDocumentationFile>true</GenerateDocumentationFile> | ||
<RootNamespace>Inasync</RootNamespace> | ||
<Authors>inasync</Authors> | ||
<Description>TestAA is a simple library that supports writing tests using the Arrange-Act-Assert (AAA) pattern.</Description> | ||
<PackageProjectUrl>https://github.com/in-async/TestAA</PackageProjectUrl> | ||
<PackageLicenseUrl>https://github.com/in-async/TestAA/blob/master/LICENSE</PackageLicenseUrl> | ||
<PackageTags>library test unittest aaa</PackageTags> | ||
<Version>0.1.0</Version> | ||
</PropertyGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
using System.Runtime.CompilerServices; | ||
|
||
[assembly: InternalsVisibleTo("Inasync.TestAA.Tests")] |
Oops, something went wrong.