Exemplo n.º 1
0
        public void IsClsCompliant()
        {
            if (AttributeTester.IsClsCompliant(parameter_type))
            {
                return;
            }

            RootContext.ToplevelTypes.Compiler.Report.Warning(3001, 1, Location, "Argument type `{0}' is not CLS-compliant", GetSignatureForError());
        }
Exemplo n.º 2
0
        public void HaveAjaxOnlyAttribute()
        {
            // Act
            var sut          = this.MockingKernel.Get <ReviewsController>();
            var hasAttribute = AttributeTester.MethodHasAttribute(() => sut.Cancel(default(int)), typeof(AjaxOnlyAttribute));

            // Assert
            Assert.IsTrue(hasAttribute);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Checks for ObsoleteAttribute presence. It's used for testing of all non-types elements
        /// </summary>
        public virtual void CheckObsoleteness(Location loc)
        {
            ObsoleteAttribute oa = GetAttributeObsolete();

            if (oa != null)
            {
                AttributeTester.Report_ObsoleteMessage(oa, GetSignatureForError(), loc, Report);
            }
        }
Exemplo n.º 4
0
        public void Have_RequiredAttributes(Type attrType)
        {
            // Arrange
            var sut = this.MockingKernel.Get <TopController>();

            // Act
            var hasAttributes = AttributeTester.MethodHasAttribute(() => sut.Breweries(), attrType);

            // Assert
            Assert.IsTrue(hasAttributes);
        }
Exemplo n.º 5
0
Arquivo: const.cs Projeto: mdae/MonoRT
        public void CheckObsoleteness(Location loc)
        {
            ObsoleteAttribute oa = AttributeTester.GetMemberObsoleteAttribute(fi);

            if (oa == null)
            {
                return;
            }

            AttributeTester.Report_ObsoleteMessage(oa, TypeManager.GetFullNameSignature(fi), loc, RootContext.ToplevelTypes.Compiler.Report);
        }
Exemplo n.º 6
0
        public void CheckObsoleteness(ParseContext parseContext, SourceSpan location)
        {
            var oa = AttributeTester.GetMemberObsoleteAttribute(_field);

            if (oa == null)
            {
                return;
            }

            AttributeTester.ReportObsoleteMessage(parseContext, oa, TypeManager.GetFullNameSignature(_field), location);
        }
Exemplo n.º 7
0
        public void HaveAllowAnonymousAttribute()
        {
            // Arrange
            var sut = this.MockingKernel.Get <ReviewsController>();

            // Act
            var hasAttribute = AttributeTester.MethodHasAttribute(() => sut.Details(default(int)), typeof(AllowAnonymousAttribute));

            // Assert
            Assert.IsTrue(hasAttribute);
        }
        public void HaveValidateAntiForgeryTokenAttribute()
        {
            // Arrange
            var sut = this.MockingKernel.Get <ReviewsController>();

            // Act
            var hasAttribute = AttributeTester.MethodHasAttribute(() => sut.Index(default(int)), typeof(ValidateAntiForgeryTokenAttribute));

            // Assert
            Assert.IsTrue(hasAttribute);
        }
Exemplo n.º 9
0
        public void Have_RequiredAttributes(Type attrType)
        {
            // Arrange
            var sut = this.MockingKernel.Get <AccountController>();

            // Act
            var hasAttribute = AttributeTester.MethodHasAttribute(() => sut.Register(), attrType);

            // Assert
            Assert.IsTrue(hasAttribute);
        }
Exemplo n.º 10
0
        public void HaveAllowAnonymousAttribute()
        {
            // Arrange
            var sut = this.MockingKernel.Get <AccountController>();

            // Act
            var hasAttribute = AttributeTester.MethodHasAttribute(() => sut.Login(default(string)), typeof(AllowAnonymousAttribute));

            // Assert
            Assert.IsTrue(hasAttribute);
        }
Exemplo n.º 11
0
        public void Have_RequiredAttributes(Type attrType)
        {
            // Arrange
            var sut = this.MockingKernel.Get <ManageController>();

            // Act
            var hasAttribute = AttributeTester.MethodHasAttribute(() => sut.ChangePassword(default(ChangePasswordViewModel)), attrType);

            // Assert
            Assert.IsTrue(hasAttribute);
        }
        public void HaveHttpPutAttribute()
        {
            // Arrange
            var sut = this.MockingKernel.Get <ReviewsController>();

            // Act
            var hasAttribute = AttributeTester.MethodHasAttribute(() => sut.Index(default(EditReviewBindingModel)), typeof(HttpPutAttribute));

            // Assert
            Assert.IsTrue(hasAttribute);
        }
        public void Have_RequiredAttributes(Type attrType)
        {
            // Arrange
            var sut = this.MockingKernel.Get <ReviewsController>();

            // Act
            var hasAttribute = AttributeTester.MethodHasAttribute(() => sut.ChangeImage(default(ChangeImageBindingModel)), attrType);

            // Assert
            Assert.IsTrue(hasAttribute);
        }
Exemplo n.º 14
0
        public void HaveRequiredAttributes(Type attrType)
        {
            // Arrange
            var sut = this.MockingKernel.Get <AccountController>();

            // Act
            var hasAttribute = AttributeTester.MethodHasAttribute(() => sut.Login(default(LoginViewModel), default(string)), attrType);

            // Assert
            Assert.IsTrue(hasAttribute);
        }
Exemplo n.º 15
0
        public void Have_RequiredAttributes(Type attrType)
        {
            // Arrange
            var sut = this.MockingKernel.Get <BreweriesController>();

            // Act
            var hasAttribute = AttributeTester.MethodHasAttribute(() => sut.Details(It.IsAny <CreateBeerBindingModel>()), attrType);

            // Assert
            Assert.IsTrue(hasAttribute);
        }
Exemplo n.º 16
0
        public void HaveAllowAnonymousAttribute()
        {
            // Arrange
            var sut = this.MockingKernel.Get <AccountController>();

            // Act
            var hasAttribute = AttributeTester.MethodHasAttribute(() => sut.ForgotPasswordConfirmation(), typeof(AllowAnonymousAttribute));

            // Assert
            Assert.IsTrue(hasAttribute);
        }
Exemplo n.º 17
0
        public void Have_AjaxOnlyAttribute()
        {
            // Arrange
            var sut = this.MockingKernel.Get <BreweriesController>();

            // Act
            var hasAttribute = AttributeTester.MethodHasAttribute(() => sut.Types(It.IsAny <string>()), typeof(AjaxOnlyAttribute));

            // Assert
            Assert.IsTrue(hasAttribute);
        }
Exemplo n.º 18
0
        public void Have_RequiredAttributes(Type attrType)
        {
            // Arrange
            var dataMock = new Mock <IPickAndBookData>();
            CategoriesController controller = new CategoriesController(dataMock.Object);

            // Act
            var hasAttribute = AttributeTester.MethodHasAttribute(() => controller.Edit(It.IsAny <Category>(), null), attrType);

            // Assert
            Assert.IsTrue(hasAttribute);
        }
Exemplo n.º 19
0
        public void Have_RequiredAttributes(Type attrType)
        {
            // Arrange
            var dataMock = new Mock <IPickAndBookData>();
            RegisterCompanyController controller = new RegisterCompanyController(dataMock.Object);

            // Act
            var hasAttribute = AttributeTester.MethodHasAttribute(() => controller.Index(It.IsAny <Company>(), null), attrType);

            // Assert
            Assert.IsTrue(hasAttribute);
        }
Exemplo n.º 20
0
        public void Have_RequiredAttributes(Type attrType)
        {
            // Arrange
            var sut = this.MockingKernel.Get <AccountController>();

            // Act
#pragma warning disable 4014
            var hasAttribute = AttributeTester.MethodHasAttribute(() => sut.Register(default(RegisterViewModel)), attrType);
#pragma warning restore 4014

            // Assert
            Assert.IsTrue(hasAttribute);
        }
Exemplo n.º 21
0
        public virtual void CheckObsoleteness(IMemberContext mc, Location loc)
        {
            var oa = GetAttributeObsolete();

            if (oa == null)
            {
                return;
            }

            if (!mc.IsObsolete)
            {
                AttributeTester.Report_ObsoleteMessage(oa, GetSignatureForError(), loc, mc.Module.Compiler.Report);
            }
        }
Exemplo n.º 22
0
        //TODO: duplicate
        protected override bool VerifyClsCompliance()
        {
            if (!base.VerifyClsCompliance())
            {
                return(false);
            }

            Parameters.VerifyClsCompliance();

            if (!AttributeTester.IsClsCompliant(ReturnType.Type))
            {
                Report.Warning(3002, 1, Location, "Return type of `{0}' is not CLS-compliant",
                               GetSignatureForError());
            }
            return(true);
        }
Exemplo n.º 23
0
    static void Main(string[] args)
    {
        // create an Attribute Tester for the attribute we are interested in
        AttributeTester <ObsoleteAttribute> attrTester = new AttributeTester <ObsoleteAttribute>();

        // check to see if the attribute has been applied to a field
        bool fieldTest = attrTester.TestForFieldAttribute(typeof(Calculator), "MultiplierField");

        if (fieldTest)
        {
            // the attribute is defined - get the instance of the attribute
            ObsoleteAttribute attr = attrTester.GetFieldAttribute(typeof(Calculator), "MultiplierField");
            // write out the properties of the attribute
            Console.WriteLine("Attribute: message: {0}, error: {1}", attr.Message, attr.IsError);
        }

        // get a list of the names of the fields that have been modified
        string[] modifiedFieldNames = attrTester.GetModifiedFields(typeof(Calculator));
        foreach (string s in modifiedFieldNames)
        {
            Console.WriteLine("Modified field: {0}", s);
        }



        // perform the same test, this time using a calc object

        // create an instance of the Calculator class
        Calculator calc = new Calculator();

        // check to see if the attribute has been applied to a field
        bool fieldTest2 = attrTester.TestForFieldAttribute(typeof(Calculator), "MultiplierField");

        if (fieldTest)
        {
            // the attribute is defined - get the instance of the attribute
            ObsoleteAttribute attr = attrTester.GetFieldAttribute(typeof(Calculator), "MultiplierField");
            // write out the properties of the attribute
            Console.WriteLine("Attribute: message: {0}, error: {1}", attr.Message, attr.IsError);
        }

        // wait for input before exiting
        Console.WriteLine("Press enter to finish");
        Console.ReadLine();
    }
    static void Main(string[] args)
    {
        // create an Attribute Tester for the attribute we are interested in
        AttributeTester <ObsoleteAttribute> attrTester = new AttributeTester <ObsoleteAttribute>();

        // check to see if the attribute has been defined using the class name
        bool classTest = attrTester.TestForClassAttribute(typeof(Calculator));

        if (classTest)
        {
            // the attribute is defined - get the instance of the attribute
            ObsoleteAttribute attr = attrTester.GetClassAttribute(typeof(Calculator));
            // write out the properties of the attribute
            Console.WriteLine("Attribute: message: {0}, error: {1}", attr.Message, attr.IsError);
        }

        // perform the same test, this time using a calc object

        // create an instance of the Calculator class
        Calculator calc = new Calculator();

        // check to see if the attribute has been defined using the class name
        bool classTest2 = attrTester.TestForClassAttribute(calc);

        if (classTest2)
        {
            // the attribute is defined - get the instance of the attribute
            ObsoleteAttribute attr = attrTester.GetClassAttribute(calc);
            // write out the properties of the attribute
            Console.WriteLine("Attribute: message: {0}, error: {1}", attr.Message, attr.IsError);
        }

        // wait for input before exiting
        Console.WriteLine("Press enter to finish");
        Console.ReadLine();
    }
Exemplo n.º 25
0
 /// <summary>
 /// Returns all attributes of the indicated type and matching the indicated parameters
 /// </summary>
 /// <param name="validator">A validator (default == null, everything)</param>
 /// <param name="allowDerivedAttributeTypes">Should types derived from <see cref="TAttribute"/> be allowed?</param>
 /// <returns>An enumerable collection of the attribute types requested</returns>
 public static IEnumerable <TAttribute> SearchForAttributes <TAttribute>(IEnumerable attributes, AttributeTester <TAttribute> validator = null, bool allowDerivedAttributeTypes = true) where TAttribute : Attribute
 {
     validator = validator ?? new AttributeTester <TAttribute>(attr => true);
     foreach (object obj in attributes)
     {
         if (allowDerivedAttributeTypes)
         {
             if (obj is TAttribute casted && validator(casted))
             {
                 yield return(casted);
             }
         }
         else
         {
             if (typeof(TAttribute) == obj.GetType() && validator((TAttribute)obj))
             {
                 yield return((TAttribute)obj);
             }
         }
     }
 }
Exemplo n.º 26
0
 public static bool HasAny <TAttribute>(IEnumerable attributes, AttributeTester <TAttribute> validator = null, bool allowDerivedAttributeTypes = true) where TAttribute : Attribute
 {
     return(SearchForAttributes(attributes, validator, allowDerivedAttributeTypes).Any());
 }
Exemplo n.º 27
0
 public static bool IsTaggedWithAttribute <TAttribute>(this MemberInfo member, AttributeTester <TAttribute> validator = null, bool allowDerivedAttributeTypes = true, bool checkInherited = true) where TAttribute : Attribute
 {
     return(member.GetAttributes(validator, allowDerivedAttributeTypes, checkInherited).Any());
 }
 public void HasClientAuthorizationAttribute_Always(Type attrType)
 {
     // Arrange & Act & Assert
     AttributeTester.EnsureClassHasClientAuthorizationAttribute(typeof(RegisterCompanyController));
 }
Exemplo n.º 29
0
 public void Class_ShouldHaveAdminAuthorizeAttribute()
 {
     // Act & Assert
     AttributeTester.EnsureClassHasAdminAuthorizationAttribute(typeof(UsersController));
 }
Exemplo n.º 30
0
 public static IEnumerable <TAttribute> GetAttributes <TAttribute>(this MemberInfo member, AttributeTester <TAttribute> validator = null, bool allowDerivedAttributeTypes = true, bool checkInherited = true) where TAttribute : Attribute
 {
     return(AttributeHelper.SearchForAttributes(member.GetCustomAttributes(checkInherited), validator, allowDerivedAttributeTypes));
 }