Skip to content

Commit f61ed3b

Browse files
committed
Initial code commit
1 parent 63b8810 commit f61ed3b

15 files changed

+1033
-0
lines changed

.editorconfig

+171
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
###############################
2+
# Core EditorConfig Options #
3+
###############################
4+
5+
root = true
6+
7+
# All files
8+
[*]
9+
indent_style = space
10+
indent_size = 4
11+
insert_final_newline = true
12+
charset = utf-8-bom
13+
end_of_line = crlf
14+
trim_trailing_whitespace = true
15+
16+
# Code files
17+
[*.{cs,csx,vb,vbx}]
18+
19+
[*.{csproj,json}]
20+
indent_size = 2
21+
22+
###############################
23+
# .NET Coding Conventions #
24+
###############################
25+
26+
[*.{cs,vb}]
27+
# Organize usings
28+
dotnet_sort_system_directives_first = true
29+
30+
# this. preferences
31+
dotnet_style_qualification_for_field = false:none
32+
dotnet_style_qualification_for_property = false:none
33+
dotnet_style_qualification_for_method = false:none
34+
dotnet_style_qualification_for_event = false:none
35+
36+
# Language keywords vs BCL types preferences
37+
dotnet_style_predefined_type_for_locals_parameters_members = true:none
38+
dotnet_style_predefined_type_for_member_access = true:none
39+
40+
# Parentheses preferences
41+
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:silent
42+
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:silent
43+
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:silent
44+
dotnet_style_parentheses_in_other_operators = never_if_unnecessary:silent
45+
46+
# Modifier preferences
47+
dotnet_style_require_accessibility_modifiers = for_non_interface_members:none
48+
dotnet_style_readonly_field = true:suggestion
49+
50+
# Expression-level preferences
51+
dotnet_style_object_initializer = true:suggestion
52+
dotnet_style_collection_initializer = true:suggestion
53+
dotnet_style_explicit_tuple_names = true:suggestion
54+
dotnet_style_null_propagation = true:suggestion
55+
dotnet_style_coalesce_expression = true:suggestion
56+
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:silent
57+
dotnet_style_prefer_inferred_tuple_names = true:suggestion
58+
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
59+
dotnet_style_prefer_auto_properties = true:silent
60+
dotnet_style_prefer_conditional_expression_over_assignment = true:silent
61+
dotnet_style_prefer_conditional_expression_over_return = true:silent
62+
63+
###############################
64+
# Naming Conventions #
65+
###############################
66+
67+
# Style Definitions
68+
dotnet_naming_style.pascal_case_style.capitalization = pascal_case
69+
dotnet_naming_style.prefix_underscore.capitalization = camel_case
70+
dotnet_naming_style.prefix_underscore.required_prefix = _
71+
72+
# Use PascalCase for constant fields
73+
dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = suggestion
74+
dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields
75+
dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style
76+
dotnet_naming_symbols.constant_fields.applicable_kinds = field
77+
dotnet_naming_symbols.constant_fields.applicable_accessibilities = *
78+
dotnet_naming_symbols.constant_fields.required_modifiers = const
79+
80+
#dotnet_naming_symbols.properties.applicable_kinds = property
81+
#dotnet_naming_symbols.properties.applicable_accessibilities = *
82+
#dotnet_naming_rule.properties_should_be_pascal_case.severity = error
83+
#dotnet_naming_rule.properties_should_be_pascal_case.symbols = properties
84+
#dotnet_naming_rule.properties_should_be_pascal_case.style = pascal_case_style
85+
86+
dotnet_naming_symbols.private_fields.applicable_kinds = field
87+
dotnet_naming_symbols.private_fields.applicable_accessibilities = private
88+
dotnet_naming_rule.private_fields_with_underscore.symbols = private_fields
89+
dotnet_naming_rule.private_fields_with_underscore.style = prefix_underscore
90+
dotnet_naming_rule.private_fields_with_underscore.severity = suggestion
91+
92+
93+
94+
###############################
95+
# C# Code Style Rules #
96+
###############################
97+
98+
[*.cs]
99+
# var preferences
100+
csharp_style_var_for_built_in_types = true:none
101+
csharp_style_var_when_type_is_apparent = true:none
102+
csharp_style_var_elsewhere = true:none
103+
104+
# Expression-bodied members
105+
csharp_style_expression_bodied_methods = false:none
106+
csharp_style_expression_bodied_constructors = false:none
107+
csharp_style_expression_bodied_operators = false:none
108+
csharp_style_expression_bodied_properties = true:none
109+
csharp_style_expression_bodied_indexers = true:none
110+
csharp_style_expression_bodied_accessors = true:none
111+
112+
# Pattern-matching preferences
113+
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
114+
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
115+
116+
# Null-checking preferences
117+
csharp_style_throw_expression = true:suggestion
118+
csharp_style_conditional_delegate_call = true:suggestion
119+
120+
# Modifier preferences
121+
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:suggestion
122+
123+
# Expression-level preferences
124+
csharp_prefer_braces = true:none
125+
csharp_style_deconstructed_variable_declaration = true:suggestion
126+
csharp_prefer_simple_default_expression = true:suggestion
127+
csharp_style_pattern_local_over_anonymous_function = true:suggestion
128+
csharp_style_inlined_variable_declaration = true:suggestion
129+
130+
###############################
131+
# C# Formatting Rules #
132+
###############################
133+
134+
# New line preferences
135+
csharp_new_line_before_open_brace = none
136+
csharp_new_line_before_else = true
137+
csharp_new_line_before_catch = true
138+
csharp_new_line_before_finally = true
139+
csharp_new_line_before_members_in_object_initializers = true
140+
csharp_new_line_before_members_in_anonymous_types = true
141+
csharp_new_line_between_query_expression_clauses = true
142+
143+
# Indentation preferences
144+
csharp_indent_case_contents = true
145+
csharp_indent_switch_labels = true
146+
csharp_indent_labels = flush_left
147+
148+
# Space preferences
149+
csharp_space_after_cast = false
150+
csharp_space_after_keywords_in_control_flow_statements = true
151+
csharp_space_between_method_call_parameter_list_parentheses = false
152+
csharp_space_between_method_declaration_parameter_list_parentheses = false
153+
csharp_space_between_parentheses = false
154+
csharp_space_before_colon_in_inheritance_clause = true
155+
csharp_space_after_colon_in_inheritance_clause = true
156+
csharp_space_around_binary_operators = before_and_after
157+
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
158+
csharp_space_between_method_call_name_and_opening_parenthesis = false
159+
csharp_space_between_method_call_empty_parameter_list_parentheses = false
160+
161+
# Wrapping preferences
162+
csharp_preserve_single_line_statements = true
163+
csharp_preserve_single_line_blocks = true
164+
165+
##################################
166+
# Visual Basic Code Style Rules #
167+
##################################
168+
169+
[*.vb]
170+
# Modifier preferences
171+
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

Directory.Build.props

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<Project>
2+
<PropertyGroup>
3+
<LangVersion>latest</LangVersion>
4+
</PropertyGroup>
5+
</Project>

README.md

+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# TestAA
2+
[![Build status](https://ci.appveyor.com/api/projects/status/8a7wlfjt9oedlmy5/branch/master?svg=true)](https://ci.appveyor.com/project/inasync/testaa/branch/master)
3+
[![NuGet](https://img.shields.io/nuget/v/Inasync.TestAA.svg)](https://www.nuget.org/packages/Inasync.TestAA/)
4+
5+
***TestAA*** は Arrange-Act-Assert(AAA)パターンによるテストの記述をサポートする為のシンプルなライブラリです。
6+
7+
8+
## Target Frameworks
9+
- .NET Standard 2.0+
10+
- .NET Standard 1.0+
11+
- .NET Framework 4.5+
12+
13+
14+
## Description
15+
***TestAA*** は AAA パターンのうち Act-Assert の記述を直接的に補助します。
16+
17+
基本的な使い方は下記の通りです:
18+
```cs
19+
TestAA
20+
.Act(テスト対象コード)
21+
.Assert(テスト対象コードの戻り値の検証, 例外の検証, その他の検証);
22+
```
23+
24+
Arrange に相当する処理は `TestAA.Act()` の呼び出しより前に記述します。
25+
```cs
26+
// Arrange
27+
// ...
28+
29+
// Act
30+
TestAA.Act(...)
31+
```
32+
33+
`Act()` の引数には、テスト対象となるメソッドまたはコードのラムダ式やデリゲートを渡して下さい。テストの対象ではないメソッドまたはコードも含めますと、そこから発生した例外がテスト対象コードから生じたものとして扱われてしまい、正しい検証が行えなくなります。
34+
```cs
35+
TestAA.Act(() => { /* ここでテスト対象のメソッドを呼ぶ */ })
36+
```
37+
38+
`Assert()``Act()` の結果を検証します。第1引数で `Act()` に渡されたテスト対象コードの戻り値を検証し、第2引数で `Act()` で生じた例外を検証(または例外が生じなかった事を検証)します。
39+
```cs
40+
.Act(() => int.Parse("123"))
41+
.Assert(
42+
@return: ret => { /* ここで戻り値の検証 */ },
43+
exception: ex => { /* ここで例外の検証 */ },
44+
others: () => { /* ここで上記以外の検証。不要なら省略 */ }
45+
);
46+
```
47+
48+
49+
## Usage
50+
```cs
51+
public void IntParseTest() {
52+
// Success
53+
TestAA.Act(() => int.Parse("123")).Assert(
54+
ret => ret.Is(123),
55+
ex => ex?.GetType().Is(null)
56+
);
57+
58+
// FormatException
59+
TestAA.Act(() => int.Parse("abc")).Assert(
60+
ret => { },
61+
ex => ex?.GetType().Is(typeof(FormatException))
62+
);
63+
}
64+
```
65+
66+
下記は *MSTest* を利用した、より実践的な例です:
67+
```cs
68+
[DataTestMethod]
69+
[DataRow(0, null, null, typeof(ArgumentNullException))]
70+
[DataRow(1, "123", 123, null)]
71+
[DataRow(2, "abc", null, typeof(FormatException))]
72+
public void IntParseTest(int testNumber, string input, int expected, Type expectedExceptionType) {
73+
var msg = "No." + testNumber;
74+
75+
TestAA.Act(() => int.Parse(input)).Assert(
76+
ret => Assert.AreEqual(expected, ret, msg),
77+
ex => Assert.AreEqual(expectedExceptionType, ex?.GetType(), msg)
78+
);
79+
}
80+
```
81+
または
82+
```cs
83+
[TestMethod]
84+
public void IntParseTest() {
85+
Action TestCase(int testNumber, string input, int expected, Type expectedExceptionType = null) => () => {
86+
var msg = "No." + testNumber;
87+
88+
TestAA.Act(() => int.Parse(input)).Assert(
89+
ret => Assert.AreEqual(expected, ret, msg),
90+
ex => Assert.AreEqual(expectedExceptionType, ex?.GetType(), msg)
91+
);
92+
};
93+
94+
foreach (var action in new[] {
95+
TestCase( 0, null , expected: 0 , expectedExceptionType: typeof(ArgumentNullException)),
96+
TestCase( 1, "abc", expected: 0 , expectedExceptionType: typeof(FormatException)),
97+
TestCase( 2, "123", expected: 123),
98+
}) { action(); }
99+
}
100+
```
101+
102+
103+
## Licence
104+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details

TestAA.sln

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.28307.852
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Inasync.TestAA", "src\Inasync.TestAA\Inasync.TestAA.csproj", "{1FA4FF51-C027-40EA-AAEA-199F2548A1A4}"
7+
EndProject
8+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Inasync.TestAA.Tests", "tests\Inasync.TestAA.Tests\Inasync.TestAA.Tests.csproj", "{25B86BC7-A35F-48E6-9255-DCE43263B194}"
9+
EndProject
10+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{7D0CB7FE-9D55-4FAF-9C3B-1688A3961B0C}"
11+
ProjectSection(SolutionItems) = preProject
12+
.editorconfig = .editorconfig
13+
.gitignore = .gitignore
14+
appveyor.yml = appveyor.yml
15+
Directory.Build.props = Directory.Build.props
16+
LICENSE = LICENSE
17+
README.md = README.md
18+
EndProjectSection
19+
EndProject
20+
Global
21+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
22+
Debug|Any CPU = Debug|Any CPU
23+
Release|Any CPU = Release|Any CPU
24+
EndGlobalSection
25+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
26+
{1FA4FF51-C027-40EA-AAEA-199F2548A1A4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27+
{1FA4FF51-C027-40EA-AAEA-199F2548A1A4}.Debug|Any CPU.Build.0 = Debug|Any CPU
28+
{1FA4FF51-C027-40EA-AAEA-199F2548A1A4}.Release|Any CPU.ActiveCfg = Release|Any CPU
29+
{1FA4FF51-C027-40EA-AAEA-199F2548A1A4}.Release|Any CPU.Build.0 = Release|Any CPU
30+
{25B86BC7-A35F-48E6-9255-DCE43263B194}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
31+
{25B86BC7-A35F-48E6-9255-DCE43263B194}.Debug|Any CPU.Build.0 = Debug|Any CPU
32+
{25B86BC7-A35F-48E6-9255-DCE43263B194}.Release|Any CPU.ActiveCfg = Release|Any CPU
33+
{25B86BC7-A35F-48E6-9255-DCE43263B194}.Release|Any CPU.Build.0 = Release|Any CPU
34+
EndGlobalSection
35+
GlobalSection(SolutionProperties) = preSolution
36+
HideSolutionNode = FALSE
37+
EndGlobalSection
38+
GlobalSection(ExtensibilityGlobals) = postSolution
39+
SolutionGuid = {93DA389C-05BA-4585-80A7-F081E7B73A80}
40+
EndGlobalSection
41+
EndGlobal

appveyor.yml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
version: ci-{build}-{branch}
2+
image: Visual Studio 2017
3+
configuration: Release
4+
nuget:
5+
project_feed: true
6+
before_build:
7+
- cmd: nuget restore
8+
build:
9+
publish_nuget: true
10+
verbosity: minimal
11+
deploy:
12+
- provider: GitHub
13+
auth_token:
14+
secure: eHI+nPFCmnPOdRRPRhGQBso/RlA5seuhkPBRgOMbGWDHzNWw+Us1FJrR7TTBLVR0
15+
on:
16+
appveyor_repo_tag: true
17+
- provider: NuGet
18+
api_key:
19+
secure: zUlOhbjj+3Jsywco3QlyLXz4zSXS9fqQdEWTOCpmwzEl5cBLHFSrYnOR8xnNaSaB
20+
on:
21+
appveyor_repo_tag: true
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFrameworks>netstandard2.0;netstandard1.0;net45</TargetFrameworks>
5+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
6+
<RootNamespace>Inasync</RootNamespace>
7+
<Authors>inasync</Authors>
8+
<Description>TestAA is a simple library that supports writing tests using the Arrange-Act-Assert (AAA) pattern.</Description>
9+
<PackageProjectUrl>https://github.com/in-async/TestAA</PackageProjectUrl>
10+
<PackageLicenseUrl>https://github.com/in-async/TestAA/blob/master/LICENSE</PackageLicenseUrl>
11+
<PackageTags>library test unittest aaa</PackageTags>
12+
<Version>0.1.0</Version>
13+
</PropertyGroup>
14+
15+
</Project>
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
using System.Runtime.CompilerServices;
2+
3+
[assembly: InternalsVisibleTo("Inasync.TestAA.Tests")]

0 commit comments

Comments
 (0)