Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 6226545

Browse files
committed
Merge pull request #1901 from Priya91/githubmove
Initial commit of System.Reflection.Emit.ILGeneration.
2 parents 80666a0 + e76f951 commit 6226545

39 files changed

+6874
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 14
4+
VisualStudioVersion = 14.0.22609.0
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Reflection.Emit.ILGeneration.Tests", "tests\System.Reflection.Emit.ILGeneration.Tests.csproj", "{FB037640-0591-4DF4-A331-0BEFE50A200B}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{FB037640-0591-4DF4-A331-0BEFE50A200B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{FB037640-0591-4DF4-A331-0BEFE50A200B}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{FB037640-0591-4DF4-A331-0BEFE50A200B}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{FB037640-0591-4DF4-A331-0BEFE50A200B}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System;
5+
6+
using System.Reflection.Emit;
7+
using System.Linq;
8+
using Xunit;
9+
10+
namespace System.Reflection.Emit.ILGeneration.Tests
11+
{
12+
public class CustomAttributeBuilderCtor1
13+
{
14+
[Fact]
15+
public void PosTest1()
16+
{
17+
string str = "PosTest1";
18+
Type[] ctorParams = new Type[] { typeof(string) };
19+
object[] paramValues = new object[] { str };
20+
CustomAttributeBuilder cab = new CustomAttributeBuilder(
21+
typeof(ObsoleteAttribute).GetConstructor(ctorParams), paramValues);
22+
23+
Assert.NotNull(cab);
24+
}
25+
26+
[Fact]
27+
public void PosTest2()
28+
{
29+
Type[] ctorParams = new Type[] { };
30+
object[] paramValues = new object[] { };
31+
32+
CustomAttributeBuilder cab = new CustomAttributeBuilder(
33+
typeof(ObsoleteAttribute).GetConstructor(ctorParams), paramValues);
34+
35+
Assert.NotNull(cab);
36+
}
37+
38+
[Fact]
39+
public void PosTest3()
40+
{
41+
string str = "PosTest3";
42+
bool b = TestLibrary.Generator.GetByte() > byte.MaxValue / 2;
43+
44+
Type[] ctorParams = new Type[] { typeof(string), typeof(bool) };
45+
object[] paramValues = new object[] { str, b };
46+
47+
CustomAttributeBuilder cab = new CustomAttributeBuilder(
48+
typeof(ObsoleteAttribute).GetConstructor(ctorParams), paramValues);
49+
50+
Assert.NotNull(cab);
51+
}
52+
53+
[Fact]
54+
public void NegTest1()
55+
{
56+
object[] paramValues = new object[] { };
57+
58+
Assert.Throws<ArgumentException>(() =>
59+
{
60+
CustomAttributeBuilder cab = new CustomAttributeBuilder(
61+
typeof(TestConstructor).GetConstructors(BindingFlags.Static | BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic)
62+
.Where(c => c.IsStatic).First(), paramValues);
63+
});
64+
}
65+
66+
[Fact]
67+
public void NegTest2()
68+
{
69+
object[] paramValues = new object[]
70+
{
71+
false
72+
};
73+
74+
Assert.Throws<ArgumentException>(() =>
75+
{
76+
CustomAttributeBuilder cab = new CustomAttributeBuilder(
77+
typeof(TestConstructor).GetConstructors(BindingFlags.Static | BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic)
78+
.Where(c => c.IsPrivate).First(), paramValues);
79+
});
80+
}
81+
82+
[Fact]
83+
public void NegTest3()
84+
{
85+
string str = "NegTest3";
86+
bool b = false;
87+
88+
Type[] ctorParams = new Type[] { typeof(string) };
89+
object[] paramValues = new object[] { str, b };
90+
91+
Assert.Throws<ArgumentException>(() =>
92+
{
93+
CustomAttributeBuilder cab = new CustomAttributeBuilder(
94+
typeof(ObsoleteAttribute).GetConstructor(ctorParams), paramValues);
95+
});
96+
}
97+
98+
[Fact]
99+
public void NegTest4()
100+
{
101+
string str = "NegTest4";
102+
bool b = true;
103+
104+
Type[] ctorParams = new Type[] { typeof(string), typeof(bool) };
105+
object[] paramValues = new object[] { b, str };
106+
107+
Assert.Throws<ArgumentException>(() =>
108+
{
109+
CustomAttributeBuilder cab = new CustomAttributeBuilder(
110+
typeof(ObsoleteAttribute).GetConstructor(ctorParams), paramValues);
111+
});
112+
}
113+
114+
[Fact]
115+
public void NegTest5()
116+
{
117+
string str = "NegTest5";
118+
bool b = false;
119+
120+
object[] paramValues = new object[] { str, b };
121+
122+
Assert.Throws<ArgumentNullException>(() =>
123+
{
124+
CustomAttributeBuilder cab = new CustomAttributeBuilder(
125+
null, paramValues);
126+
});
127+
}
128+
129+
[Fact]
130+
public void NegTest6()
131+
{
132+
Type[] ctorParams = new Type[] { typeof(bool), typeof(string) };
133+
134+
Assert.Throws<ArgumentNullException>(() =>
135+
{
136+
CustomAttributeBuilder cab = new CustomAttributeBuilder(
137+
typeof(ObsoleteAttribute).GetConstructor(ctorParams), null);
138+
});
139+
}
140+
}
141+
142+
public class TestConstructor
143+
{
144+
static TestConstructor() { }
145+
internal TestConstructor(bool b) { }
146+
}
147+
}

0 commit comments

Comments
 (0)