Repository navigation
Expand file tree
/
Copy pathBinaryExpressionFingerprintTest.cs
More file actions
94 lines (78 loc) · 3.73 KB
/
Copy pathBinaryExpressionFingerprintTest.cs
File metadata and controls
94 lines (78 loc) · 3.73 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
88
89
90
91
92
93
94
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Linq.Expressions;
using System.Reflection;
using Microsoft.TestCommon;
namespace System.Web.Mvc.ExpressionUtil.Test
{
public class BinaryExpressionFingerprintTest
{
[Fact]
public void Properties()
{
// Arrange
ExpressionType expectedNodeType = ExpressionType.Add;
Type expectedType = typeof(DateTime);
MethodInfo expectedMethod = typeof(DateTime).GetMethod("op_Addition", new Type[] { typeof(DateTime), typeof(TimeSpan) });
// Act
BinaryExpressionFingerprint fingerprint = new BinaryExpressionFingerprint(expectedNodeType, expectedType, expectedMethod);
// Assert
Assert.Equal(expectedNodeType, fingerprint.NodeType);
Assert.Equal(expectedType, fingerprint.Type);
Assert.Equal(expectedMethod, fingerprint.Method);
}
[Fact]
public void Comparison_Equality()
{
// Arrange
ExpressionType nodeType = ExpressionType.Add;
Type type = typeof(DateTime);
MethodInfo method = typeof(DateTime).GetMethod("op_Addition", new Type[] { typeof(DateTime), typeof(TimeSpan) });
// Act
BinaryExpressionFingerprint fingerprint1 = new BinaryExpressionFingerprint(nodeType, type, method);
BinaryExpressionFingerprint fingerprint2 = new BinaryExpressionFingerprint(nodeType, type, method);
// Assert
Assert.Equal(fingerprint1, fingerprint2);
Assert.Equal(fingerprint1.GetHashCode(), fingerprint2.GetHashCode());
}
[Fact]
public void Comparison_Inequality_FingerprintType()
{
// Arrange
ExpressionType nodeType = ExpressionType.Add;
Type type = typeof(DateTime);
MethodInfo method = typeof(DateTime).GetMethod("op_Addition", new Type[] { typeof(DateTime), typeof(TimeSpan) });
// Act
BinaryExpressionFingerprint fingerprint1 = new BinaryExpressionFingerprint(nodeType, type, method);
DummyExpressionFingerprint fingerprint2 = new DummyExpressionFingerprint(nodeType, type);
// Assert
Assert.NotEqual<ExpressionFingerprint>(fingerprint1, fingerprint2);
}
[Fact]
public void Comparison_Inequality_Method()
{
// Arrange
ExpressionType nodeType = ExpressionType.Add;
Type type = typeof(DateTime);
MethodInfo method = typeof(DateTime).GetMethod("op_Addition", new Type[] { typeof(DateTime), typeof(TimeSpan) });
// Act
BinaryExpressionFingerprint fingerprint1 = new BinaryExpressionFingerprint(nodeType, type, method);
BinaryExpressionFingerprint fingerprint2 = new BinaryExpressionFingerprint(nodeType, type, null /* method */);
// Assert
Assert.NotEqual(fingerprint1, fingerprint2);
}
[Fact]
public void Comparison_Inequality_Type()
{
// Arrange
ExpressionType nodeType = ExpressionType.Add;
Type type = typeof(DateTime);
MethodInfo method = typeof(DateTime).GetMethod("op_Addition", new Type[] { typeof(DateTime), typeof(TimeSpan) });
// Act
BinaryExpressionFingerprint fingerprint1 = new BinaryExpressionFingerprint(nodeType, type, method);
BinaryExpressionFingerprint fingerprint2 = new BinaryExpressionFingerprint(nodeType, typeof(object), method);
// Assert
Assert.NotEqual(fingerprint1, fingerprint2);
}
}
}