forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodeCastExpressionTests.cs
More file actions
87 lines (77 loc) · 3.59 KB
/
CodeCastExpressionTests.cs
File metadata and controls
87 lines (77 loc) · 3.59 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections.Generic;
using Xunit;
namespace System.CodeDom.Tests
{
public class CodeCastExpressionTests : CodeObjectTestBase<CodeCastExpression>
{
[Fact]
public void Ctor_Default()
{
var cast = new CodeCastExpression();
Assert.Equal(typeof(void).FullName, cast.TargetType.BaseType);
Assert.Null(cast.Expression);
}
public static IEnumerable<object[]> Ctor_CodeTypeReference_TestData()
{
yield return new object[] { null, null };
yield return new object[] { new CodeTypeReference(), new CodePrimitiveExpression() };
yield return new object[] { new CodeTypeReference(typeof(void)), new CodePrimitiveExpression("Value") };
}
[Theory]
[MemberData(nameof(Ctor_CodeTypeReference_TestData))]
public void Ctor_CodeTypeReference_CodeExpression(CodeTypeReference type, CodeExpression expression)
{
CodeExpression[] initializers = new CodeExpression[0];
var cast = new CodeCastExpression(type, expression);
Assert.Equal((type ?? new CodeTypeReference("")).BaseType, cast.TargetType.BaseType);
Assert.Equal(expression, cast.Expression);
}
public static IEnumerable<object[]> Ctor_TypeString_TestData()
{
yield return new object[] { null, null, "System.Void" };
yield return new object[] { "", new CodePrimitiveExpression(), "System.Void" };
yield return new object[] { "Int32", new CodePrimitiveExpression("Value"), "Int32" };
}
[Theory]
[MemberData(nameof(Ctor_TypeString_TestData))]
public void Ctor_String_CodeExpression(string type, CodeExpression expression, string expectedBaseType)
{
var cast = new CodeCastExpression(type, expression);
Assert.Equal(expectedBaseType, cast.TargetType.BaseType);
Assert.Equal(expression, cast.Expression);
}
public static IEnumerable<object[]> Ctor_Type_TestData()
{
yield return new object[] { typeof(int), null, "System.Int32" };
yield return new object[] { typeof(List<>), new CodePrimitiveExpression(), "System.Collections.Generic.List`1" };
yield return new object[] { typeof(void), new CodePrimitiveExpression("Value"), "System.Void" };
}
[Theory]
[MemberData(nameof(Ctor_Type_TestData))]
public void Ctor_Type_CodeExpression(Type type, CodeExpression expression, string expectedBaseType)
{
var cast = new CodeCastExpression(type, expression);
Assert.Equal(expectedBaseType, cast.TargetType.BaseType);
Assert.Equal(expression, cast.Expression);
}
[Theory]
[MemberData(nameof(CodeTypeReference_TestData))]
public void TargetType_Set_Get_ReturnsExpected(CodeTypeReference value)
{
var cast = new CodeCastExpression();
cast.TargetType = value;
Assert.Equal((value ?? new CodeTypeReference("")).BaseType, cast.TargetType.BaseType);
}
[Theory]
[MemberData(nameof(CodeExpression_TestData))]
public void Expression_Set_Get_ReturnsExpected(CodeExpression value)
{
var cast = new CodeCastExpression();
cast.Expression = value;
Assert.Equal(value, cast.Expression);
}
}
}