forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCallBackValidatorAttributeTests.cs
More file actions
105 lines (94 loc) · 3.71 KB
/
CallBackValidatorAttributeTests.cs
File metadata and controls
105 lines (94 loc) · 3.71 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
95
96
97
98
99
100
101
102
103
104
105
// 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 Xunit;
namespace System.Configuration
{
public class CallBackValidatorAttributeTests
{
[Fact]
public void GetValidatorInstance_DefaultConstructorThrows()
{
var testCallBackValidatorAttribute = new CallbackValidatorAttribute();
Assert.Throws<ArgumentNullException>(() => testCallBackValidatorAttribute.ValidatorInstance);
}
[Fact]
public void GetValidatorInstance_CallBackMethodNullThrows()
{
var testCallBackValidatorAttribute = new CallbackValidatorAttribute
{
Type = typeof(double)
};
Assert.Throws<ArgumentException>(() => testCallBackValidatorAttribute.ValidatorInstance);
}
[Fact]
public void GetValidatorInstance_MethdoInfoNotNullThrows()
{
var testCallBackValidatorAttribute = new CallbackValidatorAttribute
{
Type = typeof(double),
CallbackMethodName = "Test"
};
Assert.Throws<ArgumentException>(() => testCallBackValidatorAttribute.ValidatorInstance);
}
[Fact]
public void GetValidatorInstance_Success()
{
var testCallBackValidatorAttribute = new CallbackValidatorAttribute
{
Type = typeof(CallBackValidatorAttributeTests),
CallbackMethodName = "CallBackValidatorTestMethod"
};
var response = testCallBackValidatorAttribute.ValidatorInstance;
Assert.IsType<CallbackValidator>(response);
}
//Calls twice to test both branches of the _callbackmethod == null if statement
[Fact]
public void SuccessfulCallback_CallTwice()
{
var testCallBackValidatorAttribute = new CallbackValidatorAttribute
{
Type = typeof(CallBackValidatorAttributeTests),
CallbackMethodName = "CallBackValidatorTestMethod"
};
var response = testCallBackValidatorAttribute.ValidatorInstance;
Assert.IsType<CallbackValidator>(testCallBackValidatorAttribute.ValidatorInstance);
}
[Fact]
public void GetValidatorInstance_MethodHasTooManyParameters()
{
var testCallBackValidatorAttribute = new CallbackValidatorAttribute
{
Type = typeof(CallBackValidatorAttributeTests),
CallbackMethodName = "CallBackValidatorTestMethodNumberTwo"
};
Assert.Throws<ArgumentException>(() => testCallBackValidatorAttribute.ValidatorInstance);
}
[Fact]
public void TypeIsExpected()
{
var testCallBackValidatorAttribute = new CallbackValidatorAttribute
{
Type = typeof(double)
};
Assert.Equal(typeof(double), testCallBackValidatorAttribute.Type);
}
[Fact]
public void MethodNameIsExpected()
{
var testCallBackValidatorAttribute = new CallbackValidatorAttribute
{
CallbackMethodName = "12345"
};
Assert.Equal("12345", testCallBackValidatorAttribute.CallbackMethodName);
}
#pragma warning disable xUnit1013 // Required to be public for CallbackValidatorAttribute to work
public static void CallBackValidatorTestMethod(object o)
{
}
public static void CallBackValidatorTestMethodNumberTwo(object o, object p)
{
}
#pragma warning restore xUnit1013
}
}