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) { 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); }
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); }
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 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); }
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); }
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 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); }
public void Execute(ProjectReferences data, IConventionResultContext result) { result.Is("Project must not reference dlls from bin or obj directories", data.References.Where(IsBinOrObjReference)); }
public void Execute(Assemblies assemblies, IConventionResultContext result) { result.Is($"Forbidden reference to {_forbiddenReference}" + Because() , assemblies.Referencing(_forbiddenReference)); }
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")); }
public void Execute(Types data, IConventionResultContext result) { result.Is("Types must have a default constructor", data.TypesToVerify.Where(t => t.HasDefaultConstructor() == false)); }
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) { var invalidTypes = data.TypesToVerify.Where(type => !type.IsAbstract).ToList(); result.Is("Types should be abstract", invalidTypes); }