-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathAttributeTransferTests.cs
More file actions
51 lines (46 loc) · 1.86 KB
/
AttributeTransferTests.cs
File metadata and controls
51 lines (46 loc) · 1.86 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
using DevExpress.Mvvm.CodeGenerators.Tests.Included;
using NUnit.Framework;
using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using DevExpress.Mvvm.CodeGenerators.MvvmLight;
namespace MvvmLight.Mvvm.Tests {
class MyCustomAttribute : Attribute {
public MyCustomAttribute(int value, string str, bool condition, TestEnum testEnum) { }
}
namespace Included {
enum TestEnum {
Num = 1,
String = 2
}
}
[GenerateViewModel]
partial class AttributeTransfer {
const int number = 1;
[GenerateProperty]
int noAttribute;
[GenerateProperty, System.ComponentModel.DataAnnotations.Range(0, 1)]
[Required, MyCustom(number,
"Some string",
true, TestEnum.Num)]
int withMultipleAttributes;
}
[TestFixture]
public class AttributeTransferTests {
[Test]
public void AttributeTransferTest() {
var noAttributeProperty = typeof(AttributeTransfer).GetProperty(nameof(AttributeTransfer.NoAttribute));
var attributes = Attribute.GetCustomAttributes(noAttributeProperty);
var expectedAttributes = new Attribute[] { };
Assert.AreEqual(expectedAttributes, attributes);
var withMultipleAttributesProperty = typeof(AttributeTransfer).GetProperty(nameof(AttributeTransfer.WithMultipleAttributes));
attributes = Attribute.GetCustomAttributes(withMultipleAttributesProperty);
expectedAttributes = new Attribute[] {
new System.ComponentModel.DataAnnotations.RangeAttribute(0, 1),
new RequiredAttribute(),
new MyCustomAttribute(1, "Some string", true, TestEnum.Num)
};
Assert.AreEqual(expectedAttributes, attributes);
}
}
}