forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodeMemberFieldTests.cs
More file actions
72 lines (63 loc) · 2.49 KB
/
CodeMemberFieldTests.cs
File metadata and controls
72 lines (63 loc) · 2.49 KB
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
// 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 Xunit;
namespace System.CodeDom.Tests
{
public class CodeMemberFieldTests : CodeTypeMemberTestBase<CodeMemberField>
{
[Fact]
public void Ctor_Default()
{
var field = new CodeMemberField();
Assert.Equal(typeof(void).FullName, field.Type.BaseType);
Assert.Null(field.InitExpression);
}
[Theory]
[MemberData(nameof(CodeTypeReference_TestData))]
public void Ctor_CodeTypeReference_String(CodeTypeReference type)
{
var field = new CodeMemberField(type, "name");
Assert.Equal((type ?? new CodeTypeReference("")).BaseType, field.Type.BaseType);
Assert.Equal("name", field.Name);
}
[Theory]
[MemberData(nameof(CodeTypeReference_TestData))]
public void Ctor_Type_String(CodeTypeReference type)
{
if (type == null)
{
return;
}
var field = new CodeMemberField(type.BaseType, "name");
Assert.Equal(type.BaseType, field.Type.BaseType);
Assert.Equal("name", field.Name);
}
[Fact]
public void Ctor_Type_String_NullType_ThrowsArgumentNullException()
{
AssertExtensions.Throws<ArgumentNullException>("type", () => new CodeMemberField((Type)null, "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 field = new CodeMemberField(type, name);
Assert.Equal(expectedBaseType, field.Type.BaseType);
Assert.Equal(name ?? string.Empty, field.Name);
}
[Theory]
[MemberData(nameof(CodeTypeReference_TestData))]
public void Type_Set_Get_ReturnsExpected(CodeTypeReference type)
{
var field = new CodeMemberField() { Type = type };
Assert.Equal((type ?? new CodeTypeReference("")).BaseType, field.Type.BaseType);
}
}
}