Skip to content

Commit

Permalink
Initial commit of System.Reflection.Emit.ILGeneration.
Browse files Browse the repository at this point in the history
  • Loading branch information
dotnet-bot authored and Lakshmi Priya Sekar committed Jun 2, 2015
1 parent 7aa7b9d commit 39252e0
Show file tree
Hide file tree
Showing 39 changed files with 7,078 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.22609.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Reflection.Emit.ILGeneration.Tests", "tests\System.Reflection.Emit.ILGeneration.Tests.csproj", "{FB037640-0591-4DF4-A331-0BEFE50A200B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{FB037640-0591-4DF4-A331-0BEFE50A200B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FB037640-0591-4DF4-A331-0BEFE50A200B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FB037640-0591-4DF4-A331-0BEFE50A200B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FB037640-0591-4DF4-A331-0BEFE50A200B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;

using System.Reflection.Emit;
using System.Linq;
using Xunit;

namespace System.Reflection.Emit.ILGeneration.Tests
{
public class CustomAttributeBuilderCtor1
{
[Fact]
public void PosTest1()
{
string str = "PosTest1";
Type[] ctorParams = new Type[] { typeof(string) };
object[] paramValues = new object[] { str };
CustomAttributeBuilder cab = new CustomAttributeBuilder(
typeof(ObsoleteAttribute).GetConstructor(ctorParams), paramValues);

Assert.NotNull(cab);
}

[Fact]
public void PosTest2()
{
Type[] ctorParams = new Type[] { };
object[] paramValues = new object[] { };

CustomAttributeBuilder cab = new CustomAttributeBuilder(
typeof(ObsoleteAttribute).GetConstructor(ctorParams), paramValues);

Assert.NotNull(cab);
}

[Fact]
public void PosTest3()
{
string str = "PosTest3";
bool b = TestLibrary.Generator.GetByte(-55) > Byte.MaxValue / 2;

Type[] ctorParams = new Type[] { typeof(string), typeof(bool) };
object[] paramValues = new object[] { str, b };

CustomAttributeBuilder cab = new CustomAttributeBuilder(
typeof(ObsoleteAttribute).GetConstructor(ctorParams), paramValues);

Assert.NotNull(cab);
}

[Fact]
public void NegTest1()
{
object[] paramValues = new object[] { };

Assert.Throws<ArgumentException>(() =>
{
CustomAttributeBuilder cab = new CustomAttributeBuilder(
typeof(TestConstructor).GetConstructors(BindingFlags.Static | BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic)
.Where(c => c.IsStatic).First(), paramValues);
});
}

[Fact]
public void NegTest2()
{
object[] paramValues = new object[]
{
false
};

Assert.Throws<ArgumentException>(() =>
{
CustomAttributeBuilder cab = new CustomAttributeBuilder(
typeof(TestConstructor).GetConstructors(BindingFlags.Static | BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic)
.Where(c => c.IsPrivate).First(), paramValues);
});
}

[Fact]
public void NegTest3()
{
string str = "NegTest3";
bool b = false;

Type[] ctorParams = new Type[] { typeof(string) };
object[] paramValues = new object[] { str, b };

Assert.Throws<ArgumentException>(() =>
{
CustomAttributeBuilder cab = new CustomAttributeBuilder(
typeof(ObsoleteAttribute).GetConstructor(ctorParams), paramValues);
});
}

[Fact]
public void NegTest4()
{
string str = "NegTest4";
bool b = true;

Type[] ctorParams = new Type[] { typeof(string), typeof(bool) };
object[] paramValues = new object[] { b, str };

Assert.Throws<ArgumentException>(() =>
{
CustomAttributeBuilder cab = new CustomAttributeBuilder(
typeof(ObsoleteAttribute).GetConstructor(ctorParams), paramValues);
});
}

[Fact]
public void NegTest5()
{
string str = "NegTest5";
bool b = false;

object[] paramValues = new object[] { str, b };

Assert.Throws<ArgumentNullException>(() =>
{
CustomAttributeBuilder cab = new CustomAttributeBuilder(
null, paramValues);
});
}

[Fact]
public void NegTest6()
{
Type[] ctorParams = new Type[] { typeof(bool), typeof(string) };

Assert.Throws<ArgumentNullException>(() =>
{
CustomAttributeBuilder cab = new CustomAttributeBuilder(
typeof(ObsoleteAttribute).GetConstructor(ctorParams), null);
});
}
}

public class TestConstructor
{
static TestConstructor() { }
internal TestConstructor(bool b) { }
}
}
Loading

0 comments on commit 39252e0

Please sign in to comment.