-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Expand file tree
/
Copy pathCustomAttributeDataTests.cs
More file actions
84 lines (73 loc) · 2.82 KB
/
CustomAttributeDataTests.cs
File metadata and controls
84 lines (73 loc) · 2.82 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
// 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.Reflection.Context.Tests
{
// Test for CustomAttributeData projections
public class CustomAttributeDataTests
{
private readonly CustomReflectionContext _customReflectionContext = new TestCustomReflectionContext();
private readonly TypeInfo _customTypeInfo;
private readonly CustomAttributeData _customAttributeData;
public CustomAttributeDataTests()
{
TypeInfo typeInfo = typeof(TypeWithProperties).GetTypeInfo();
_customTypeInfo = _customReflectionContext.MapType(typeInfo);
PropertyInfo property = _customTypeInfo.GetProperty("AttributedProperty");
_customAttributeData = property.GetCustomAttributesData().FirstOrDefault();
}
[Fact]
public void CustomAttributeData_Exists()
{
Assert.NotNull(_customAttributeData);
}
[Fact]
public void AttributeType_ReturnsProjectedType()
{
Type attrType = _customAttributeData.AttributeType;
Assert.NotNull(attrType);
Assert.Equal(ProjectionConstants.CustomType, attrType.GetType().FullName);
}
[Fact]
public void Constructor_ReturnsProjectedConstructor()
{
ConstructorInfo ctor = _customAttributeData.Constructor;
Assert.NotNull(ctor);
}
[Fact]
public void ConstructorArguments_ReturnsEmptyForParameterlessAttribute()
{
IList<CustomAttributeTypedArgument> args = _customAttributeData.ConstructorArguments;
Assert.Empty(args);
}
[Fact]
public void NamedArguments_ReturnsEmptyForSimpleAttribute()
{
IList<CustomAttributeNamedArgument> args = _customAttributeData.NamedArguments;
Assert.Empty(args);
}
[Fact]
public void ToString_ContainsAttributeTypeName()
{
string str = _customAttributeData.ToString();
Assert.NotNull(str);
Assert.NotEmpty(str);
}
[Fact]
public void Equals_DifferentInstance_ReturnsFalse()
{
PropertyInfo property = _customTypeInfo.GetProperty("AttributedProperty");
CustomAttributeData otherData = property.GetCustomAttributesData().FirstOrDefault();
Assert.False(_customAttributeData.Equals(otherData));
}
[Fact]
public void GetHashCode_IsIdempotent()
{
int hashCode1 = _customAttributeData.GetHashCode();
int hashCode2 = _customAttributeData.GetHashCode();
Assert.Equal(hashCode1, hashCode2);
}
}
}