public void Aspect_Factory_Must_Have_Factory_Method()
        {
            var test =
                @"using AspectInjector.Broker;
using System;
namespace TestNameSpace
{    
    [Aspect(Scope.Global, Factory = typeof(FakeFactory))]
    class TypeClass
    {
        public TypeClass(string value){}

        [Advice(Advice.Type.Before, Target.Method)]
        public void Before(){}
    }

    class FakeFactory {
        public object GetInstance(Type type){
            return null;
        }
    }
}";

            var expected = DiagnosticResult.From(AspectRules.AspectFactoryMustContainFactoryMethod.AsDescriptor(), 5, 6);

            VerifyCSharpDiagnostic(test, expected);
        }
        public void Aspect_Must_Not_Be_Static()
        {
            var test =
                @"using AspectInjector.Broker;
    namespace TestNameSpace
    {
            [Aspect(Scope.Global)]
            static class TypeClass
            {
        [Advice(Advice.Type.Before, Target.Method)]
        public void Before(){}
            }
    }";
            var expected = DiagnosticResult.From(AspectRules.AspectMustHaveValidSignature.AsDescriptor(), 4, 14);

            VerifyCSharpDiagnostic(test, expected);

            var fixtest =
                @"using AspectInjector.Broker;
    namespace TestNameSpace
    {
            [Aspect(Scope.Global)]
            class TypeClass
            {
        [Advice(Advice.Type.Before, Target.Method)]
        public void Before(){}
            }
    }";

            VerifyCSharpFix(test, fixtest);
        }
Exemplo n.º 3
0
        public void Mixin_Should_Implement_Interface_With_BaseClass()
        {
            var test      = @"  
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using AspectInjector.Broker;

    namespace TestNameSpace
    {
        [Mixin(typeof(IDummyInterface))]
        [Mixin(typeof(IDummyInterface2))]
        [Aspect(Scope.Global)]
        class TypeClass : object
        {   
        }

        interface IDummyInterface{}
        interface IDummyInterface2{}
        class DummyClass{}
    }";
            var expected1 = DiagnosticResult.From(EffectRules.MixinSupportsOnlyAspectInterfaces.AsDescriptor(), 12, 10);
            var expected2 = DiagnosticResult.From(EffectRules.MixinSupportsOnlyAspectInterfaces.AsDescriptor(), 13, 10);

            VerifyCSharpDiagnostic(test, expected1, expected2);

            var fixtest = @"  
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using AspectInjector.Broker;

    namespace TestNameSpace
    {
        [Mixin(typeof(IDummyInterface))]
        [Mixin(typeof(IDummyInterface2))]
        [Aspect(Scope.Global)]
        class TypeClass : object, IDummyInterface, IDummyInterface2
        {   
        }

        interface IDummyInterface{}
        interface IDummyInterface2{}
        class DummyClass{}
    }";

            VerifyCSharpFix(test, fixtest);
        }
        public void Aspect_Should_Have_Effects()
        {
            var test =
                @"using AspectInjector.Broker;
namespace TestNameSpace
{
    [Aspect(Scope.Global)]
    class TypeClass
    {
    }
}";
            var expected = DiagnosticResult.From(AspectRules.AspectShouldContainEffect.AsDescriptor(), 4, 6);

            VerifyCSharpDiagnostic(test, expected);
        }
Exemplo n.º 5
0
        public void Advice_Should_Be_Part_Of_Aspect()
        {
            var test =
                @"using AspectInjector.Broker;
namespace TestNameSpace
{
    class TypeClass
    {   
        [Advice(Kind.Before)]
        public void Before(){}
    }
}";
            var expected = DiagnosticResult.From(EffectRules.EffectMustBePartOfAspect.AsDescriptor(), 6, 10);

            VerifyCSharpDiagnostic(test, expected);
        }
        public void Argument_Should_Be_Part_Of_Advice()
        {
            var test =
                @"using AspectInjector.Broker;
namespace TestNameSpace
{
    [Aspect(Scope.Global)]
    class TypeClass
    {
        public static void Before([Argument(Source.Instance)] object i){}
    }
}";
            var expected = DiagnosticResult.From(EffectRules.ArgumentMustBePartOfAdvice.AsDescriptor(), 7, 36);

            VerifyCSharpDiagnostic(test, expected);
        }
Exemplo n.º 7
0
        public void Mixin_Should_Be_Part_Of_Aspect()
        {
            var test     = @"  
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using AspectInjector.Broker;

    namespace TestNameSpace
    {
        [Mixin(typeof(IDummyInterface))]
        class TypeClass : IDummyInterface
        {   
        }

        interface IDummyInterface{}
        class DummyClass{}
    }";
            var expected = DiagnosticResult.From(EffectRules.EffectMustBePartOfAspect.AsDescriptor(), 12, 10);

            VerifyCSharpDiagnostic(test, expected);

//            var fixtest = @"
//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//using System.Threading.Tasks;
//using System.Diagnostics;
//using AspectInjector.Broker;

//    namespace TestNameSpace
//    {
//        [Mixin(typeof(IDummyInterface))]
//        [Aspect(Scope.Global)]
//        class TypeClass : IDummyInterface
//        {
//        }

//        interface IDummyInterface{}
//        class DummyClass{}
//    }";
//            VerifyCSharpFix(test, fixtest);
        }
        public void Mixin_Should_Be_Part_Of_Aspect()
        {
            var test =
                @"using AspectInjector.Broker;
namespace TestNameSpace
{
    [Mixin(typeof(IDummyInterface))]
    class TypeClass : IDummyInterface
    {   
    }

    interface IDummyInterface{}
}";
            var expected = DiagnosticResult.From(EffectRules.EffectMustBePartOfAspect.AsDescriptor(), 4, 6);

            VerifyCSharpDiagnostic(test, expected);
        }
Exemplo n.º 9
0
        public void Advice_Must_Not_Be_Static()
        {
            var test =
                @"using AspectInjector.Broker;
namespace TestNameSpace
{
    [Aspect(Scope.Global)]
    class TypeClass
    {
        [Advice(Kind.Before)]
        public static void Before(){}
    }
}";
            var expected = DiagnosticResult.From(EffectRules.AdviceMustHaveValidSingnature.AsDescriptor(), 7, 10);

            VerifyCSharpDiagnostic(test, expected);
        }
        public void Aspect_Must_Have_Valid_Scope()
        {
            var test =
                @"using AspectInjector.Broker;
namespace TestNameSpace
{
    [Aspect((Scope)18)]
    public class TypeClass
    {
        [Advice(Advice.Type.Before)]
        public void Before(){}
    }
}";
            var expected = DiagnosticResult.From(GeneralRules.UnknownCompilationOption.AsDescriptor(), 4, 6);

            VerifyCSharpDiagnostic(test, expected);
        }
        public void Mixin_Should_Implement_Interface()
        {
            var test =
                @"using AspectInjector.Broker;
namespace TestNameSpace
{
    [Mixin(typeof(IDummyInterface))]
    [Aspect(Scope.Global)]
    class TypeClass
    {   
    }

    interface IDummyInterface{}
}";

            var expected = DiagnosticResult.From(EffectRules.MixinSupportsOnlyAspectInterfaces.AsDescriptor(), 4, 6);

            VerifyCSharpDiagnostic(test, expected);
        }
        public void Can_Mixin_Only_Interfaces()
        {
            var test =
                @"using AspectInjector.Broker;
namespace TestNameSpace
{
    [Mixin(typeof(DummyClass))]
    [Aspect(Scope.Global)]
    class TypeClass
    {   
    }

    class DummyClass{}
}";

            var expected = DiagnosticResult.From(EffectRules.MixinSupportsOnlyInterfaces.AsDescriptor(), 4, 6);

            VerifyCSharpDiagnostic(test, expected);
        }
Exemplo n.º 13
0
        public void Can_Mixin_Only_Interfaces()
        {
            var test     = @"  
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using AspectInjector.Broker;

    namespace TestNameSpace
    {
        [Mixin(typeof(DummyClass))]
        [Aspect(Scope.Global)]
        class TypeClass
        {   
        }

        interface IDummyInterface{}
        class DummyClass{}
    }";
            var expected = DiagnosticResult.From(EffectRules.MixinSupportsOnlyInterfaces.AsDescriptor(), 12, 10);

            VerifyCSharpDiagnostic(test, expected);

            //        var fixtest = @"
            //using System;
            //using System.Collections.Generic;
            //using System.Linq;
            //using System.Text;
            //using System.Threading.Tasks;
            //using System.Diagnostics;

            //namespace ConsoleApplication1
            //{
            //    class TYPENAME
            //    {
            //    }
            //}";
            //        VerifyCSharpFix(test, fixtest);
        }
        public void Aspect_Must_Have_Parameterless_Ctor()
        {
            var test =
                @"using AspectInjector.Broker;
namespace TestNameSpace
{
    [Aspect(Scope.Global)]
    class TypeClass
    {
        public TypeClass(string value){}

        [Advice(Advice.Type.Before, Target.Method)]
        public void Before(){}
    }
}";

            var expected = DiagnosticResult.From(AspectRules.AspectMustHaveContructorOrFactory.AsDescriptor(), 4, 6);

            VerifyCSharpDiagnostic(test, expected);
        }
Exemplo n.º 15
0
        public void Advice_Argument_Must_Be_Bound()
        {
            var test =
                @"using AspectInjector.Broker;
namespace TestNameSpace
{
    [Aspect(Scope.Global)]
    class TypeClass
    {
        [Advice(Kind.Before)]
        public void Before(string data, int val, [Argument(Source.Instance)] object i){ }
    }
}";

            var expected = new[] {
                DiagnosticResult.From(EffectRules.AdviceArgumentMustBeBound.AsDescriptor(), 8, 35),
                DiagnosticResult.From(EffectRules.AdviceArgumentMustBeBound.AsDescriptor(), 8, 45),
            };

            VerifyCSharpDiagnostic(test, expected);
        }
        public void Argument_Types_Must_Be_Valid()
        {
            var test =
                @"using AspectInjector.Broker;
namespace TestNameSpace
{
    [Aspect(Scope.Global)]
    class TypeClass
    {
        [Advice(Kind.Before)]
        public void Before(
            [Argument(Source.Instance)] int i,
            [Argument(Source.Type)] int t,
            [Argument(Source.Method)] int m,
            [Argument(Source.Name)] int n,
            [Argument(Source.Arguments)] int a,
            [Argument(Source.ReturnType)] int rt,
            [Argument(Source.ReturnValue)] int rv,
            [Argument(Source.Target)] int target, 
            [Argument(Source.Injections)] int inj
        )
        { }
    }
}";
            var expected = new[] {
                DiagnosticResult.From(EffectRules.ArgumentMustHaveValidType.AsDescriptor(), 9, 14),
                DiagnosticResult.From(EffectRules.ArgumentMustHaveValidType.AsDescriptor(), 10, 14),
                DiagnosticResult.From(EffectRules.ArgumentMustHaveValidType.AsDescriptor(), 11, 14),
                DiagnosticResult.From(EffectRules.ArgumentMustHaveValidType.AsDescriptor(), 12, 14),
                DiagnosticResult.From(EffectRules.ArgumentMustHaveValidType.AsDescriptor(), 13, 14),
                DiagnosticResult.From(EffectRules.ArgumentMustHaveValidType.AsDescriptor(), 14, 14),
                DiagnosticResult.From(EffectRules.ArgumentMustHaveValidType.AsDescriptor(), 15, 14),
                DiagnosticResult.From(EffectRules.ArgumentIsAlwaysNull.AsDescriptor(), 15, 14),
                DiagnosticResult.From(EffectRules.ArgumentMustHaveValidType.AsDescriptor(), 16, 14),
                DiagnosticResult.From(EffectRules.ArgumentIsAlwaysNull.AsDescriptor(), 16, 14),
                DiagnosticResult.From(EffectRules.ArgumentMustHaveValidType.AsDescriptor(), 17, 14),
            };

            VerifyCSharpDiagnostic(test, expected);
        }