public PackageHasSignatureValidator( ValidatorConfiguration config, ILogger <PackageHasSignatureValidator> logger) : base(config, logger) { _logger = logger ?? throw new ArgumentNullException(nameof(logger)); }
/// <summary> /// Sets <see cref="ValidatorConfiguration.DisplayNameResolver"/> to a custom resolver that handles <see cref="SettingDisplayNameAttribute"/> and <see cref="OptionAttribute"/>. /// </summary> public static void UseCustomDisplayNameResolver(this ValidatorConfiguration validatorConfiguration) { validatorConfiguration.DisplayNameResolver = (type, member, expression) => { if (member is PropertyInfo property) { // If the property has a [SettingDisplayName] attribute, use value defined here var displayName = property?.GetCustomAttribute <SettingDisplayNameAttribute>()?.DisplayName; if (!String.IsNullOrEmpty(displayName)) { return(displayName); } // If the value has a [Option] attribute (used by the command line parser) displayName = property?.GetCustomAttribute <OptionAttribute>()?.LongName; if (!String.IsNullOrEmpty(displayName)) { return(displayName); } } // default case: No display name return(null); }; }
public CsvValidationeResult Validate(StreamReader csvStream, IList <string> fields) { var config = new ValidatorConfiguration(); config.ColumnSeperator = ","; config.HasHeaderRow = true; config.RowSeperator = Environment.NewLine; for (int i = 0; i < fields.Count; i++) { config.Columns.Add(i, new ColumnValidatorConfiguration() { Name = fields[i], IsNumeric = false, Unique = true }); } Validator validator = Validator.FromConfiguration(config); var sourceReader = new StreamSourceReader(csvStream.BaseStream); var validationResult = new CsvValidationeResult { Errors = validator.Validate(sourceReader).ToList() }; return(validationResult); }
public RegistrationDeprecationValidator( RegistrationEndpoint endpoint, ValidatorConfiguration config, ILogger <RegistrationDeprecationValidator> logger) : base(endpoint, config, logger) { }
protected override RegistrationDeprecationValidator CreateValidator( ILogger <RegistrationDeprecationValidator> logger) { var endpoint = ValidatorTestUtility.CreateRegistrationEndpoint(); var config = new ValidatorConfiguration("https://nuget.test/packages", requireRepositorySignature: false); return(new RegistrationDeprecationValidator(endpoint, config, logger)); }
public void JsonReader_WhenEmptyString_ShouldReturnEmptyConfiguration() { JsonReader reader = new JsonReader(); ValidatorConfiguration configuration = reader.Read(string.Empty); Assert.IsNotNull(configuration, "configuration reader did not create configuration."); }
protected override RegistrationRequireLicenseAcceptanceValidator CreateValidator( IDictionary <FeedType, SourceRepository> feedToSource, ILogger <RegistrationRequireLicenseAcceptanceValidator> logger) { var config = new ValidatorConfiguration("https://nuget.test/packages", requirePackageSignature: false); return(new RegistrationRequireLicenseAcceptanceValidator(feedToSource, config, logger)); }
public void Constructor_WhenArgumentsAreValid_InitializesInstance( string packageBaseAddress, bool requirePackageSignature) { var configuration = new ValidatorConfiguration(packageBaseAddress, requirePackageSignature); Assert.Equal(packageBaseAddress, configuration.PackageBaseAddress); Assert.Equal(requirePackageSignature, configuration.RequirePackageSignature); }
public void JsonReader_WhenHasHeaderRowIsProvided_ShouldBePopulated() { const string INPUT = "{ \"hasHeaderRow\": true }"; JsonReader reader = new JsonReader(); ValidatorConfiguration configuration = reader.Read(INPUT); Assert.AreEqual(true, configuration.HasHeaderRow); }
public void JsonReader_WhenColumnSeperatorProvided_ShouldBePopulated() { const string INPUT = "{ \"columnSeperator\": \"|\" }"; JsonReader reader = new JsonReader(); ValidatorConfiguration configuration = reader.Read(INPUT); Assert.AreEqual("|", configuration.ColumnSeperator); }
public void JsonReader_WhenRowSeperatorProvided_ShouldBePopulated() { const string INPUT = "{ \"rowSeperator\": \"\\r\\n\" }"; JsonReader reader = new JsonReader(); ValidatorConfiguration configuration = reader.Read(INPUT); Assert.AreEqual("\r\n", configuration.RowSeperator); }
public void JsonReader_WhenColumnNameIsProvided_ShouldBePopulated() { const string EXPECTED = "HEADER"; const string INPUT = "{ \"columns\": { \"1\": { \"name\": \"HEADER\" } } }"; JsonReader reader = new JsonReader(); ValidatorConfiguration configuration = reader.Read(INPUT); Assert.AreEqual(EXPECTED, configuration.Columns[1].Name); }
public ValidatorConfiguration Read(string json) { ValidatorConfiguration configuration = new ValidatorConfiguration(); if (!string.IsNullOrEmpty(json)) { configuration = Newtonsoft.Json.JsonConvert.DeserializeObject <ValidatorConfiguration>(json); } return(configuration); }
/// <inheritdoc /> public bool CreateValidatorFor(ValidatorConfiguration validatorConfiguration, DynamicMetadataDefinition definition) { var validator = _validators.FirstOrDefault(x => x.Key == validatorConfiguration.ValidatorKey); var validatorType = validator.GetType(); var fromContainer = (IValidator)_container.GetInstance(validatorType); fromContainer.ConfigureValidator(validatorConfiguration.Parameters); return(fromContainer.IsValidValidator(definition)); }
// This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { services.AddCors(); services.AddControllers(); services.TryAddSingleton <IHttpContextAccessor, HttpContextAccessor>(); services.AddScoped <IActionResultConverter, ActionResultConverter>(); services.ConfigureSwagger(); AuthConfig.ConfigureAuthentication(services, this.configuration); ValidatorConfiguration.ConfigureServices(services); AppConfiguration.ConfigureServices(services); DomainServicesConfiguration.ConfigureServices(services); RepositoryConfiguration.ConfigureServices(services); AuthConfigurations.ConfigureServices(services); }
static TestableValidator() { var sourceRepository = new Mock <SourceRepository>(); var metadataResource = new Mock <IPackageTimestampMetadataResource>(); metadataResource.Setup(x => x.GetAsync(It.IsAny <ValidationContext>())) .ReturnsAsync(PackageTimestampMetadata.CreateForExistingPackage(DateTime.Now, DateTime.Now)); sourceRepository.Setup(x => x.GetResource <IPackageTimestampMetadataResource>()) .Returns(metadataResource.Object); var feedToSource = new Mock <IDictionary <FeedType, SourceRepository> >(); feedToSource.Setup(x => x[It.IsAny <FeedType>()]).Returns(sourceRepository.Object); _validatorConfiguration = new ValidatorConfiguration(packageBaseAddress: "a", requireRepositorySignature: true); _logger = Mock.Of <ILogger <Validator> >(); }
public CatalogAggregateValidator(ValidatorFactory factory, ValidatorConfiguration configuration) { if (factory == null) { throw new ArgumentNullException(nameof(factory)); } if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } var validators = new List <IValidator>(); if (configuration.RequirePackageSignature) { validators.Add(factory.Create(typeof(PackageHasSignatureValidator))); } _validators = validators; }
protected override void Init(IDictionary <string, string> arguments, CancellationToken cancellationToken) { var gallery = arguments.GetOrThrow <string>(Arguments.Gallery); var index = arguments.GetOrThrow <string>(Arguments.Index); var packageBaseAddress = arguments.GetOrThrow <string>(Arguments.ContentBaseAddress); var source = arguments.GetOrThrow <string>(Arguments.Source); var requireSignature = arguments.GetOrDefault(Arguments.RequireSignature, false); var verbose = arguments.GetOrDefault(Arguments.Verbose, false); CommandHelpers.AssertAzureStorage(arguments); var monitoringStorageFactory = CommandHelpers.CreateStorageFactory(arguments, verbose); var auditingStorageFactory = CommandHelpers.CreateSuffixedStorageFactory("Auditing", arguments, verbose); var endpointInputs = CommandHelpers.GetEndpointFactoryInputs(arguments); var messageHandlerFactory = CommandHelpers.GetHttpMessageHandlerFactory(TelemetryService, verbose); Logger.LogInformation( "CONFIG gallery: {Gallery} index: {Index} storage: {Storage} auditingStorage: {AuditingStorage} endpoints: {Endpoints}", gallery, index, monitoringStorageFactory, auditingStorageFactory, string.Join(", ", endpointInputs.Select(e => e.Name))); var validatorConfig = new ValidatorConfiguration( packageBaseAddress, requireSignature); _packageValidator = new PackageValidatorFactory(LoggerFactory) .Create(gallery, index, auditingStorageFactory, endpointInputs, messageHandlerFactory, validatorConfig, verbose); _queue = CommandHelpers.CreateStorageQueue <PackageValidatorContext>(arguments, PackageValidatorContext.Version); _statusService = CommandHelpers.GetPackageMonitoringStatusService(arguments, monitoringStorageFactory, LoggerFactory); _notificationService = new LoggerMonitoringNotificationService(LoggerFactory.CreateLogger <LoggerMonitoringNotificationService>()); _regResource = Repository.Factory.GetCoreV3(index).GetResource <RegistrationResourceV3>(cancellationToken); _client = new CollectorHttpClient(messageHandlerFactory()); SetUserAgentString(); }
public void Validator_WhenRowInvalid_ShouldStoreRowInError() { string[] ROWS = { @"this1,", @"this2," }; FakeSourceReader source = new FakeSourceReader(ROWS); ValidatorConfiguration configuration = new ValidatorConfiguration(); configuration.Columns.Add(2, new ColumnValidatorConfiguration { IsRequired = true }); Validator validator = Validator.FromConfiguration(configuration); List <RowValidationError> errors = validator.Validate(source).ToList(); Assert.AreEqual(1, errors[0].Row); Assert.AreEqual(2, errors[1].Row); }
protected override void OnApplicationStarted() { Error += OnError; EndRequest += OnEndRequest; var settings = new SparkSettings() .AddNamespace("System") .AddNamespace("System.Collections.Generic") .AddNamespace("System.Web.Mvc") .AddNamespace("System.Web.Mvc.Html") .AddNamespace("MvcContrib.FluentHtml") .AddNamespace("CodeBetter.Canvas") .AddNamespace("CodeBetter.Canvas.Web") .SetPageBaseType("ApplicationViewPage") .SetAutomaticEncoding(true); #if DEBUG settings.SetDebug(true); #endif var viewFactory = new SparkViewFactory(settings); ViewEngines.Engines.Add(viewFactory); #if !DEBUG PrecompileViews(viewFactory); #endif RegisterAllControllersIn("CodeBetter.Canvas.Web"); log4net.Config.XmlConfigurator.Configure(); RegisterRoutes(RouteTable.Routes); Factory.Load(new Components.WebDependencies()); ModelBinders.Binders.DefaultBinder = new Binders.GenericBinderResolver(Factory.TryGet <IModelBinder>); ValidatorConfiguration.Initialize("CodeBetter.Canvas"); HtmlValidationExtensions.Initialize(ValidatorConfiguration.Rules); }
public Constructor() { _configuration = new ValidatorConfiguration(packageBaseAddress: "a", requirePackageSignature: true); }
protected override void Init(IDictionary <string, string> arguments, CancellationToken cancellationToken) { var gallery = arguments.GetOrThrow <string>(Arguments.Gallery); var index = arguments.GetOrThrow <string>(Arguments.Index); var packageBaseAddress = arguments.GetOrThrow <string>(Arguments.ContentBaseAddress); var source = arguments.GetOrThrow <string>(Arguments.Source); var requireRepositorySignature = arguments.GetOrDefault(Arguments.RequireRepositorySignature, false); var verbose = arguments.GetOrDefault(Arguments.Verbose, false); var timeoutInSeconds = arguments.GetOrDefault(Arguments.SqlCommandTimeoutInSeconds, 300); var sqlTimeout = TimeSpan.FromSeconds(timeoutInSeconds); var connectionString = arguments.GetOrThrow <string>(Arguments.ConnectionString); var galleryDbConnection = new AzureSqlConnectionFactory( connectionString, SecretInjector, LoggerFactory.CreateLogger <AzureSqlConnectionFactory>()); var packageContentUriBuilder = new PackageContentUriBuilder( arguments.GetOrThrow <string>(Arguments.PackageContentUrlFormat)); var galleryDatabase = new GalleryDatabaseQueryService( galleryDbConnection, packageContentUriBuilder, TelemetryService, timeoutInSeconds); CommandHelpers.AssertAzureStorage(arguments); var monitoringStorageFactory = CommandHelpers.CreateStorageFactory(arguments, verbose); var auditingStorageFactory = CommandHelpers.CreateSuffixedStorageFactory("Auditing", arguments, verbose); var endpointConfiguration = CommandHelpers.GetEndpointConfiguration(arguments); var messageHandlerFactory = CommandHelpers.GetHttpMessageHandlerFactory(TelemetryService, verbose); Logger.LogInformation( "CONFIG gallery: {Gallery} index: {Index} storage: {Storage} auditingStorage: {AuditingStorage} registration cursor uri: {RegistrationCursorUri} flat-container cursor uri: {FlatContainerCursorUri}", gallery, index, monitoringStorageFactory, auditingStorageFactory, endpointConfiguration.RegistrationCursorUri, endpointConfiguration.FlatContainerCursorUri); var validatorConfig = new ValidatorConfiguration( packageBaseAddress, requireRepositorySignature); _packageValidator = ValidationFactory.CreatePackageValidator( gallery, index, auditingStorageFactory, validatorConfig, endpointConfiguration, messageHandlerFactory, galleryDatabase, LoggerFactory); _queue = CommandHelpers.CreateStorageQueue <PackageValidatorContext>(arguments, PackageValidatorContext.Version); _statusService = CommandHelpers.GetPackageMonitoringStatusService(arguments, monitoringStorageFactory, LoggerFactory); _notificationService = new LoggerMonitoringNotificationService(LoggerFactory.CreateLogger <LoggerMonitoringNotificationService>()); _client = new CollectorHttpClient(messageHandlerFactory()); _queueLoopDuration = TimeSpan.FromHours( arguments.GetOrDefault( Arguments.QueueLoopDurationHours, DefaultQueueLoopDurationHours)); _queueDelay = TimeSpan.FromSeconds( arguments.GetOrDefault( Arguments.QueueDelaySeconds, DefaultQueueDelaySeconds)); _workerCount = arguments.GetOrDefault(Arguments.WorkerCount, DefaultWorkerCount); SetUserAgentString(); }
public ValidationFixture() { ValidatorConfiguration.Initialize("CodeBetter.Canvas.Tests"); }
public void Setup() { _configuration = new ValidatorConfiguration(); _converter = new ConfigurationConvertor(_configuration); }
public Constructor() { _endpoint = ValidatorTestUtility.CreateFlatContainerEndpoint(); _configuration = new ValidatorConfiguration(packageBaseAddress: "a", requireRepositorySignature: true); }
public ValidatorFactoryTests() { _configuration = new ValidatorConfiguration(packageBaseAddress: "a", requirePackageSignature: true); }
static async Task Main(string[] args) { string ioTHubEventHubEndpointConnectionString = null; string storageConnectionString = null; string blobContainerName = "checkpoint"; string eventHubConsumerGroup = "$Default"; bool showHelp = false; uint expectedValueChangesPerTimestamp = 0; uint expectedIntervalOfValueChanges = 0; uint expectedMaximalTotalDuration = 0; var options = new OptionSet { { "c|connectionString=", "The connection string of the IoT Hub Device/Module that receives telemetry", s => ioTHubEventHubEndpointConnectionString = s }, { "sc|storageConnectionString=", "The connection string of the storage account to store checkpoints.", s => storageConnectionString = s }, { "ee|expectedEvents=", "The amount of value changes per ServerTimestamp that is expected", (uint i) => expectedValueChangesPerTimestamp = i }, { "ei|expectedInterval=", "The time in milliseconds between value changes that is expected", (uint i) => expectedIntervalOfValueChanges = i }, { "ed|expectedDuration=", "The maximal time in milliseconds between OPC UA value change and enqueue in event hub partition that is expected", (uint i) => expectedMaximalTotalDuration = i }, { "h|help", "show this message and exit", b => showHelp = b != null } }; options.Parse(args); if (showHelp) { ShowHelp(options); return; } Log.Logger = new LoggerConfiguration() .WriteTo.Console(outputTemplate: "[{Timestamp:yyyy-MM-dd HH:mm:ss.fff}][{Level:u3}] {Message:lj}{NewLine}{Exception}") .CreateLogger(); var configuration = new ValidatorConfiguration() { BlobContainerName = blobContainerName, EventHubConsumerGroup = eventHubConsumerGroup, ExpectedIntervalOfValueChanges = expectedIntervalOfValueChanges, ExpectedMaximalDuration = expectedMaximalTotalDuration, ExpectedValueChangesPerTimestamp = expectedValueChangesPerTimestamp, IoTHubEventHubEndpointConnectionString = ioTHubEventHubEndpointConnectionString, StorageConnectionString = storageConnectionString, }; var loggerFactory = new SerilogLoggerFactory(Log.Logger); var melLogger = loggerFactory.CreateLogger <TelemetryValidator>(); var validator = new TelemetryValidator(melLogger); await validator.StartAsync(configuration); var cts = new CancellationTokenSource(); Console.CancelKeyPress += (sender, cancelArgs) => { if (cancelArgs.SpecialKey == ConsoleSpecialKey.ControlC) { Log.Information("Cancellation requested by hitting ctrl+c"); validator.StopAsync().Wait(); } }; Log.Information("TestEventProcessor stopped"); }
public FluentValidationMvcConfiguration(ValidatorConfiguration validatorOptions) { ValidatorOptions = validatorOptions; }
public void SetUp() { validators = new BulkValidator(); config = new ValidatorConfiguration(validators); }