コード例 #1
0
 public void Execute(Types data, IConventionResultContext result)
 {
     result.Is("Each type must have at most one constructor",
               data.TypesToVerify.Select(SmartType.For)
               .Where(t => !t.IsException())
               .Where(t => !t.HasPublicConstructorCountOfAtMost(1))
               .Select(t => t.ToClrType()));
 }
 public void Execute(Types data, IConventionResultContext result)
 {
     result.IsSymmetric(
         string.Format("{0}s must be under the '{1}' namespace", classType, namespaceToCheck),
         string.Format("Non-{0}s must not be under the '{1}' namespace", classType, namespaceToCheck),
         classIsApplicable,
         TypeLivesInSpecifiedNamespace,
         data.TypesToVerify.Where(t => !t.IsCompilerGenerated()));
 }
        public void Execute(Types data, IConventionResultContext result)
        {
            var notifyPropertyChanged = typeof(INotifyPropertyChanged);
            var failingData           = data.TypesToVerify.Where(t => t.Name.EndsWith(viewModelSuffix, StringComparison.OrdinalIgnoreCase))
                                        .Where(t => !notifyPropertyChanged.GetTypeInfo().IsAssignableFrom(t.GetTypeInfo()));

            result.Is($"ViewModels (types named *{viewModelSuffix}) should inherit from INotifyPropertyChanged",
                      failingData);
        }
コード例 #4
0
        public void Execute(Types data, IConventionResultContext result)
        {
            var notifyPropertyChanged = typeof(INotifyPropertyChanged);
            var failingData           = data.TypesToVerify.Where(t => t.Name.EndsWith(viewModelSuffix, StringComparison.InvariantCultureIgnoreCase))
                                        .Where(t => !notifyPropertyChanged.IsAssignableFrom(t));

            result.Is(string.Format("ViewModels (types named *{0}) should inherit from INotifyPropertyChanged", viewModelSuffix),
                      failingData);
        }
コード例 #5
0
 public void Execute(Types data, IConventionResultContext result)
 {
     result.IsSymmetric(
         "All types inheriting from exception must end with 'Exception'",
         data
         .Where(t => t.IsSubclassOf(typeof(Exception)))
         .Where(t => !t.Name.EndsWith("Exception")),
         "All types ending with 'Exception' must inherit from Exception",
         data
         .Where(t => t.Name.EndsWith("Exception"))
         .Where(t => !t.IsSubclassOf(typeof(Exception))));
 }
        public void Execute(ProjectPropertyGroups data, IConventionResultContext result)
        {
            foreach (var group in data.PropertyGroups.Where(Match))
            {
                if (group[Property] == null)
                {
                    continue;
                }

                result.Is(string.Format("{0} property in {1} must have a value of {2}", this.Property, group.Name, this.Value),
                          group[Property].Equals(this.Value) ? new string[] {} : new[] { string.Format("{0}:{1}", this.Property, group[Property]) });
            }
        }
        public void Execute(Types data, IConventionResultContext result)
        {
            var controllers = GetControllers(data);
            var typesWhichDoNotEndInController = controllers.Where(c => !c.Name.EndsWith("Controller"));

            var typesWhichEndInController = data.TypesToVerify.Where(t => t.Name.EndsWith("Controller"));
            var controllersWhichDoNotInheritFromController =
                typesWhichEndInController.Where(t => !IsMvcController(t) && !IsWebApiController(t));

            result.IsSymmetric(
                GetControllerTypeName() + "s must be suffixed with Controller", typesWhichDoNotEndInController,
                "Types named *Controller must inherit from ApiController or Controller",
                controllersWhichDoNotInheritFromController);
        }
        public void Execute(Types data, IConventionResultContext result)
        {
            var failingTypes =
                from shouldlyClasses in data
                from shouldlyMethods in shouldlyClasses.GetMethods()
                where typeof(object).GetMethods().All(m => m.Name != shouldlyMethods.Name)
                group shouldlyMethods by FormatKey(shouldlyMethods) into shouldlyMethod
                    where HasNoCustomMessageOverload(shouldlyMethod)
                select shouldlyMethod.Key;

            result.Is(
                "The following shouldly methods are missing one or more of the custom message overloads",
                failingTypes);
        }
        public void Execute(Types data, IConventionResultContext result)
        {
            ConventionTitle = "well, does the header apply here all across the board? How would that work for CSV?";
            var types = data.TypesToVerify;
            var collectionToItemLookup = from collection in types
                                         where collection.IsClass
                                         orderby collection.FullName
                                         from item in GetItemTypes(collection)
                                         select new
            {
                collection,
                item,
                can_add    = typeof(ICanAdd <>).MakeGenericType(item).IsAssignableFrom(collection),
                can_remove = typeof(ICanRemove <>).MakeGenericType(item).IsAssignableFrom(collection)
            };

            result.Is("Some title", collectionToItemLookup);
        }
コード例 #10
0
        public void Execute(Types data, IConventionResultContext result)
        {
            var shouldThrowMethods = data
                                     .SelectMany(t => t.GetMethods())
                                     .Where(method => method.Name.StartsWith("Throw") || method.Name.StartsWith("ShouldThrow"))
                                     .Select(throwMethod => new ShouldThrowMethod(throwMethod))
                                     .ToList();

            var extensionMethods = shouldThrowMethods.Where(m => m.IsShouldlyExtension).ToList();
            var staticMethods    = shouldThrowMethods.Where(m => !m.IsShouldlyExtension).ToList();

            var firstSetFailureData  = staticMethods.Where(e => !extensionMethods.Any(e.Equals));
            var secondSetFailureData = extensionMethods.Where(e => !staticMethods.Any(e.Equals));

            result.IsSymmetric(
                "Should.Throw method without corresponding ShouldThrow extension method",
                firstSetFailureData,
                "ShouldThrow extension method without Should.Throw static method",
                secondSetFailureData);
        }
コード例 #11
0
        public void Execute(Types data, IConventionResultContext result)
        {
            var resultProperty = typeof(ConfigInitWizardStep).GetProperty("DefaultResult", BindingFlags.NonPublic | BindingFlags.Instance);

            result
            .Is("Init steps default response should not throw",
                data.TypesToVerify.Where(t =>
            {
                var constructorInfo = t.GetConstructors().Single();
                var ctorArguments   = constructorInfo.GetParameters().Select(p => p.ParameterType.IsValueType ? Activator.CreateInstance(p.ParameterType) : null).ToArray();
                var instance        = Activator.CreateInstance(t, ctorArguments);
                try
                {
                    resultProperty.GetValue(instance);
                }
                catch (Exception)
                {
                    return(true);
                }
                return(false);
            }));
        }
        public void Execute(AutofacRegistrations data, IConventionResultContext result)
        {
            var distinctTypes = data.ComponentRegistry.Registrations
                                .SelectMany(r => r.Services.OfType <TypedService>().Select(s => s.ServiceType).Union(GetGenericFactoryTypes(data, r)))
                                .Distinct();

            var failingTypes = new List <string>();

            foreach (var distinctType in distinctTypes)
            {
                try
                {
                    container.Resolve(distinctType);
                }
                catch (DependencyResolutionException e)
                {
                    failingTypes.Add(e.Message);
                }
            }

            result.Is("Can resolve all types registered with Autofac", failingTypes);
        }
コード例 #13
0
        public void Execute(AutofacRegistrations data, IConventionResultContext result)
        {
            var exceptions = new List <string>();

            foreach (var registration in data.ComponentRegistry.Registrations)
            {
                var registrationLifetime = data.GetLifetime(registration);

                foreach (var ctorParameter in data.GetRegistrationCtorParameters(registration))
                {
                    IComponentRegistration parameterRegistration;
                    var typedService = new TypedService(ctorParameter.ParameterType);

                    // If the parameter is not registered with autofac, ignore
                    if (!data.ComponentRegistry.TryGetRegistration(typedService, out parameterRegistration))
                    {
                        continue;
                    }

                    var parameterLifetime = data.GetLifetime(parameterRegistration);

                    if (parameterLifetime >= registrationLifetime)
                    {
                        continue;
                    }

                    var typeName      = data.GetConcreteType(registration).ToTypeNameString();
                    var parameterType = ctorParameter.ParameterType.ToTypeNameString();

                    var error = string.Format("{0} ({1}) => {2} ({3})",
                                              typeName, registrationLifetime,
                                              parameterType, parameterLifetime);
                    exceptions.Add(error);
                }
            }

            result.Is("Components should not depend on services with lesser lifetimes", exceptions);
        }
コード例 #14
0
        public void Execute(Types data, IConventionResultContext result)
        {
            var invalidTypes = data.TypesToVerify.Where(type => !type.IsAbstract).ToList();

            result.Is("Types should be abstract", invalidTypes);
        }
コード例 #15
0
 public void Execute(Types data, IConventionResultContext result)
 {
     var failingTypes = data.TypesToVerify.Where(IsBroken);
     // Oops, I forgot to set the result
 }
コード例 #16
0
 public void Execute(Types data, IConventionResultContext result)
 {
     result.Is("Methods must be virtual", data.TypesToVerify.SelectMany(t => t.NonVirtualMethods()));
 }
 public void Execute(Types data, IConventionResultContext result)
 {
     result.Is("Types must have a default constructor",
               data.TypesToVerify.Where(t => t.HasDefaultConstructor() == false));
 }
コード例 #18
0
 public void Execute(ProjectFileItems data, IConventionResultContext result)
 {
     result.Is(
         string.Format("{0} Files must be embedded resources", FileExtension),
         data.Items.Where(s => s.FilePath.EndsWith(FileExtension) && s.ReferenceType != "EmbeddedResource"));
 }
コード例 #19
0
 public void Execute(ProjectReferences data, IConventionResultContext result)
 {
     result.Is("Project must not reference dlls from bin or obj directories",
               data.References.Where(IsBinOrObjReference));
 }
コード例 #20
0
 public void Execute(Assemblies assemblies, IConventionResultContext result)
 {
     result.Is($"Forbidden reference to {_forbiddenReference}"
               + Because()
               , assemblies.Referencing(_forbiddenReference));
 }