-
Notifications
You must be signed in to change notification settings - Fork 4.7k
/
CodeParameterDeclarationExpressionTests.cs
139 lines (122 loc) · 5.84 KB
/
CodeParameterDeclarationExpressionTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Collections.Generic;
using System.Linq;
using Xunit;
namespace System.CodeDom.Tests
{
public class CodeParameterDeclarationExpressionTests : CodeObjectTestBase<CodeParameterDeclarationExpression>
{
[Fact]
public void Ctor_Default()
{
var parameter = new CodeParameterDeclarationExpression();
Assert.Empty(parameter.CustomAttributes);
Assert.Equal(FieldDirection.In, parameter.Direction);
Assert.Equal(typeof(void).FullName, parameter.Type.BaseType);
Assert.Empty(parameter.Name);
}
public static IEnumerable<object[]> Ctor_CodeTypeReference_String_TestData()
{
yield return new object[] { null, null };
yield return new object[] { new CodeTypeReference(), "" };
yield return new object[] { new CodeTypeReference(typeof(int)), "Name" };
}
[Theory]
[MemberData(nameof(Ctor_CodeTypeReference_String_TestData))]
public void Ctor_CodeTypeReference_String(CodeTypeReference type, string name)
{
var parameter = new CodeParameterDeclarationExpression(type, name);
Assert.Empty(parameter.CustomAttributes);
Assert.Equal(FieldDirection.In, parameter.Direction);
Assert.Equal((type ?? new CodeTypeReference("")).BaseType, parameter.Type.BaseType);
Assert.Equal(name ?? string.Empty, parameter.Name);
}
public static IEnumerable<object[]> Ctor_String_String_TestData()
{
yield return new object[] { null, null, "System.Void" };
yield return new object[] { "", "", "System.Void" };
yield return new object[] { "Int32", "Name", "Int32" };
}
[Theory]
[MemberData(nameof(Ctor_String_String_TestData))]
public void Ctor_String_String(string type, string name, string expectedBaseType)
{
var parameter = new CodeParameterDeclarationExpression(type, name);
Assert.Empty(parameter.CustomAttributes);
Assert.Equal(FieldDirection.In, parameter.Direction);
Assert.Equal(expectedBaseType, parameter.Type.BaseType);
Assert.Equal(name ?? string.Empty, parameter.Name);
}
public static IEnumerable<object[]> Ctor_Type_String_TestData()
{
yield return new object[] { typeof(int), null, "System.Int32" };
yield return new object[] { typeof(List<>), "", "System.Collections.Generic.List`1" };
yield return new object[] { typeof(void), "Name", "System.Void" };
}
[Theory]
[MemberData(nameof(Ctor_Type_String_TestData))]
public void Ctor_Type_String(Type type, string name, string expectedBaseType)
{
var parameter = new CodeParameterDeclarationExpression(type, name);
Assert.Empty(parameter.CustomAttributes);
Assert.Equal(FieldDirection.In, parameter.Direction);
Assert.Equal(expectedBaseType, parameter.Type.BaseType);
Assert.Equal(name ?? string.Empty, parameter.Name);
}
[Fact]
public void CustomAttributes_SetNull_Get_ReturnsEmpty()
{
var parameter = new CodeParameterDeclarationExpression() { CustomAttributes = null };
Assert.Empty(parameter.CustomAttributes);
}
[Fact]
public void CustomAttributes_SetNonNull_Get_ReturnsExpected()
{
var parameter = new CodeParameterDeclarationExpression() { CustomAttributes = null };
CodeAttributeDeclarationCollection value = new CodeAttributeDeclarationCollection();
value.Add(new CodeAttributeDeclaration("Name1"));
value.Add(new CodeAttributeDeclaration("Name2"));
parameter.CustomAttributes = value;
Assert.Equal(value, parameter.CustomAttributes);
}
[Fact]
public void CustomAttributes_AddMultiple_ReturnsExpected()
{
var parameter = new CodeParameterDeclarationExpression();
CodeAttributeDeclaration attribute1 = new CodeAttributeDeclaration("Name1");
parameter.CustomAttributes.Add(attribute1);
Assert.Equal(new CodeAttributeDeclaration[] { attribute1 }, parameter.CustomAttributes.Cast<CodeAttributeDeclaration>());
CodeAttributeDeclaration attribute2 = new CodeAttributeDeclaration("Name2");
parameter.CustomAttributes.Add(attribute2);
Assert.Equal(new CodeAttributeDeclaration[] { attribute1, attribute2 }, parameter.CustomAttributes.Cast<CodeAttributeDeclaration>());
}
[Theory]
[InlineData(FieldDirection.In - 1)]
[InlineData(FieldDirection.In)]
[InlineData(FieldDirection.In | FieldDirection.Out)]
[InlineData(FieldDirection.Ref + 1)]
public void Direction_Set_Get_ReturnsExpected(FieldDirection value)
{
var parameter = new CodeParameterDeclarationExpression();
parameter.Direction = value;
Assert.Equal(value, parameter.Direction);
}
[Theory]
[MemberData(nameof(CodeTypeReference_TestData))]
public void Type_Set_Get_ReturnsExpected(CodeTypeReference value)
{
var parameter = new CodeParameterDeclarationExpression();
parameter.Type = value;
Assert.Equal((value ?? new CodeTypeReference("")).BaseType, parameter.Type.BaseType);
}
[Theory]
[MemberData(nameof(String_TestData))]
public void Name_Set_Get_ReturnsExpected(string value)
{
var parameter = new CodeParameterDeclarationExpression();
parameter.Name = value;
Assert.Equal(value ?? string.Empty, parameter.Name);
}
}
}