public void RespectsConnectionOptionsForProducer(string expectedPathName, string connectionString) { var testEndpoint = new Uri("http://mycustomendpoint.com"); EventHubOptions options = new EventHubOptions { CustomEndpointAddress = testEndpoint, ClientRetryOptions = new EventHubsRetryOptions { MaximumRetries = 10 } }; var configuration = ConfigurationUtilities.CreateConfiguration(new KeyValuePair <string, string>("connection", connectionString)); var factory = ConfigurationUtilities.CreateFactory(configuration, options); var producer = factory.GetEventHubProducerClient(expectedPathName, "connection"); EventHubConnection connection = (EventHubConnection)typeof(EventHubProducerClient).GetProperty("Connection", BindingFlags.NonPublic | BindingFlags.Instance) .GetValue(producer); EventHubConnectionOptions connectionOptions = (EventHubConnectionOptions)typeof(EventHubConnection).GetProperty("Options", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(connection); Assert.AreEqual(testEndpoint, connectionOptions.CustomEndpointAddress); Assert.AreEqual(expectedPathName, producer.EventHubName); EventHubProducerClientOptions producerOptions = (EventHubProducerClientOptions)typeof(EventHubProducerClient).GetProperty("Options", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(producer); Assert.AreEqual(10, producerOptions.RetryOptions.MaximumRetries); Assert.AreEqual(expectedPathName, producer.EventHubName); }
public void ExpandFullyQualified() { var fileName = Path.Combine(Path.GetPathRoot(Environment.CurrentDirectory), "test", "demo.txt"); var expandedPath = ConfigurationUtilities.ExpandConfigFileName(fileName, null); Assert.IsTrue(string.Equals(fileName, expandedPath, StringComparison.Ordinal), "Expanded directory path was incorrect"); }
public void ExpandFileName(bool offRoot, string directory, string fileName, params string[] pathElements) { var constructedDirectoryPathElements = new List <string>(); if (offRoot) { constructedDirectoryPathElements.Add(Path.GetPathRoot(Environment.CurrentDirectory)); } if ((pathElements?.Count() ?? 0) > 0) { constructedDirectoryPathElements.AddRange(pathElements); } var constructedDirectoryPath = Path.Combine(constructedDirectoryPathElements.ToArray()); if (offRoot) { Path.Combine(Path.GetPathRoot(Environment.CurrentDirectory), directory); } var expectedQualifiedName = offRoot ? Path.Combine(constructedDirectoryPath, fileName) : Path.Combine(Environment.CurrentDirectory, constructedDirectoryPath, fileName); var expandedPath = ConfigurationUtilities.ExpandConfigFileName(fileName, constructedDirectoryPath); Assert.IsTrue(string.Equals(expectedQualifiedName, expandedPath, StringComparison.Ordinal), "Expanded directory path was incorrect"); }
public void RespectsConnectionOptionsForProcessor(string expectedPathName, string connectionString) { var testEndpoint = new Uri("http://mycustomendpoint.com"); EventHubOptions options = new EventHubOptions { CustomEndpointAddress = testEndpoint, TransportType = EventHubsTransportType.AmqpWebSockets, WebProxy = new WebProxy("http://proxyserver/"), ClientRetryOptions = new EventHubsRetryOptions { MaximumRetries = 10 }, MaxEventBatchSize = 20 }; var configuration = ConfigurationUtilities.CreateConfiguration(new KeyValuePair <string, string>("connection", connectionString)); var factory = ConfigurationUtilities.CreateFactory(configuration, options); var processor = factory.GetEventProcessorHost(expectedPathName, "connection", "consumer", false); EventProcessorOptions processorOptions = (EventProcessorOptions)typeof(EventProcessor <EventProcessorHostPartition>) .GetProperty("Options", BindingFlags.NonPublic | BindingFlags.Instance) .GetValue(processor); Assert.AreEqual(testEndpoint, processorOptions.ConnectionOptions.CustomEndpointAddress); Assert.AreEqual(EventHubsTransportType.AmqpWebSockets, processorOptions.ConnectionOptions.TransportType); Assert.AreEqual("http://proxyserver/", ((WebProxy)processorOptions.ConnectionOptions.Proxy).Address.AbsoluteUri); Assert.AreEqual(10, processorOptions.RetryOptions.MaximumRetries); Assert.AreEqual(expectedPathName, processor.EventHubName); int batchSize = (int)typeof(EventProcessor <EventProcessorHostPartition>) .GetProperty("EventBatchMaximumCount", BindingFlags.NonPublic | BindingFlags.Instance) .GetValue(processor); Assert.AreEqual(20, batchSize); }
public EventHubTriggerAttributeBindingProviderTests() { var configuration = ConfigurationUtilities.CreateConfiguration( new KeyValuePair <string, string>("connection", "Endpoint=sb://test.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=abc123=;"), new KeyValuePair <string, string>("Storage", "Endpoint=sb://test.blob.core.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=abc123=")); var options = new EventHubOptions(); Mock <IConverterManager> convertManager = new Mock <IConverterManager>(MockBehavior.Default); // mock the BlobServiceClient and BlobContainerClient which are used for the checkpointing var blobServiceClient = new Mock <BlobServiceClient>(); blobServiceClient.Setup(client => client.GetBlobContainerClient(It.IsAny <string>())) .Returns(Mock.Of <BlobContainerClient>()); var componentFactory = new Mock <AzureComponentFactory>(); componentFactory.Setup( factory => factory.CreateClient( typeof(BlobServiceClient), It.IsAny <IConfiguration>(), It.IsAny <TokenCredential>(), It.IsAny <BlobClientOptions>())).Returns(blobServiceClient.Object); var factory = ConfigurationUtilities.CreateFactory(configuration, options, componentFactory.Object); _provider = new EventHubTriggerAttributeBindingProvider(convertManager.Object, Options.Create(options), NullLoggerFactory.Instance, factory); }
public string GetSSOUrl(string returnUrl) { var url = string.Format(ConfigurationUtilities.GetString("SSO.AuthorizationUrl"), ConfigurationUtilities.GetString("SSO.ClientId")); var encodedUrl = HttpUtility.UrlEncode(returnUrl); return($"{url}&redirect_uri={_postbackAuthUri}&state={encodedUrl}"); }
public void ReadDefaultConnectionString(string defaultConnectionString, string defaultConnectionSettingString, string expectedValue) { var configuration = ConfigurationUtilities.CreateConfiguration( new KeyValuePair <string, string>("ConnectionStrings:" + Constants.DefaultConnectionStringName, defaultConnectionString), new KeyValuePair <string, string>(Constants.DefaultConnectionSettingStringName, defaultConnectionSettingString)); var mockProvider = new Mock <MessagingProvider>(); mockProvider.Setup( p => p.CreateClient(expectedValue)) .Returns(Mock.Of <ServiceBusClient>()); var factory = new ServiceBusClientFactory(configuration, Mock.Of <AzureComponentFactory>(), mockProvider.Object, new AzureEventSourceLogForwarder(new NullLoggerFactory())); if (expectedValue == null) { Assert.That( () => factory.CreateClientFromSetting(null), Throws.InstanceOf <InvalidOperationException>()); } else { factory.CreateClientFromSetting(null); mockProvider.VerifyAll(); } }
public void GetEventHubClient_AddsConnection(string expectedPathName, string connectionString) { EventHubOptions options = new EventHubOptions(); var configuration = ConfigurationUtilities.CreateConfiguration(new KeyValuePair <string, string>("connection", connectionString)); var factory = ConfigurationUtilities.CreateFactory(configuration, options); var client = factory.GetEventHubProducerClient(expectedPathName, "connection"); Assert.AreEqual(expectedPathName, client.EventHubName); }
private void Initialize() { if (ConfigurationManager.AppSettings != null) { CheckFileMapper(); LegacyDirectoryPath = FileMapper.MapApplicationRelativePath(ConfigurationUtilities.GetSetting("Legacy.Directory", "Legacy")); PersonalizationDirectoryPath = FileMapper.MapApplicationRelativePath(DataDirectory + "/Personalization_Data"); } }
public void Setup() { _mockExecutor = new Mock <ITriggeredFunctionExecutor>(MockBehavior.Strict); _client = new ServiceBusClient(_testConnection); ServiceBusProcessorOptions processorOptions = new ServiceBusProcessorOptions(); ServiceBusProcessor messageProcessor = _client.CreateProcessor(_entityPath); ServiceBusReceiver receiver = _client.CreateReceiver(_entityPath); _mockMessageProcessor = new Mock <MessageProcessor>(MockBehavior.Strict, messageProcessor); var configuration = ConfigurationUtilities.CreateConfiguration(new KeyValuePair <string, string>(_connection, _testConnection)); _serviceBusOptions = new ServiceBusOptions(); _mockProvider = new Mock <MessagingProvider>(new OptionsWrapper <ServiceBusOptions>(_serviceBusOptions)); _mockClientFactory = new Mock <ServiceBusClientFactory>( configuration, Mock.Of <AzureComponentFactory>(), _mockProvider.Object, new AzureEventSourceLogForwarder(new NullLoggerFactory()), new OptionsWrapper <ServiceBusOptions>(_serviceBusOptions)); _mockProvider .Setup(p => p.CreateMessageProcessor(_client, _entityPath, It.IsAny <ServiceBusProcessorOptions>())) .Returns(_mockMessageProcessor.Object); _mockProvider .Setup(p => p.CreateClient(_testConnection, It.IsAny <ServiceBusClientOptions>())) .Returns(_client); _loggerFactory = new LoggerFactory(); _loggerProvider = new TestLoggerProvider(); _loggerFactory.AddProvider(_loggerProvider); var concurrencyOptions = new OptionsWrapper <ConcurrencyOptions>(new ConcurrencyOptions()); var mockConcurrencyThrottleManager = new Mock <IConcurrencyThrottleManager>(MockBehavior.Strict); var concurrencyManager = new ConcurrencyManager(concurrencyOptions, _loggerFactory, mockConcurrencyThrottleManager.Object); _listener = new ServiceBusListener( _functionId, ServiceBusEntityType.Queue, _entityPath, false, _serviceBusOptions.AutoCompleteMessages, _mockExecutor.Object, _serviceBusOptions, _connection, _mockProvider.Object, _loggerFactory, false, _mockClientFactory.Object, concurrencyManager); _scaleMonitor = (ServiceBusScaleMonitor)_listener.GetMonitor(); }
// For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301883 public void ConfigureAuth(IAppBuilder app) { // Configure the db context, user manager and signin manager to use a single instance per request app.CreatePerOwinContext(YouTubePlaylistsDbContext.Create); app.CreatePerOwinContext <ApplicationUserManager>(ApplicationUserManager.Create); app.CreatePerOwinContext <ApplicationSignInManager>(ApplicationSignInManager.Create); // Enable the application to use a cookie to store information for the signed in user // and to use a cookie to temporarily store information about a user logging in with a third party login provider // Configure the sign in cookie app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, LoginPath = new PathString("/Account/Login"), Provider = new CookieAuthenticationProvider { OnValidateIdentity = SecurityStampValidator.OnValidateIdentity <ApplicationUserManager, User>( validateInterval: TimeSpan.FromMinutes(30), regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager)) } }); // Use a cookie to temporarily store information about a user logging in with a third party login provider app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie); // Enables the application to temporarily store user information when they are verifying the second factor in the two-factor authentication process. app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5)); // Enables the application to remember the second login verification factor such as phone or email. // Once you check this option, your second step of verification during the login process will be remembered on the device where you logged in from. // This is similar to the RememberMe option when you log in. app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie); // Uncomment the following lines to enable logging in with third party login providers //app.UseMicrosoftAccountAuthentication( // clientId: "", // clientSecret: ""); //app.UseTwitterAuthentication( // consumerKey: "", // consumerSecret: ""); app.UseFacebookAuthentication( appId: ConfigurationUtilities.GetAppSetting("appId"), appSecret: ConfigurationUtilities.GetAppSetting("appSecret")); app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions() { ClientId = ConfigurationUtilities.GetAppSetting("ClientId"), ClientSecret = ConfigurationUtilities.GetAppSetting("ClientSecret") }); }
public ServiceBusListenerTests() { _mockExecutor = new Mock <ITriggeredFunctionExecutor>(MockBehavior.Strict); _client = new ServiceBusClient(_testConnection); ServiceBusProcessor processor = _client.CreateProcessor(_entityPath); ServiceBusReceiver receiver = _client.CreateReceiver(_entityPath); var configuration = ConfigurationUtilities.CreateConfiguration(new KeyValuePair <string, string>("connection", _testConnection)); ServiceBusOptions config = new ServiceBusOptions { ProcessErrorAsync = ExceptionReceivedHandler }; _mockMessageProcessor = new Mock <MessageProcessor>(MockBehavior.Strict, processor); _mockMessagingProvider = new Mock <MessagingProvider>(new OptionsWrapper <ServiceBusOptions>(config)); _mockClientFactory = new Mock <ServiceBusClientFactory>(configuration, Mock.Of <AzureComponentFactory>(), _mockMessagingProvider.Object, new AzureEventSourceLogForwarder(new NullLoggerFactory()), new OptionsWrapper <ServiceBusOptions>(new ServiceBusOptions())); _mockMessagingProvider .Setup(p => p.CreateMessageProcessor(It.IsAny <ServiceBusClient>(), _entityPath, It.IsAny <ServiceBusProcessorOptions>())) .Returns(_mockMessageProcessor.Object); _mockMessagingProvider .Setup(p => p.CreateBatchMessageReceiver(It.IsAny <ServiceBusClient>(), _entityPath, default)) .Returns(receiver); _loggerFactory = new LoggerFactory(); _loggerProvider = new TestLoggerProvider(); _loggerFactory.AddProvider(_loggerProvider); var concurrencyOptions = new OptionsWrapper <ConcurrencyOptions>(new ConcurrencyOptions()); _mockConcurrencyThrottleManager = new Mock <IConcurrencyThrottleManager>(MockBehavior.Strict); var concurrencyManager = new ConcurrencyManager(concurrencyOptions, _loggerFactory, _mockConcurrencyThrottleManager.Object); _listener = new ServiceBusListener( _functionId, ServiceBusEntityType.Queue, _entityPath, false, config.AutoCompleteMessages, _mockExecutor.Object, config, "connection", _mockMessagingProvider.Object, _loggerFactory, false, _mockClientFactory.Object, concurrencyManager); _listener.Started = true; }
public void CreateSimpleNoValuesGeneric() { var typedConfiguration = ConfigurationUtilities.CreateFrom <DemoConfiguration>(null, null, null, null, null); Assert.IsNotNull(typedConfiguration, "Configuration unexpected value"); Assert.IsNotNull(typedConfiguration, "Invalid type returned"); Assert.IsNotNull(typedConfiguration.ObjectValue == default, "ObjectValue not expected"); Assert.IsTrue(typedConfiguration.BooleanValue == default, "BooleanValue not expected"); Assert.IsTrue(typedConfiguration.DateTimeValue == default, "DateTimeValue not expected"); Assert.IsTrue(typedConfiguration.IntegerValue == default, "IntegerValue not expected"); Assert.IsTrue(typedConfiguration.EnumerationValue == default, "EnumerationValue not expected"); Assert.IsTrue(typedConfiguration.TimeSpanValue == default, "TimeSpanValue not expected"); Assert.IsTrue(typedConfiguration.StringValue == default, "StringValue not expected"); }
public void DefaultStrategyIsGreedy() { EventHubOptions options = new EventHubOptions(); var configuration = ConfigurationUtilities.CreateConfiguration(new KeyValuePair <string, string>("connection", ConnectionString)); var factory = ConfigurationUtilities.CreateFactory(configuration, options); var processor = factory.GetEventProcessorHost("connection", "connection", "consumer", true); EventProcessorOptions processorOptions = (EventProcessorOptions)typeof(EventProcessor <EventProcessorHostPartition>) .GetProperty("Options", BindingFlags.NonPublic | BindingFlags.Instance) .GetValue(processor); Assert.AreEqual(LoadBalancingStrategy.Greedy, processorOptions.LoadBalancingStrategy); }
public ServiceBusTriggerAttributeBindingProviderTests() { var configuration = ConfigurationUtilities.CreateConfiguration(new KeyValuePair <string, string>(Constants.DefaultConnectionStringName, "defaultConnection")); Mock <INameResolver> mockResolver = new Mock <INameResolver>(MockBehavior.Strict); ServiceBusOptions options = new ServiceBusOptions(); Mock <IConverterManager> convertManager = new Mock <IConverterManager>(MockBehavior.Default); var provider = new MessagingProvider(new OptionsWrapper <ServiceBusOptions>(options)); var factory = new ServiceBusClientFactory(configuration, new Mock <AzureComponentFactory>().Object, provider); _provider = new ServiceBusTriggerAttributeBindingProvider(mockResolver.Object, options, provider, NullLoggerFactory.Instance, convertManager.Object, factory); }
public void ConsumersAndProducersAreCached() { EventHubOptions options = new EventHubOptions(); var configuration = ConfigurationUtilities.CreateConfiguration(new KeyValuePair <string, string>("connection", ConnectionString)); var factory = ConfigurationUtilities.CreateFactory(configuration, options); var producer = factory.GetEventHubProducerClient("k1", "connection"); var consumer = factory.GetEventHubConsumerClient("k1", "connection", null); var producer2 = factory.GetEventHubProducerClient("k1", "connection"); var consumer2 = factory.GetEventHubConsumerClient("k1", "connection", null); Assert.AreSame(producer, producer2); Assert.AreSame(consumer, consumer2); }
static void Main(string[] args) { AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve); System.Windows.Forms.Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException); System.AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); InstallUtils = new ConfigurationUtilities(); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Dictionary <string, string> commandLineValues = new Dictionary <string, string>(); foreach (string arg in args) { string[] tempSetting = arg.Split(new char[] { '=' }, StringSplitOptions.RemoveEmptyEntries); if (tempSetting.Length == 2) { commandLineValues[tempSetting[0]] = tempSetting[1]; } } if (commandLineValues.ContainsKey(Constants.AdapterType)) { InstallUtils.SetAdapter(commandLineValues[Constants.AdapterType]); } if (commandLineValues.ContainsKey(Constants.DiscoveryServiceAddress)) { InstallUtils.InstallAdapter.DiscoveryServiceAddress = new Uri(commandLineValues[Constants.DiscoveryServiceAddress]); } if (commandLineValues.ContainsKey(Constants.UserName)) { InstallUtils.InstallAdapter.UserName = commandLineValues[Constants.UserName]; } if (commandLineValues.ContainsKey(Constants.Password)) { InstallUtils.InstallAdapter.UserPassword = commandLineValues[Constants.Password]; } if (commandLineValues.ContainsKey(Constants.Organization)) { InstallUtils.InstallAdapter.OrganizationName = commandLineValues[Constants.Organization]; } Application.Run(new MainForm()); TraceArguments(); }
public void CreateSimpleRootFileValuesGeneric() { var typedConfiguration = ConfigurationUtilities.CreateFrom <DemoConfiguration>(null, "SimpleConfigurationRoot.json", null, null, null); Assert.IsNotNull(typedConfiguration, "Configuration unexpected value"); Assert.IsNotNull(typedConfiguration, "Invalid type returned"); Assert.IsNotNull(typedConfiguration.ObjectValue == default, "ObjectValue not expected"); Assert.IsTrue(typedConfiguration.BooleanValue == true, "BooleanValue not expected"); Assert.IsTrue(typedConfiguration.IntegerValue == 88, "IntegerValue not expected"); Assert.IsTrue(typedConfiguration.TimeSpanValue == TimeSpan.Parse("17:17:17.1717"), "TimeSpanValue not expected"); Assert.IsTrue(typedConfiguration.EnumerationValue == DemoType.Complex, "EnumerationValue not expected"); Assert.IsTrue(string.Equals(typedConfiguration.StringValue, "StringFile2", StringComparison.Ordinal), "StringValue not expected"); Assert.IsTrue(string.Equals(typedConfiguration.ObjectValue.StringValue, "SubstringFile2", StringComparison.Ordinal), "ObjectValue::StringValue not expected"); Assert.IsTrue(typedConfiguration.DateTimeValue == DateTime.Parse("2020-10-17 17:05:00.0000"), "DateTimeValue not expected"); }
public void CreateSimpleSubdirectoryFileValuesGeneric() { var typedConfiguration = ConfigurationUtilities.CreateFrom <DemoConfiguration>(null, "SimpleConfiguration.json", "configuration", null, null); Assert.IsNotNull(typedConfiguration, "Configuration unexpected value"); Assert.IsNotNull(typedConfiguration, "Invalid type returned"); Assert.IsNotNull(typedConfiguration.ObjectValue == default, "ObjectValue not expected"); Assert.IsTrue(typedConfiguration.BooleanValue == false, "BooleanValue not expected"); Assert.IsTrue(typedConfiguration.IntegerValue == 99, "IntegerValue not expected"); Assert.IsTrue(typedConfiguration.EnumerationValue == DemoType.Simple, "EnumerationValue not expected"); Assert.IsTrue(typedConfiguration.TimeSpanValue == TimeSpan.Parse("16:16:16.1616"), "TimeSpanValue not expected"); Assert.IsTrue(string.Equals(typedConfiguration.StringValue, "StringFile1", StringComparison.Ordinal), "StringValue not expected"); Assert.IsTrue(string.Equals(typedConfiguration.ObjectValue.StringValue, "SubstringFile1", StringComparison.Ordinal), "ObjectValue::StringValue not expected"); Assert.IsTrue(typedConfiguration.DateTimeValue == DateTime.Parse("2020-09-05 17:05:00.0000"), "DateTimeValue not expected"); }
public void CreateSimpleCommandLineValuesGeneric() { var commandLine = GetSimpleCommandLine(); var typedConfiguration = ConfigurationUtilities.CreateFrom <DemoConfiguration>(null, null, null, commandLine, null); Assert.IsNotNull(typedConfiguration, "Configuration unexpected value"); Assert.IsNotNull(typedConfiguration, "Invalid type returned"); Assert.IsNotNull(typedConfiguration.ObjectValue == default, "ObjectValue not expected"); Assert.IsTrue(typedConfiguration.BooleanValue == true, "BooleanValue not expected"); Assert.IsTrue(typedConfiguration.IntegerValue == 53, "IntegerValue not expected"); Assert.IsTrue(typedConfiguration.EnumerationValue == DemoType.Complex, "EnumerationValue not expected"); Assert.IsTrue(typedConfiguration.TimeSpanValue == TimeSpan.Parse("01:03:04.4567"), "TimeSpanValue not expected"); Assert.IsTrue(string.Equals(typedConfiguration.StringValue, "StringValueCommand", StringComparison.Ordinal), "StringValue not expected"); Assert.IsTrue(string.Equals(typedConfiguration.ObjectValue.StringValue, "SubstringCommand", StringComparison.Ordinal), "ObjectValue::StringValue not expected"); Assert.IsTrue(typedConfiguration.DateTimeValue == DateTime.Parse("2020-09-01 14:00:00.0000"), "DateTimeValue not expected"); }
public void CreateSimpleMemoryValuesGeneric() { var memory = GetSimpleDictionary(); var typedConfiguration = ConfigurationUtilities.CreateFrom <DemoConfiguration>(null, null, null, null, memory); Assert.IsNotNull(typedConfiguration, "Configuration unexpected value"); Assert.IsNotNull(typedConfiguration, "Invalid type returned"); Assert.IsNotNull(typedConfiguration.ObjectValue == default, "ObjectValue not expected"); Assert.IsTrue(typedConfiguration.BooleanValue == false, "BooleanValue not expected"); Assert.IsTrue(typedConfiguration.IntegerValue == 42, "IntegerValue not expected"); Assert.IsTrue(typedConfiguration.TimeSpanValue == TimeSpan.Parse("01:02:03.4567"), "TimeSpanValue not expected"); Assert.IsTrue(typedConfiguration.EnumerationValue == DemoType.Simple, "EnumerationValue not expected"); Assert.IsTrue(string.Equals(typedConfiguration.StringValue, "StringValueMemory", StringComparison.Ordinal), "StringValue not expected"); Assert.IsTrue(string.Equals(typedConfiguration.ObjectValue.StringValue, "SubstringMemory", StringComparison.Ordinal), "ObjectValue::StringValue not expected"); Assert.IsTrue(typedConfiguration.DateTimeValue == DateTime.Parse("2020-09-01 13:00:00.0000"), "DateTimeValue not expected"); }
public void CreateSimpleJsonValuesGeneric() { var json = GetSimpleJson(); var typedConfiguration = ConfigurationUtilities.CreateFrom <DemoConfiguration>(json, null, null, null, null); Assert.IsNotNull(typedConfiguration, "Configuration unexpected value"); Assert.IsNotNull(typedConfiguration, "Invalid type returned"); Assert.IsNotNull(typedConfiguration.ObjectValue == default, "ObjectValue not expected"); Assert.IsTrue(typedConfiguration.BooleanValue == true, "BooleanValue not expected"); Assert.IsTrue(typedConfiguration.IntegerValue == 23, "IntegerValue not expected"); Assert.IsTrue(typedConfiguration.TimeSpanValue == TimeSpan.FromMinutes(123), "TimeSpanValue not expected"); Assert.IsTrue(typedConfiguration.EnumerationValue == DemoType.Complex, "EnumerationValue not expected"); Assert.IsTrue(string.Equals(typedConfiguration.StringValue, "StringValueJson", StringComparison.Ordinal), "StringValue not expected"); Assert.IsTrue(string.Equals(typedConfiguration.ObjectValue.StringValue, "SubstringJson", StringComparison.Ordinal), "ObjectValue::StringValue not expected"); Assert.IsTrue(typedConfiguration.DateTimeValue == DateTime.Parse("2020-09-01 12:00:00.0000"), "DateTimeValue not expected"); }
public void CreatesClientsFromConfigWithConnectionString() { EventHubOptions options = new EventHubOptions(); var configuration = ConfigurationUtilities.CreateConfiguration(new KeyValuePair <string, string>("connection", ConnectionString)); var factory = ConfigurationUtilities.CreateFactory(configuration, options); var producer = factory.GetEventHubProducerClient("k1", "connection"); var consumer = factory.GetEventHubConsumerClient("k1", "connection", null); var host = factory.GetEventProcessorHost("k1", "connection", null, true); Assert.AreEqual("k1", producer.EventHubName); Assert.AreEqual("k1", consumer.EventHubName); Assert.AreEqual("k1", host.EventHubName); Assert.AreEqual("test89123-ns-x.servicebus.windows.net", producer.FullyQualifiedNamespace); Assert.AreEqual("test89123-ns-x.servicebus.windows.net", consumer.FullyQualifiedNamespace); Assert.AreEqual("test89123-ns-x.servicebus.windows.net", host.FullyQualifiedNamespace); }
public void CreateMemoryAndFileAndCommandLineAndJsonMixedValuesGeneric() { var memory = GetSparseDictionary(); var commandLine = GetSparseCommandLine(); var json = GetSparseJson(); var typedConfiguration = ConfigurationUtilities.CreateFrom <DemoConfiguration>(json, "SparseConfiguration.json", "configuration", commandLine, memory); Assert.IsNotNull(typedConfiguration, "Configuration unexpected value"); Assert.IsNotNull(typedConfiguration, "Invalid type returned"); Assert.IsNotNull(typedConfiguration.ObjectValue == default, "ObjectValue not expected"); Assert.IsTrue(typedConfiguration.BooleanValue == true, "BooleanValue not expected"); Assert.IsTrue(typedConfiguration.IntegerValue == 72, "IntegerValue not expected"); Assert.IsTrue(typedConfiguration.TimeSpanValue == TimeSpan.Parse("16:16:16.1616"), "TimeSpanValue not expected"); Assert.IsTrue(typedConfiguration.EnumerationValue == DemoType.Simple, "EnumerationValue not expected"); Assert.IsTrue(string.Equals(typedConfiguration.StringValue, "StringValueMemory", StringComparison.Ordinal), "StringValue not expected"); Assert.IsTrue(string.Equals(typedConfiguration.ObjectValue.StringValue, "SubstringMemory", StringComparison.Ordinal), "ObjectValue::StringValue not expected"); Assert.IsTrue(typedConfiguration.DateTimeValue == DateTime.Parse("2020-09-01 14:00:00.0000"), "DateTimeValue not expected"); }
public JsonResult GetProducto(Producto obj) { try { var bussingLogic = new GP.BusinessLogic.BLProducto(); obj.Stock_Prod = 1; obj.Estado_Prod = 1; var ctx = HttpContext.GetOwinContext(); var tipoUsuario = ctx.Authentication.User.Claims.FirstOrDefault().Value; string draw = Request.Form.GetValues("draw")[0]; int inicio = Convert.ToInt32(Request.Form.GetValues("start").FirstOrDefault()); int fin = Convert.ToInt32(Request.Form.GetValues("length").FirstOrDefault()); obj.Auditoria = new Auditoria { TipoUsuario = tipoUsuario }; obj.Operacion = new Operacion { Inicio = (inicio / fin), Fin = fin }; var response = bussingLogic.GetProducto(obj); var Datos = response.Data; int totalRecords = Datos.Any() ? Datos.FirstOrDefault().Operacion.TotalRows : 0; int recFilter = totalRecords; var result = (new { draw = Convert.ToInt32(draw), recordsTotal = totalRecords, recordsFiltered = recFilter, data = Datos }); return(Json(result)); } catch (Exception ex) { return(Json(ConfigurationUtilities.ErrorCatchDataTable(ex))); } }
public void CreateMemoryAndFileAndCommandLineAndJsonValues() { var memory = GetSimpleDictionary(); var commandLine = GetSimpleCommandLine(); var json = GetSimpleJson(); var configuration = ConfigurationUtilities.CreateFrom(typeof(DemoConfiguration), json, "SimpleConfigurationRoot.json", null, commandLine, memory); var typedConfiguration = configuration as DemoConfiguration; Assert.IsNotNull(configuration, "Configuration unexpected value"); Assert.IsNotNull(typedConfiguration, "Invalid type returned"); Assert.IsNotNull(typedConfiguration.ObjectValue == default, "ObjectValue not expected"); Assert.IsTrue(typedConfiguration.BooleanValue == true, "BooleanValue not expected"); Assert.IsTrue(typedConfiguration.IntegerValue == 23, "IntegerValue not expected"); Assert.IsTrue(typedConfiguration.TimeSpanValue == TimeSpan.FromMinutes(123), "TimeSpanValue not expected"); Assert.IsTrue(typedConfiguration.EnumerationValue == DemoType.Complex, "EnumerationValue not expected"); Assert.IsTrue(string.Equals(typedConfiguration.StringValue, "StringValueJson", StringComparison.Ordinal), "StringValue not expected"); Assert.IsTrue(string.Equals(typedConfiguration.ObjectValue.StringValue, "SubstringJson", StringComparison.Ordinal), "ObjectValue::StringValue not expected"); Assert.IsTrue(typedConfiguration.DateTimeValue == DateTime.Parse("2020-09-01 12:00:00.0000"), "DateTimeValue not expected"); }
public ServiceBusListenerTests() { _mockExecutor = new Mock <ITriggeredFunctionExecutor>(MockBehavior.Strict); var client = new ServiceBusClient(_testConnection); ServiceBusProcessor processor = client.CreateProcessor(_entityPath); ServiceBusReceiver receiver = client.CreateReceiver(_entityPath); var configuration = ConfigurationUtilities.CreateConfiguration(new KeyValuePair <string, string>("connection", _testConnection)); ServiceBusOptions config = new ServiceBusOptions { ExceptionHandler = ExceptionReceivedHandler }; _mockMessageProcessor = new Mock <MessageProcessor>(MockBehavior.Strict, processor, receiver); _mockMessagingProvider = new Mock <MessagingProvider>(new OptionsWrapper <ServiceBusOptions>(config)); _mockClientFactory = new Mock <ServiceBusClientFactory>(configuration, Mock.Of <AzureComponentFactory>(), _mockMessagingProvider.Object); _mockMessagingProvider .Setup(p => p.CreateMessageProcessor(It.IsAny <ServiceBusClient>(), _entityPath)) .Returns(_mockMessageProcessor.Object); _mockMessagingProvider .Setup(p => p.CreateBatchMessageReceiver(It.IsAny <ServiceBusClient>(), _entityPath)) .Returns(receiver); _loggerFactory = new LoggerFactory(); _loggerProvider = new TestLoggerProvider(); _loggerFactory.AddProvider(_loggerProvider); _listener = new ServiceBusListener( _functionId, EntityType.Queue, _entityPath, false, _mockExecutor.Object, config, "connection", _mockMessagingProvider.Object, _loggerFactory, false, _mockClientFactory.Object); }
public void RespectsConnectionOptionsForConsumer(string expectedPathName, string connectionString) { var testEndpoint = new Uri("http://mycustomendpoint.com"); EventHubOptions options = new EventHubOptions { CustomEndpointAddress = testEndpoint, ClientRetryOptions = new EventHubsRetryOptions { MaximumRetries = 10 } }; var configuration = ConfigurationUtilities.CreateConfiguration(new KeyValuePair <string, string>("connection", connectionString)); var factory = ConfigurationUtilities.CreateFactory(configuration, options); var consumer = factory.GetEventHubConsumerClient(expectedPathName, "connection", "consumer"); var consumerClient = (EventHubConsumerClient)typeof(EventHubConsumerClientImpl) .GetField("_client", BindingFlags.NonPublic | BindingFlags.Instance) .GetValue(consumer); EventHubConnection connection = (EventHubConnection)typeof(EventHubConsumerClient) .GetProperty("Connection", BindingFlags.NonPublic | BindingFlags.Instance) .GetValue(consumerClient); EventHubConnectionOptions connectionOptions = (EventHubConnectionOptions)typeof(EventHubConnection) .GetProperty("Options", BindingFlags.NonPublic | BindingFlags.Instance) .GetValue(connection); Assert.AreEqual(testEndpoint, connectionOptions.CustomEndpointAddress); EventHubsRetryPolicy retryPolicy = (EventHubsRetryPolicy)typeof(EventHubConsumerClient) .GetProperty("RetryPolicy", BindingFlags.NonPublic | BindingFlags.Instance) .GetValue(consumerClient); // Reflection was still necessary here because BasicRetryOptions (which is the concrete derived type) // is internal. EventHubsRetryOptions retryOptions = (EventHubsRetryOptions)retryPolicy.GetType() .GetProperty("Options", BindingFlags.Public | BindingFlags.Instance) .GetValue(retryPolicy); Assert.AreEqual(10, retryOptions.MaximumRetries); Assert.AreEqual(expectedPathName, consumer.EventHubName); }
public async System.Threading.Tasks.Task <string> Authorize(string code) { var client = new HttpClient(); var secret = await GetClientSecret(); // confirm legitimacy of the token var response = await client.RequestAuthorizationCodeTokenAsync(new AuthorizationCodeTokenRequest { Address = ConfigurationUtilities.GetString("SSO.TokenUrl"), ClientId = ConfigurationUtilities.GetString("SSO.ClientId"), ClientSecret = secret, ////ConfigurationUtilities.GetString("SSO.Secret"), Code = code, RedirectUri = _postbackAuthUri }); if (response.IsError) { throw new AuthenticationException(response.Error); } // get specific details about the user var userInfoResponse = await client.GetUserInfoAsync(new UserInfoRequest { Address = ConfigurationUtilities.GetString("SSO.UserInfoUrl"), Token = response.AccessToken }); if (userInfoResponse.IsError) { throw new AuthenticationException(userInfoResponse.Error); } return(userInfoResponse.Json.TryGetString("uid")); //note: we can also parse other user details from json response if necessary. e.g.: //userInfoResponse.Json.TryGetString("givenName"), //userInfoResponse.Json.TryGetString("sn") }; }
public void UsesDefaultConnectionToStorageAccount() { EventHubOptions options = new EventHubOptions(); var configuration = ConfigurationUtilities.CreateConfiguration(new KeyValuePair <string, string>("AzureWebJobsStorage", "UseDevelopmentStorage=true")); var factoryMock = new Mock <AzureComponentFactory>(); factoryMock.Setup(m => m.CreateClient( typeof(BlobServiceClient), It.Is <ConfigurationSection>(c => c.Path == "AzureWebJobsStorage"), null, null)) .Returns(new BlobServiceClient(configuration["AzureWebJobsStorage"])); var factory = ConfigurationUtilities.CreateFactory(configuration, options, factoryMock.Object); var client = factory.GetCheckpointStoreClient(); Assert.AreEqual("azure-webjobs-eventhub", client.Name); Assert.AreEqual("devstoreaccount1", client.AccountName); }