Imported Upstream version 5.0.0.42

Former-commit-id: fd56571888259555122d8a0f58c68838229cea2b
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2017-04-10 11:41:01 +00:00
parent 1190d13a04
commit 6bdd276d05
19939 changed files with 3099680 additions and 93811 deletions

View File

@@ -0,0 +1,84 @@
// 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 System.Collections.Generic;
using Xunit;
namespace System.Dynamic.Runtime.Tests
{
public class CallInfoTests
{
[Fact]
public void NullNames()
{
Assert.Throws<ArgumentNullException>("argNames", () => new CallInfo(0, default(string[])));
Assert.Throws<ArgumentNullException>("argNames", () => new CallInfo(0, default(IEnumerable<string>)));
}
[Fact]
public void ArgCountTooLow()
{
Assert.Throws<ArgumentException>(null, () => new CallInfo(1, "a", "b"));
}
[Fact]
public void NullName()
{
Assert.Throws<ArgumentNullException>("argNames[1]", () => new CallInfo(3, "a", null, "c"));
}
[Fact]
public void ArgCountRetained()
{
Assert.Equal(0, new CallInfo(0).ArgumentCount);
Assert.Equal(4, new CallInfo(4).ArgumentCount);
Assert.Equal(3, new CallInfo(3, "a", "b", "c").ArgumentCount);
}
[Fact]
public void ArgNamesRetained()
{
Assert.Equal(new[] { "a", "b", "c" }, new CallInfo(3, "a", "b", "c").ArgumentNames);
// Having a singleton for empty name lists isn't required by the spec,
// (any empty ReadOnlyCollection<string> will fulfill that),
// but consider the impact (possibly breaking, possibly less performant)
// before changing this.
Assert.Same(new CallInfo(0).ArgumentNames, new CallInfo(1).ArgumentNames);
}
[Fact]
public void Equality()
{
CallInfo a = new CallInfo(5, "a", "b");
CallInfo b = new CallInfo(5, "a", "b");
CallInfo c = new CallInfo(5, a.ArgumentNames);
CallInfo d = new CallInfo(5, "b", "a");
CallInfo e = new CallInfo(4, "a", "b");
CallInfo f = new CallInfo(5, "a");
CallInfo x = new CallInfo(3);
CallInfo y = new CallInfo(3);
CallInfo z = new CallInfo(2);
Assert.Equal(a, a);
Assert.Equal(a, b);
Assert.Equal(a, c);
Assert.NotEqual(a, d);
Assert.NotEqual(a, e);
Assert.NotEqual(a, f);
Assert.Equal(x, y);
Assert.NotEqual(x, z);
var dict = new Dictionary<CallInfo, int> { { a, 1 }, { x, 2 } };
Assert.Equal(1, dict[a]);
Assert.Equal(1, dict[b]);
Assert.Equal(1, dict[c]);
Assert.False(dict.ContainsKey(d));
Assert.False(dict.ContainsKey(e));
Assert.False(dict.ContainsKey(f));
Assert.Equal(2, dict[y]);
Assert.False(dict.ContainsKey(z));
}
}
}

View File

@@ -0,0 +1,11 @@
// 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.
namespace Dynamic.Tests
{
public static class Helpers
{
public static T Cast<T>(dynamic d) => (T)d;
}
}

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<BuildConfigurations>
netstandard;
</BuildConfigurations>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,44 @@
// 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.
namespace Dynamic.Operator.Tests
{
public static class LiftCommon
{
public static bool? s_bool = null;
public static byte? s_byte = null;
public static char? s_char = null;
public static decimal? s_decimal = null;
public static double? s_double = null;
public static float? s_float = null;
public static int? s_int = null;
public static long? s_long = null;
public static object s_object = new object();
public static sbyte? s_sbyte = null;
public static short? s_short = 6;
public static string s_string = "a";
public static uint? s_uint = null;
public static ulong? s_ulong = 2;
public static ushort? s_ushort = 7;
}
public static class TypeCommon
{
public static bool s_bool = true;
public static byte s_byte = 1;
public static char s_char = 'a';
public static decimal s_decimal = 1M;
public static double s_double = 10.1;
public static float s_float = 10.1f;
public static int s_int = 10;
public static long s_long = 5;
public static object s_object = new object();
public static sbyte s_sbyte = 10;
public static short s_short = 6;
public static string s_string = "a";
public static uint s_uint = 15;
public static ulong s_ulong = 2;
public static ushort s_ushort = 7;
}
}

View File

@@ -0,0 +1,185 @@
// 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 System;
using Microsoft.CSharp.RuntimeBinder;
using Xunit;
namespace Dynamic.Tests
{
public class ExplicitlyImplementedGenericInterfaceTests
{
[Fact]
public void NonGenericInterface_WithGenericMember1()
{
dynamic d = new ExplicitlyImplementedInterface1();
Assert.Throws<RuntimeBinderException>(() => d.Foo<int>());
var x = Helpers.Cast<InterfaceWithGenericMember>(d);
}
[Fact]
public void NonGenericInterface_WithGenericMember2()
{
dynamic d = new ExplicitlyImplementedInterface2();
Assert.Throws<RuntimeBinderException>(() => d.Foo<int>());
}
[Fact]
public void GenericInterface_WithNonGenericMember()
{
dynamic d = new ExplicitlyImplementedGenericInterface();
Assert.Equal(2, d.Foo());
var x = Helpers.Cast<GenericInterfaceWithNonGenericMember<int>>(d);
Assert.Throws<InvalidCastException>(() => Helpers.Cast<GenericInterfaceWithNonGenericMember<double>>(d));
}
[Fact]
public void GenericInterface_WithGenericMember1()
{
dynamic d = new ExplicitlyImplementedGenericInterfaceWithGenericMember1();
Assert.Throws<RuntimeBinderException>(() => d.Foo(1));
var x = Helpers.Cast<GenericInterfaceWithGenericMember1<int>>(d);
Assert.Throws<InvalidCastException>(() => Helpers.Cast<GenericInterfaceWithGenericMember1<double>>(d));
}
[Fact]
public void GenericInterface_WithGenericMember2()
{
dynamic d = new ExplicitlyImplementedGenericInterfaceWithGenericMember2();
Assert.Throws<RuntimeBinderException>(() => d.Foo<int>());
var x = Helpers.Cast<GenericInterfaceWithGenericMember2<int>>(d);
Assert.Throws<InvalidCastException>(() => Helpers.Cast<GenericInterfaceWithGenericMember2<double>>(d));
}
[Fact]
public void GenericInterface_WithInGenericParameter_BaseClass()
{
dynamic d = new ExplicitlyImplementedGenericInInterface<BaseClass>();
Assert.Throws<RuntimeBinderException>(() => d.Foo());
var x = Helpers.Cast<GenericInInterface<SubClass>>(d);
var y = Helpers.Cast<GenericInInterface<BaseClass>>(d);
}
[Fact]
public void GenericInterface_WithInGenericParameter_SubClass()
{
dynamic d = new ExplicitlyImplementedGenericInInterface<SubClass>();
Assert.Throws<RuntimeBinderException>(() => d.Foo());
Assert.Throws<InvalidCastException>(() => Helpers.Cast<GenericInInterface<BaseClass>>(d));
var y = Helpers.Cast<GenericInInterface<SubClass>>(d);
Assert.Throws<InvalidCastException>(() => ((GenericInInterface<BaseClass>)d).Foo(new BaseClass()));
}
[Fact]
public void GenericInterface_WithOutGenericParameter_BaseClass()
{
dynamic d = new ExplicitlyImplementedGenericOutInterface<BaseClass>();
Assert.Throws<RuntimeBinderException>(() => d.Foo());
Assert.Throws<InvalidCastException>(() => Helpers.Cast<GenericOutInterface<SubClass>>(d));
var y = Helpers.Cast<GenericOutInterface<BaseClass>>(d);
Assert.Throws<InvalidCastException>(() => ((GenericOutInterface<SubClass>)d).Foo());
}
[Fact]
public void GenericInterface_WithOutGenericParameter_SubClass()
{
dynamic d = new ExplicitlyImplementedGenericOutInterface<SubClass>();
Assert.Throws<RuntimeBinderException>(() => d.Foo());
var x = Helpers.Cast<GenericOutInterface<SubClass>>(d);
var y = Helpers.Cast<GenericOutInterface<BaseClass>>(d);
}
}
public interface InterfaceWithGenericMember
{
int Foo<T>();
int Bar();
}
public class ExplicitlyImplementedInterface1 : InterfaceWithGenericMember
{
int InterfaceWithGenericMember.Foo<T>() => 0;
public int Bar() => 1;
}
public class ExplicitlyImplementedInterface2 : InterfaceWithGenericMember
{
int InterfaceWithGenericMember.Foo<T>() => 0;
public int Foo() => 2;
public int Bar() => 1;
}
public interface GenericInterfaceWithNonGenericMember<T>
{
int Foo();
int Bar();
}
public class ExplicitlyImplementedGenericInterface : GenericInterfaceWithNonGenericMember<int>
{
int GenericInterfaceWithNonGenericMember<int>.Foo() => 0;
public int Foo() => 2;
public int Bar() => 1;
}
public interface GenericInterfaceWithGenericMember1<T>
{
int Foo(T t);
int Bar();
}
public class ExplicitlyImplementedGenericInterfaceWithGenericMember1 : GenericInterfaceWithGenericMember1<int>
{
int GenericInterfaceWithGenericMember1<int>.Foo(int i) => 0;
public int Bar() => 1;
}
public interface GenericInterfaceWithGenericMember2<T>
{
int Foo<U>();
int Bar();
}
public class ExplicitlyImplementedGenericInterfaceWithGenericMember2 : GenericInterfaceWithGenericMember2<int>
{
int GenericInterfaceWithGenericMember2<int>.Foo<U>() => 0;
public int Bar() => 1;
}
public class BaseClass { }
public class SubClass : BaseClass { }
public interface GenericInInterface<in T>
{
int Foo(T t);
}
public class ExplicitlyImplementedGenericInInterface<T> : GenericInInterface<T>
{
int GenericInInterface<T>.Foo(T t) => 0;
}
public interface GenericOutInterface<out T>
{
T Foo();
}
public class ExplicitlyImplementedGenericOutInterface<T> : GenericOutInterface<T> where T : new()
{
T GenericOutInterface<T>.Foo() => new T();
}
}

View File

@@ -0,0 +1,222 @@
// 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 System;
using Microsoft.CSharp.RuntimeBinder;
using Xunit;
namespace Dynamic.Tests
{
public class ExplicitlyImplementedInheritedInterfaceTests
{
[Fact]
public void SubInterface_BaseInterface()
{
dynamic d = new ExplicitlyImplementedBaseAndSubInterface();
Assert.Throws<RuntimeBinderException>(() => d.Foo());
var x = Helpers.Cast<BaseInterfaceWithOneMember1>(d);
var y = Helpers.Cast<SubInterfaceWithOneMember1>(d);
}
[Fact]
public void SubInterfaceOnly()
{
dynamic d = new ExplicitlyImplementedSubInterface();
Assert.Throws<RuntimeBinderException>(() => d.Foo());
var x = Helpers.Cast<BaseInterfaceWithOneMember1>(d);
var y = Helpers.Cast<SubInterfaceWithOneMember1>(d);
}
[Fact]
public void BaseInterfaceOnly()
{
dynamic d = new ExplicitlyImplementedBaseInterfaceWithTwoMembers();
Assert.Throws<RuntimeBinderException>(() => d.Foo());
Assert.Throws<InvalidCastException>(() => Helpers.Cast<SubInterfaceWithNoMembers>(d));
}
[Fact]
public void SubInterface_WithNewMember()
{
dynamic d = new ExplicitlyImplementedSubInterfaceWithNewMember();
Assert.Throws<RuntimeBinderException>(() => d.Foo());
Assert.Throws<InvalidCastException>(() => Helpers.Cast<SubInterfaceWithNoMembers>(d));
Assert.Throws<InvalidCastException>(() => ((SubInterfaceWithNoMembers)d).Foo());
}
[Fact]
public void SubInterfaceWithNewMember_SubInterfaceWithNoMembers()
{
dynamic d = new ExplicitlyImplementedSubInterfaceWithNewMemberAndSubInterfaceWithNoMembers();
Assert.Throws<RuntimeBinderException>(() => d.Foo());
var x = Helpers.Cast<SubInterfaceWithNoMembers>(d);
}
[Fact]
public void InterfaceWithTwoMembers_InSubClass()
{
dynamic d = new EmptyClass();
Assert.Throws<RuntimeBinderException>(() => d.Foo());
Assert.Throws<InvalidCastException>(() => Helpers.Cast<BaseInterfaceWithTwoMembers>(d));
Assert.Throws<InvalidCastException>(() => ((BaseInterfaceWithTwoMembers)d).Foo());
}
[Fact]
public void InterfaceWithTwoMembers_InBaseClass()
{
dynamic d = new SubClassOfExplicitlyImplementedInterfaceWithTwoMembersAndEmptySubClass();
Assert.Throws<RuntimeBinderException>(() => d.Foo());
var x = Helpers.Cast<BaseInterfaceWithTwoMembers>(d);
}
[Fact]
public void NonGenericInterface_Interface_WithTwoMembers_PartialClass()
{
dynamic d = new ExplicitlyImplementedInterfaceInPartialClass();
Assert.Throws<RuntimeBinderException>(() => d.Foo());
var x = Helpers.Cast<BaseInterfaceWithTwoMembers>(d);
}
[Fact]
public void PartialInterfaceWithTwoMembers()
{
dynamic d = new ExplicitlyImlementedPartialInterface();
Assert.Throws<RuntimeBinderException>(() => d.Foo());
var x = Helpers.Cast<PartialInterfaceWithTwoMembers>(d);
}
[Fact]
public void SubInterfaceWithOneMember_BaseClassWithOneVirtualMethod()
{
dynamic d = new ExplicitlyImplementedSubInterfaceWithOneMemberAndVirtualBaseClass();
Assert.Equal(1, d.Foo());
Assert.Equal(-1, ((SubInterfaceWithOneMember2)d).Foo());
}
}
public interface BaseInterfaceWithOneMember1
{
int Foo();
}
public interface SubInterfaceWithOneMember1 : BaseInterfaceWithOneMember1
{
int Bar();
}
public class ExplicitlyImplementedBaseAndSubInterface : BaseInterfaceWithOneMember1, SubInterfaceWithOneMember1
{
int BaseInterfaceWithOneMember1.Foo() => 0;
public int Bar() => 1;
}
public class ExplicitlyImplementedSubInterface : SubInterfaceWithOneMember1
{
int BaseInterfaceWithOneMember1.Foo() => 0;
public int Bar() => 1;
}
public interface BaseInterfaceWithTwoMembers
{
int Foo();
int Bar();
}
public interface SubInterfaceWithNoMembers : BaseInterfaceWithTwoMembers { }
public interface SubInterfaceWithNewMember : BaseInterfaceWithTwoMembers
{
new int Foo();
}
public class ExplicitlyImplementedBaseInterfaceWithTwoMembers : BaseInterfaceWithTwoMembers
{
int BaseInterfaceWithTwoMembers.Foo() => 0;
public int Bar() => 1;
}
public class ExplicitlyImplementedSubInterfaceWithNewMember : SubInterfaceWithNewMember
{
int SubInterfaceWithNewMember.Foo() => 0;
int BaseInterfaceWithTwoMembers.Foo() => 2;
public int Bar() => 1;
}
public class ExplicitlyImplementedSubInterfaceWithNewMemberAndSubInterfaceWithNoMembers : SubInterfaceWithNewMember, SubInterfaceWithNoMembers
{
int SubInterfaceWithNewMember.Foo() => 0;
int BaseInterfaceWithTwoMembers.Foo() => 2;
public int Bar() => 1;
}
public class EmptyClass { }
public class ExplicitlyImplementedInterfaceWithTwoMembersAndEmptyBaseClass : EmptyClass, BaseInterfaceWithTwoMembers
{
int BaseInterfaceWithTwoMembers.Foo() => 0;
public int Bar() => 1;
}
public class ExplicitlyImplementedInterfaceWithTwoMembersAndEmptySubClass : BaseInterfaceWithTwoMembers
{
int BaseInterfaceWithTwoMembers.Foo() => 0;
public int Bar() => 1;
}
public class SubClassOfExplicitlyImplementedInterfaceWithTwoMembersAndEmptySubClass : ExplicitlyImplementedInterfaceWithTwoMembersAndEmptySubClass { }
public partial class ExplicitlyImplementedInterfaceInPartialClass { }
public partial class ExplicitlyImplementedInterfaceInPartialClass : BaseInterfaceWithTwoMembers
{
int BaseInterfaceWithTwoMembers.Foo() => 0;
public int Bar() => 1;
}
public partial interface PartialInterfaceWithTwoMembers
{
int Foo();
}
public partial interface PartialInterfaceWithTwoMembers
{
int Bar();
}
public class ExplicitlyImlementedPartialInterface : PartialInterfaceWithTwoMembers
{
int PartialInterfaceWithTwoMembers.Foo() => 0;
public int Bar() => 1;
}
public class BaseClassWithVirtualMethod
{
public virtual int Foo() => -1;
}
public interface BaseInterfaceWithOneMember2
{
int Bar();
}
public interface SubInterfaceWithOneMember2 : BaseInterfaceWithOneMember2
{
int Foo();
}
public class ExplicitlyImplementedSubInterfaceWithOneMemberAndVirtualBaseClass : BaseClassWithVirtualMethod, SubInterfaceWithOneMember2
{
int SubInterfaceWithOneMember2.Foo() => -1;
public override int Foo() => 1;
public int Bar() => 1;
}
}

View File

@@ -0,0 +1,227 @@
// 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 System;
using Microsoft.CSharp.RuntimeBinder;
using Xunit;
namespace Dynamic.Tests
{
public class ExplicitlyImplementedBasicTests
{
[Fact]
public void NonGenericInterface_OneInterface_Class()
{
dynamic d = new OneExplicitlyImplementedNonGenericInterface1();
Assert.Throws<RuntimeBinderException>(() => d.Foo());
}
[Fact]
public void NonGenericInterface_OneInterface_Struct()
{
dynamic d = new OneExplicitlyImplementedNonGenericInterface2();
Assert.Equal(2, d.Foo());
}
[Fact]
public void NonGenericInterface_TwoInterfaces_Class1()
{
dynamic d = new TwoExplicitlyImplementedNonGenericInterface1();
Assert.Throws<RuntimeBinderException>(() => d.Foo());
var x = Helpers.Cast<NonGenericInterface2>(d);
}
[Fact]
public void NonGenericInterface_TwoInterfaces_Class2()
{
dynamic d = new TwoExplicitlyImplementedNonGenericInterface2();
Assert.Throws<RuntimeBinderException>(() => d.Foo());
var x = Helpers.Cast<NonGenericInterface3>(d);
}
[Fact]
public void NonGenericInterface_OneInterfaceClass2()
{
dynamic d = new OneExplicitlyImplementedNonGenericInterface3();
Assert.Equal(2, d.Foo());
Assert.Throws<InvalidCastException>(() => Helpers.Cast<NonGenericInterface3>(d));
Assert.Throws<InvalidCastException>(() => ((NonGenericInterface3)d).Foo());
}
[Fact]
public void NonGenericInterface_WithGetter()
{
dynamic d = new ExplicitlyImplementedInterfaceWithGetter();
Assert.Throws<RuntimeBinderException>(() => d.Property);
var x = Helpers.Cast<InterfaceWithGetter>(d);
}
[Fact]
public void NonGenericInterface_WithSetter()
{
dynamic d = new ExplicitlyImplementedInterfaceWithSetter();
Assert.Throws<RuntimeBinderException>(() => d.Prop = 1);
var x = Helpers.Cast<InterfaceWithSetter>(d);
}
[Fact]
public void NonGenericInterface_WithGetterAndSetter()
{
dynamic d = new ExplicitlyImplementedInterfaceWithGetterAndSetter();
Assert.Throws<RuntimeBinderException>(() => d.Property);
Assert.Throws<RuntimeBinderException>(() => d.Property = 1);
var x = Helpers.Cast<InterfaceWithGetterAndSetter>(d);
}
[Fact]
public void NonGenericInterface_WithEvent()
{
dynamic d = new ExplicitlyImplementedInterfaceWithEvent();
Assert.Throws<RuntimeBinderException>(() => d.Event += (Func<int, int>)(y => y));
Assert.Throws<RuntimeBinderException>(() => d.Event -= (Func<int, int>)(y => y));
var x = Helpers.Cast<InterfaceWithEvent>(d);
}
[Fact]
public void NonGenericInterface_WithIndexer()
{
dynamic d = new ExplicitlyImplementedInterfaceWithIndexer();
Assert.Throws<RuntimeBinderException>(() => d[0]);
Assert.Throws<RuntimeBinderException>(() => d[0] = 1);
var x = Helpers.Cast<InterfaceWithIndexer>(d);
}
}
public interface NonGenericInterface1
{
int Foo();
int Bar();
}
public interface NonGenericInterface2
{
int Bar();
}
public interface NonGenericInterface3
{
int Foo();
}
public class OneExplicitlyImplementedNonGenericInterface1 : NonGenericInterface1
{
int NonGenericInterface1.Foo() => 0;
public int Bar() => 1;
}
public struct OneExplicitlyImplementedNonGenericInterface2 : NonGenericInterface1
{
int NonGenericInterface1.Foo() => 0;
public int Foo() => 2;
public int Bar() => 1;
}
public class OneExplicitlyImplementedNonGenericInterface3 : NonGenericInterface1
{
int NonGenericInterface1.Foo() => 0;
public int Foo() => 2;
public int Bar() => 1;
}
public class TwoExplicitlyImplementedNonGenericInterface1 : NonGenericInterface1, NonGenericInterface2
{
int NonGenericInterface1.Foo() => 0;
public int Bar() => 1;
}
public class TwoExplicitlyImplementedNonGenericInterface2 : NonGenericInterface1, NonGenericInterface3
{
int NonGenericInterface1.Foo() => 0;
int NonGenericInterface3.Foo() => 2;
public int Bar() => 1;
}
public interface InterfaceWithSetter
{
int Property { set; }
}
public class ExplicitlyImplementedInterfaceWithSetter : InterfaceWithSetter
{
public static bool s_setterCalled;
int InterfaceWithSetter.Property
{
set { s_setterCalled = true; }
}
}
public interface InterfaceWithGetter
{
int Property { get; }
}
public class ExplicitlyImplementedInterfaceWithGetter : InterfaceWithGetter
{
public static bool s_getterCalled;
int InterfaceWithGetter.Property
{
get { s_getterCalled = true; return 2; }
}
}
public interface InterfaceWithGetterAndSetter
{
int Property { get; set; }
}
public class ExplicitlyImplementedInterfaceWithGetterAndSetter : InterfaceWithGetterAndSetter
{
public static bool s_getterCalled;
public static bool s_setterCalled;
int InterfaceWithGetterAndSetter.Property
{
get { s_getterCalled = true; return 1; }
set { s_setterCalled = true; }
}
}
public interface InterfaceWithEvent
{
event Func<int, int> Event;
}
public class ExplicitlyImplementedInterfaceWithEvent : InterfaceWithEvent
{
public static bool s_addCalled;
public static bool s_removeCalled;
event Func<int, int> InterfaceWithEvent.Event
{
add { s_addCalled = true; }
remove { s_addCalled = true; }
}
}
public interface InterfaceWithIndexer
{
long this[byte index] { get; set; }
}
public class ExplicitlyImplementedInterfaceWithIndexer : InterfaceWithIndexer
{
public static bool s_getCalled;
public static bool s_setCalled;
long InterfaceWithIndexer.this[byte index]
{
get { s_getCalled = true; return 1; }
set { s_setCalled = true; }
}
}
}

View File

@@ -0,0 +1,45 @@
// 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 System;
using System.Linq.Expressions;
namespace ManagedTests.DynamicCSharp.Conformance.dynamic.context.attribute.publickeydecl001.publickeydecl001
{
using ManagedTests.DynamicCSharp.Conformance.dynamic.context.attribute.publickeydecl001.publickeydecl001;
// <Title>
// Using PublicKey attribute as part of the InternalsVisibleTo attribute
// </Title>
// <Description>
// Using PublicKey attribute as part of the InternalsVisibleTo attribute
// </Description>
// <RelatedBugs></RelatedBugs>
// <Expects Status=success></Expects>
// <Code>
using System;
//[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("publickey001,PublicKey=002400000480000094000000060200000024000052534131000400000100010027be9b82deaeb8b98e5f455cbbde386f80f5c19516548cac1f2ffeea96f1712f51540946f2a8133c03d349cf0611788215da54989dcc88ee262c385d2c17343cf5cb969c436fb94fe399cc46f74bf0af2eb1f46aed1fb0adee16721c40ae02baf3d3d8b50a2dd6466829465db165a0f2915f74e1b67a63b4cf76c215cdba4ba6")]
public class A
{
public string returnme()
{
return "hello world";
}
int unit = 0;
public int Unit
{
get
{
return unit;
}
set
{
unit = value;
}
}
}
// </Code>
}

View File

@@ -0,0 +1,429 @@
// 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 ManagedTests.DynamicCSharp.Conformance.dynamic.context.operate.compound.evnt.negative.neg001.neg001
{
using ManagedTests.DynamicCSharp.Conformance.dynamic.context.operate.compound.evnt.negative.neg001.neg001;
// <Area> Dynamic -- compound operator</Area>
// <Title> compound operator +=/-= on event </Title>
// <Description>
// Negative: The operator is *=, /=, %=, &=, |=, ^=, <<=, >>=
// </Description>
// <RelatedBugs></RelatedBugs>
// <Expects Status=success></Expects>
// <Code>
using System;
public delegate int Dele(int i);
public class C
{
public event Dele E = x => x;
public static int Foo(int i)
{
return i;
}
public static void DynamicCSharpRunTest()
{
Assert.Equal(0, MainMethod());
}
public static int MainMethod()
{
dynamic c = new C();
int result = 0;
try
{
c.E *= new Dele(C.Foo);
}
catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException e)
{
if (ErrorVerifier.Verify(ErrorMessageId.BadBinaryOps, e.Message, "*=", "Dele", "Dele"))
result += 1;
}
try
{
c.E /= new Dele(C.Foo);
}
catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException e)
{
if (ErrorVerifier.Verify(ErrorMessageId.BadBinaryOps, e.Message, "/=", "Dele", "Dele"))
result += 2;
}
try
{
c.E %= new Dele(C.Foo);
}
catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException e)
{
if (ErrorVerifier.Verify(ErrorMessageId.BadBinaryOps, e.Message, "%=", "Dele", "Dele"))
result += 4;
}
try
{
c.E &= new Dele(C.Foo);
}
catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException e)
{
if (ErrorVerifier.Verify(ErrorMessageId.BadBinaryOps, e.Message, "&=", "Dele", "Dele"))
result += 8;
}
try
{
c.E |= new Dele(C.Foo);
}
catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException e)
{
if (ErrorVerifier.Verify(ErrorMessageId.BadBinaryOps, e.Message, "|=", "Dele", "Dele"))
result += 16;
}
try
{
c.E ^= new Dele(C.Foo);
}
catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException e)
{
if (ErrorVerifier.Verify(ErrorMessageId.BadBinaryOps, e.Message, "^=", "Dele", "Dele"))
result += 32;
}
try
{
c.E <<= new Dele(C.Foo);
}
catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException e)
{
if (ErrorVerifier.Verify(ErrorMessageId.BadBinaryOps, e.Message, "<<=", "Dele", "Dele"))
result += 64;
}
try
{
c.E >>= new Dele(C.Foo);
}
catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException e)
{
if (ErrorVerifier.Verify(ErrorMessageId.BadBinaryOps, e.Message, ">>=", "Dele", "Dele"))
result += 128;
}
if (result != 255)
{
System.Console.WriteLine("result = {0}", result);
return 1;
}
return 0;
}
public int DoEvent(int arg)
{
return this.E(arg);
}
}
// </Code>
}
namespace ManagedTests.DynamicCSharp.Conformance.dynamic.context.operate.compound.evnt.negative.neg002.neg002
{
using ManagedTests.DynamicCSharp.Conformance.dynamic.context.operate.compound.evnt.negative.neg002.neg002;
// <Area> Dynamic -- compound operator</Area>
// <Title> compound operator +=/-= on event </Title>
// <Description>
// Negative: rhs is dynamic expression with runtime non-delegate type
// </Description>
// <RelatedBugs></RelatedBugs>
// <Expects Status=success></Expects>
// <Code>
using System;
public delegate int Dele(int i);
public class C
{
public event Dele E;
public static int Foo(int i)
{
return i;
}
[Fact]
public static void DynamicCSharpRunTest()
{
Assert.Equal(0, MainMethod());
}
public static int MainMethod()
{
dynamic c = new C();
try
{
c.E += c;
}
catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException e)
{
// incorrect error message
// resolution is 'By design' so this error message should be use again
// new error message
if (ErrorVerifier.Verify(ErrorMessageId.NoImplicitConv, e.Message, "C", "Dele"))
return 0;
}
return 1;
}
public int DoEvent(int arg)
{
return this.E(arg);
}
}
// </Code>
}
namespace ManagedTests.DynamicCSharp.Conformance.dynamic.context.operate.compound.evnt.negative.neg003.neg003
{
using ManagedTests.DynamicCSharp.Conformance.dynamic.context.operate.compound.evnt.negative.neg003.neg003;
// <Area> Dynamic -- compound operator</Area>
// <Title> compound operator +=/-= on event </Title>
// <Description>
// Negative: rhs is non-matched delegate
// </Description>
// <RelatedBugs></RelatedBugs>
// <Expects Status=success></Expects>
// <Code>
using System;
public delegate int Dele(int i);
public class C
{
public event Dele E;
public static int Foo(int i)
{
return i;
}
[Fact]
public static void DynamicCSharpRunTest()
{
Assert.Equal(0, MainMethod());
}
public static int MainMethod()
{
dynamic c = new C();
int result = 0;
try
{
c.E += (Func<int, int>)(x => x);
}
catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException e)
{
if (ErrorVerifier.Verify(ErrorMessageId.NoImplicitConv, e.Message, "System.Func<int,int>", "Dele"))
result += 1;
}
try
{
c.E -= (Func<int, int>)(x => x);
}
catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException e)
{
if (ErrorVerifier.Verify(ErrorMessageId.NoImplicitConv, e.Message, "System.Func<int,int>", "Dele"))
result += 2;
}
if (result != 3)
{
System.Console.WriteLine("Result = {0}", result);
return 1;
}
return 0;
}
public int DoEvent(int arg)
{
return this.E(arg);
}
}
// </Code>
}
namespace ManagedTests.DynamicCSharp.Conformance.dynamic.context.operate.compound.evnt.negative.neg004.neg004
{
using ManagedTests.DynamicCSharp.Conformance.dynamic.context.operate.compound.evnt.negative.neg004.neg004;
// <Area> Dynamic -- compound operator</Area>
// <Title> compound operator +=/-= on event </Title>
// <Description>
// Negative: rhs is compile time known type and it's non valid type
// </Description>
// <RelatedBugs></RelatedBugs>
// <Expects Status=success></Expects>
// <Code>
using System;
public delegate int Dele(int i);
public class C
{
public event Dele E;
public static int Foo(int i)
{
return i;
}
[Fact]
public static void DynamicCSharpRunTest()
{
Assert.Equal(0, MainMethod());
}
public static int MainMethod()
{
dynamic c = new C();
int result = 0;
try
{
c.E += new C();
}
catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException e)
{
if (!ErrorVerifier.Verify(ErrorMessageId.NoImplicitConv, e.Message, "C", "Dele"))
result++;
}
try
{
c.E += 1;
} // : not type info for c.E at runtime as it's null
catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException e)
{
if (!ErrorVerifier.Verify(ErrorMessageId.NoImplicitConv, e.Message, "int", "Dele"))
result++;
;
}
try
{
c.E -= new C();
}
catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException e)
{
if (!ErrorVerifier.Verify(ErrorMessageId.NoImplicitConv, e.Message, "C", "Dele"))
result++;
;
}
try
{
c.E -= 1; // : not type info for c.E at runtime as it's null
}
catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException e)
{
if (!ErrorVerifier.Verify(ErrorMessageId.NoImplicitConv, e.Message, "int", "Dele"))
result++;
;
}
return result;
}
public int DoEvent(int arg)
{
return this.E(arg);
}
}
// </Code>
}
namespace ManagedTests.DynamicCSharp.Conformance.dynamic.context.operate.compound.evnt.negative.neg005.neg005
{
using ManagedTests.DynamicCSharp.Conformance.dynamic.context.operate.compound.evnt.negative.neg005.neg005;
// <Area> Dynamic -- compound operator</Area>
// <Title> compound operator +=/-= on event </Title>
// <Description>
// Negative: rhs is non-matched delegate and lhs is null
// </Description>
// <RelatedBugs></RelatedBugs>
// <Expects Status=success></Expects>
// <Code>
//<Expects Status=warning>\(17,23\).*CS0067</Expects>
using System;
public delegate int Dele(int i);
public class C
{
public event Dele E;
[Fact]
public static void DynamicCSharpRunTest()
{
Assert.Equal(0, MainMethod());
}
public static int MainMethod()
{
dynamic c = new C();
int result = 0;
try
{
c.E += (Func<int, int>)(x => x);
}
catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException e)
{
if (ErrorVerifier.Verify(ErrorMessageId.NoImplicitConv, e.Message, "System.Func<int,int>", "Dele"))
result += 1;
}
try
{
c.E += (Func<int, int, int>)((x, y) => x);
}
catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException e)
{
if (ErrorVerifier.Verify(ErrorMessageId.NoImplicitConv, e.Message, "System.Func<int,int,int>", "Dele"))
result += 2;
}
try
{
// - no error for -= (by design :()
// it seems that it is fixed now.
c.E -= (Func<int, int>)(x => x);
}
catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException e)
{
if (ErrorVerifier.Verify(ErrorMessageId.NoImplicitConv, e.Message, "System.Func<int,int>", "Dele"))
result += 4;
}
try
{
// - no error for -= (by design :()
c.E -= (Func<int, int, int>)((x, y) => x);
}
catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException e)
{
if (ErrorVerifier.Verify(ErrorMessageId.NoImplicitConv, e.Message, "System.Func<int,int,int>", "Dele"))
result += 8;
}
return (result == 15) ? 0 : 1;
}
}
// </Code>
}

Some files were not shown because too many files have changed in this diff Show More