public void SerializableTypesCannotDeclareInstanceEvents()
        {
            Prepare(@"using System; using System.Runtime.CompilerServices; [Serializable] sealed class C1 { event System.EventHandler Evt; }", expectErrors: true);
            Assert.That(AllErrorTexts, Has.Count.EqualTo(1));
            Assert.That(AllErrorTexts.Any(m => m.Contains("C1") && m.Contains("serializable type") && m.Contains("cannot declare instance event")));

            Prepare(@"using System.Runtime.CompilerServices; sealed class C1 : System.Record { event System.EventHandler Evt; }", expectErrors: true);
            Assert.That(AllErrorTexts, Has.Count.EqualTo(1));
            Assert.That(AllErrorTexts.Any(m => m.Contains("C1") && m.Contains("serializable type") && m.Contains("cannot declare instance event")));

            // But static events are OK
            Prepare(@"using System.Runtime.CompilerServices; [Record] sealed class C1 { static event System.EventHandler Evt; }", expectErrors: false);
            Prepare(@"using System.Runtime.CompilerServices; sealed class C1 : System.Record { static event System.EventHandler Evt; }", expectErrors: false);
        }
예제 #2
0
        public void CannotSpecifyInlineCodeOnEventAccessorsThatOverrideBaseMembers()
        {
            Prepare(
                @"using System.Runtime.CompilerServices;
class B {
	public virtual event System.EventHandler Evt;
}

class D : B {
	public sealed override event System.EventHandler Evt { [InlineCode(""X"")] add {} [InlineCode(""X"")] remove {} }
}", expectErrors: true);

            Assert.That(AllErrorTexts, Has.Count.EqualTo(2));
            Assert.That(AllErrorTexts.Any(m => m.Contains("D.add_Evt") && m.Contains("InlineCodeAttribute") && m.Contains("overrides")));
            Assert.That(AllErrorTexts.Any(m => m.Contains("D.remove_Evt") && m.Contains("InlineCodeAttribute") && m.Contains("overrides")));
        }
예제 #3
0
        public void CannotSpecifyInlineCodeOnEventAccessorsImplementingInterfaceMembers()
        {
            Prepare(
                @"using System.Runtime.CompilerServices;
interface I {
	event System.EventHandler Evt;
}

class C : I {
	public event System.EventHandler Evt { [InlineCode(""|some code|"")] add {} [InlineCode(""|some code|"")] remove {} }
}", expectErrors: true);

            Assert.That(AllErrorTexts, Has.Count.EqualTo(2));
            Assert.That(AllErrorTexts.Any(m => m.Contains("C.add_Evt") && m.Contains("InlineCodeAttribute") && m.Contains("interface member")));
            Assert.That(AllErrorTexts.Any(m => m.Contains("C.remove_Evt") && m.Contains("InlineCodeAttribute") && m.Contains("interface member")));
        }
예제 #4
0
        public void CannotSpecifyIntrinsicPropertyAttributeOnPropertiesThatOverrideBaseMembers()
        {
            Prepare(
                @"using System.Runtime.CompilerServices;
class B {
	public virtual int this[int x] { get { return 0; } set {} }
}

class D1 : B {
	[IntrinsicProperty]
	public sealed override int this[int x] { get { return 0; } set {} }
}", expectErrors: true);

            Assert.That(AllErrorTexts, Has.Count.EqualTo(1));
            Assert.That(AllErrorTexts.Any(m => m.Contains("indexer") && m.Contains("IntrinsicPropertyAttribute") && m.Contains("overrides")));
        }
예제 #5
0
        public void CannotSpecifyIntrinsicPropertyAttributeOnPropertiesImplementingInterfaceMembers()
        {
            Prepare(
                @"using System.Runtime.CompilerServices;
interface I {
	int this[int x] { get; set; }
}

class C1 : I {
	[IntrinsicProperty]
	public int this[int x] { get { return 0; } set {} }
}", expectErrors: true);

            Assert.That(AllErrorTexts, Has.Count.EqualTo(1));
            Assert.That(AllErrorTexts.Any(m => m.Contains("indexer") && m.Contains("IntrinsicPropertyAttribute") && m.Contains("interface member")));
        }
예제 #6
0
        public void CannotSpecifyInlineCodeOnIndexerAccessorsThatOverrideBaseMembers()
        {
            Prepare(
                @"using System.Runtime.CompilerServices;
class B {
	public virtual int this[int x] { get { return 0; } set {} }
}

class D : B {
	public sealed override int this[int x] { [InlineCode(""X"")] get { return 0; } [InlineCode(""X"")] set {} }
}", expectErrors: true);

            Assert.That(AllErrorTexts, Has.Count.EqualTo(2));
            Assert.That(AllErrorTexts.Any(m => m.Contains("D.get_Item") && m.Contains("InlineCodeAttribute") && m.Contains("overrides")));
            Assert.That(AllErrorTexts.Any(m => m.Contains("D.set_Item") && m.Contains("InlineCodeAttribute") && m.Contains("overrides")));
        }
예제 #7
0
        public void CannotSpecifyScriptSkipOnPropertyAccessorsThatOverrideBaseMembers()
        {
            Prepare(
                @"using System.Runtime.CompilerServices;
class B {
	public virtual int Prop { get; set; }
}

class D : B {
	public sealed override int Prop { [ScriptSkip] get { return 0; } [ScriptSkip] set {} }
}", expectErrors: true);

            Assert.That(AllErrorTexts, Has.Count.EqualTo(2));
            Assert.That(AllErrorTexts.Any(m => m.Contains("D.get_Prop") && m.Contains("ScriptSkipAttribute") && m.Contains("overrides")));
            Assert.That(AllErrorTexts.Any(m => m.Contains("D.set_Prop") && m.Contains("ScriptSkipAttribute") && m.Contains("overrides")));
        }
예제 #8
0
        public void CannotSpecifyScriptSkipOnPropertyAccessorsImplementingInterfaceMembers()
        {
            Prepare(
                @"using System.Runtime.CompilerServices;
interface I {
	int Prop { get; set; }
}

class C : I {
	public int Prop { [ScriptSkip] get { return 0; } [ScriptSkip] set {} }
}", expectErrors: true);

            Assert.That(AllErrorTexts, Has.Count.EqualTo(2));
            Assert.That(AllErrorTexts.Any(m => m.Contains("C.get_Prop") && m.Contains("ScriptSkipAttribute") && m.Contains("interface member")));
            Assert.That(AllErrorTexts.Any(m => m.Contains("C.set_Prop") && m.Contains("ScriptSkipAttribute") && m.Contains("interface member")));
        }
예제 #9
0
        public void CannotSpecifyInlineCodeOnPropertyAccessorsImplementingInterfaceMembers()
        {
            Prepare(
                @"using System.Runtime.CompilerServices;
interface I {
	int Prop { get; set; }
}

class C : I {
	public int Prop { [InlineCode(""|some code|"")] get { return 0; } [InlineCode(""|setter|{value}"")] set {} }
}", expectErrors: true);

            Assert.That(AllErrorTexts, Has.Count.EqualTo(2));
            Assert.That(AllErrorTexts.Any(m => m.Contains("C.get_Prop") && m.Contains("InlineCodeAttribute") && m.Contains("interface member")));
            Assert.That(AllErrorTexts.Any(m => m.Contains("C.set_Prop") && m.Contains("InlineCodeAttribute") && m.Contains("interface member")));
        }
 public void TestAttributeAndAsyncTestAttributeOnTheSameMethodIsAnError()
 {
     Prepare("using System.Testing; [TestFixture] public class C1 { [Test][AsyncTest] public void M() {} }", expectErrors: true);
     Assert.That(AllErrorTexts, Has.Count.EqualTo(1));
     Assert.That(AllErrorTexts.Any(m => m.Contains("TestAttribute") && m.Contains("AsyncTestAttribute")));
 }
 public void SerializableTypesCannotOverrideMembers()
 {
     TestBothKinds(@"public override string ToString() { return null; }", () => {
         Assert.That(AllErrorTexts.Any(m => m.Contains("C1") && m.Contains("ToString") && m.Contains("cannot override")));
     }, expectErrors: true);
 }