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
|
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System.Linq.Expressions;
using System.Reflection;
using Xunit;
namespace System.Web.Mvc.ExpressionUtil.Test
{
public class UnaryExpressionFingerprintTest
{
[Fact]
public void Properties()
{
// Arrange
ExpressionType expectedNodeType = ExpressionType.Not;
Type expectedType = typeof(int);
MethodInfo expectedMethod = typeof(object).GetMethod("GetHashCode");
// Act
UnaryExpressionFingerprint fingerprint = new UnaryExpressionFingerprint(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.Not;
Type type = typeof(int);
MethodInfo method = typeof(object).GetMethod("GetHashCode");
// Act
UnaryExpressionFingerprint fingerprint1 = new UnaryExpressionFingerprint(nodeType, type, method);
UnaryExpressionFingerprint fingerprint2 = new UnaryExpressionFingerprint(nodeType, type, method);
// Assert
Assert.Equal(fingerprint1, fingerprint2);
Assert.Equal(fingerprint1.GetHashCode(), fingerprint2.GetHashCode());
}
[Fact]
public void Comparison_Inequality_FingerprintType()
{
// Arrange
ExpressionType nodeType = ExpressionType.Not;
Type type = typeof(int);
MethodInfo method = typeof(object).GetMethod("GetHashCode");
// Act
UnaryExpressionFingerprint fingerprint1 = new UnaryExpressionFingerprint(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.Not;
Type type = typeof(int);
MethodInfo method = typeof(object).GetMethod("GetHashCode");
// Act
UnaryExpressionFingerprint fingerprint1 = new UnaryExpressionFingerprint(nodeType, type, method);
UnaryExpressionFingerprint fingerprint2 = new UnaryExpressionFingerprint(nodeType, type, null /* method */);
// Assert
Assert.NotEqual(fingerprint1, fingerprint2);
}
[Fact]
public void Comparison_Inequality_Type()
{
// Arrange
ExpressionType nodeType = ExpressionType.Not;
Type type = typeof(int);
MethodInfo method = typeof(object).GetMethod("GetHashCode");
// Act
UnaryExpressionFingerprint fingerprint1 = new UnaryExpressionFingerprint(nodeType, type, method);
UnaryExpressionFingerprint fingerprint2 = new UnaryExpressionFingerprint(nodeType, typeof(object), method);
// Assert
Assert.NotEqual(fingerprint1, fingerprint2);
}
}
}
|