public void CreateContext_AttributeUri_Wins(string attributeConnection, string expectedConnection) { // Arrange var attribute = new DocumentDBAttribute { ConnectionString = attributeConnection }; var mockFactory = new Mock <IDocumentDBServiceFactory>(); mockFactory .Setup(f => f.CreateService(expectedConnection)) .Returns <IDocumentDBService>(null); // Default ConnecitonString will come from app.config var config = new DocumentDBConfiguration { DocumentDBServiceFactory = mockFactory.Object }; // Act DocumentDBAttributeBindingProvider.CreateContext(config, attribute, null); // Assert mockFactory.VerifyAll(); }
public async Task CreateIfNotExists_Creates_IfTrue() { // Arrange string databaseName = "TestDB"; string collectionName = "TestCollection"; var databaseUri = UriFactory.CreateDatabaseUri(databaseName); var mockService = new Mock <IDocumentDBService>(MockBehavior.Strict); mockService .Setup(m => m.CreateDatabaseAsync(It.Is <Database>(d => d.Id == databaseName))) .ReturnsAsync(new Database()); mockService .Setup(m => m.CreateDocumentCollectionAsync(databaseUri, It.Is <DocumentCollection>(d => d.Id == collectionName))) .ReturnsAsync(new DocumentCollection()); var config = new DocumentDBConfiguration { ConnectionString = "AccountEndpoint=http://someuri;AccountKey=some_key", DocumentDBServiceFactory = new TestDocumentDBServiceFactory(mockService.Object) }; var provider = new DocumentDBAttributeBindingProvider(new JobHostConfiguration(), config); // Act await provider.TryCreateAsync(new BindingProviderContext(GetCreateIfNotExistsParameters().Last(), null, CancellationToken.None)); // Assert mockService.VerifyAll(); }
public ActionResult Configure() { var config = DocumentDBConfiguration.RetrieveAppSettings(); return(View(new ConfigurationViewModel { Saved = false, Configuration = config })); }
public void Resolve_FallsBackToNull() { // Arrange ClearEnvironment(); // Act var connString = DocumentDBConfiguration.GetSettingFromConfigOrEnvironment(NeitherKey); // Assert Assert.Null(connString); }
public void CreateContext_UsesDefaultRetryValue() { // Arrange var attribute = new DocumentDBAttribute(); var config = new DocumentDBConfiguration(); // Act var context = config.CreateContext(attribute, new TestTraceWriter()); // Assert Assert.Equal(DocumentDBContext.DefaultMaxThrottleRetries, context.MaxThrottleRetries); }
static Program() { AzureDocumentDBConfiguration = new DocumentDBConfiguration( CloudConfigurationManager.GetSetting("AzureDocumentDBAccountKey"), CloudConfigurationManager.GetSetting("AzureDocumentDBAccountUri"), CloudConfigurationManager.GetSetting("AzureDocumentDBDatabaseName")); ResetDocumentDB = Boolean.TryParse(CloudConfigurationManager.GetSetting("ResetDocumentDB"), out ResetDocumentDB) && ResetDocumentDB; ResetSqlAlpha = Boolean.TryParse(CloudConfigurationManager.GetSetting("ResetSqlAlpha"), out ResetSqlAlpha) && ResetSqlAlpha; ResetSqlBravo = Boolean.TryParse(CloudConfigurationManager.GetSetting("ResetSqlBravo"), out ResetSqlBravo) && ResetSqlBravo; SqlAlphaConnectionString = ConfigurationManager.ConnectionStrings["SqlAlphaConnectionString"].ConnectionString; SqlBravoConnectionString = ConfigurationManager.ConnectionStrings["SqlBravoConnectionString"].ConnectionString; }
public void Resolve_UsesConnectionString_First() { // Arrange SetEnvironment(ConnectionStringKey); // Act var connString = DocumentDBConfiguration.GetSettingFromConfigOrEnvironment(ConnectionStringKey); // Assert Assert.Equal("AccountEndpoint=https://fromconnstrings;AccountKey=some_key", connString); ClearEnvironment(); }
private static Task <IBinding> CreateProviderAndTryCreateAsync(ParameterInfo parameter) { var jobConfig = new JobHostConfiguration(); var docDBConfig = new DocumentDBConfiguration { ConnectionString = "AccountEndpoint=https://someuri;AccountKey=my_key" }; var provider = new DocumentDBAttributeBindingProvider(jobConfig, docDBConfig); var context = new BindingProviderContext(parameter, null, CancellationToken.None); return(provider.TryCreateAsync(context)); }
public void Resolve_UsesAppSetting_Second() { // Arrange SetEnvironment(AppSettingKey); // Act var connString = DocumentDBConfiguration.GetSettingFromConfigOrEnvironment(AppSettingKey); // Assert Assert.Equal("AccountEndpoint=https://fromappsettings2;AccountKey=some_key", connString); ClearEnvironment(); }
public void Resolve_UsesEnvironment_Third() { // Arrange SetEnvironment(EnvironmentKey); // Act var connString = DocumentDBConfiguration.GetSettingFromConfigOrEnvironment(EnvironmentKey); // Assert Assert.Equal("https://fromenvironment/", connString); ClearEnvironment(); }
/// <summary> /// Enables use of the DocumentDB extensions /// </summary> /// <param name="config">The <see cref="JobHostConfiguration"/> to configure.</param> /// <param name="documentDBConfig">The <see cref="DocumentDBConfiguration"/> to use.</param> public static void UseDocumentDB(this JobHostConfiguration config, DocumentDBConfiguration documentDBConfig = null) { if (config == null) { throw new ArgumentNullException("config"); } if (documentDBConfig == null) { documentDBConfig = new DocumentDBConfiguration(); } config.RegisterExtensionConfigProvider(documentDBConfig); }
public void NoConnectionString() { // Arrange var config = new DocumentDBConfiguration { ConnectionString = null }; // Act var ex = Assert.Throws <FunctionIndexingException>( () => RunTest(typeof(DocumentDBNoConnectionStringFunctions), "Broken", new DefaultDocumentDBServiceFactory(), new TestTraceWriter(), documentDBConfig: config)); // Assert Assert.IsType <InvalidOperationException>(ex.InnerException); }
public void CreateContext_UsesDefaultRetryValue() { // Arrange var attribute = new DocumentDBAttribute { ConnectionStringSetting = "AccountEndpoint=https://someuri;AccountKey=c29tZV9rZXk=;" }; var config = new DocumentDBConfiguration(); // Act var context = config.CreateContext(attribute); // Assert Assert.Equal(DocumentDBContext.DefaultMaxThrottleRetries, context.MaxThrottleRetries); }
private static DocumentDBEnumerableBuilder <T> CreateBuilder <T>(out Mock <IDocumentDBService> mockService) where T : class { DocumentDBConfiguration config = new DocumentDBConfiguration(); config.ConnectionString = "AccountEndpoint=https://someuri;AccountKey=c29tZV9rZXk=;"; mockService = new Mock <IDocumentDBService>(MockBehavior.Strict); Mock <IDocumentDBServiceFactory> mockServiceFactory = new Mock <IDocumentDBServiceFactory>(MockBehavior.Strict); mockServiceFactory .Setup(m => m.CreateService(It.IsAny <string>())) .Returns(mockService.Object); config.DocumentDBServiceFactory = mockServiceFactory.Object; return(new DocumentDBEnumerableBuilder <T>(config)); }
public async Task Configuration_Caches_Clients() { // Arrange var config = new DocumentDBConfiguration { ConnectionString = "AccountEndpoint=https://someuri;AccountKey=c29tZV9rZXk=;", }; var attribute = new DocumentDBAttribute(); // Act var context1 = config.CreateContext(attribute); var context2 = config.CreateContext(attribute); var binder = await config.BindForItemAsync(attribute, typeof(Item)); // Assert Assert.Equal(1, config.ClientCache.Count); }
public async Task Configuration_Caches_Clients() { // Arrange var config = new DocumentDBConfiguration { ConnectionString = "AccountEndpoint=https://someuri;AccountKey=some_key", }; var attribute = new DocumentDBAttribute(); // Act var client = config.BindForClient(attribute); var context = config.BindForOutput(attribute, typeof(Item), null); var binder = await config.BindForItemAsync(attribute, typeof(Item), null); // Assert Assert.Equal(1, config.ClientCache.Count); }
/// <inheritdoc/> public override void Initialize() { DocumentDBConfiguration documentDBConfiguration = new DocumentDBConfiguration(); JObject configSection = (JObject)Metadata.GetValue("documentDB", StringComparison.OrdinalIgnoreCase); if (configSection != null) { JToken leaseOptions = configSection["leaseOptions"]; if (leaseOptions != null) { documentDBConfiguration.LeaseOptions = leaseOptions.ToObject <ChangeFeedHostOptions>(); } } Config.UseDocumentDB(documentDBConfiguration); }
private async Task RunTestAsync(Type testType, string testName, IDocumentDBServiceFactory factory, TraceWriter testTrace, object argument = null, string configConnectionString = ConfigConnStr, bool includeDefaultConnectionString = true) { ExplicitTypeLocator locator = new ExplicitTypeLocator(testType); JobHostConfiguration config = new JobHostConfiguration { TypeLocator = locator, }; config.Tracing.Tracers.Add(testTrace); var arguments = new Dictionary <string, object>(); arguments.Add("triggerData", argument); var documentDBConfig = new DocumentDBConfiguration() { ConnectionString = configConnectionString, DocumentDBServiceFactory = factory }; var resolver = new TestNameResolver(); resolver.Values.Add("Database", "ResolvedDatabase"); resolver.Values.Add("Collection", "ResolvedCollection"); resolver.Values.Add("MyConnectionString", AttributeConnStr); resolver.Values.Add("Query", "ResolvedQuery"); if (includeDefaultConnectionString) { resolver.Values.Add(DocumentDBConfiguration.AzureWebJobsDocumentDBConnectionStringName, DefaultConnStr); } config.NameResolver = resolver; config.UseDocumentDB(documentDBConfig); JobHost host = new JobHost(config); await host.StartAsync(); await host.CallAsync(testType.GetMethod(testName), arguments); await host.StopAsync(); }
public async Task CreateIfNotExists_DoesNotCreate_IfFalse() { // Arrange var mockService = new Mock <IDocumentDBService>(MockBehavior.Strict); var config = new DocumentDBConfiguration { ConnectionString = "AccountEndpoint=http://someuri;AccountKey=some_key", DocumentDBServiceFactory = new TestDocumentDBServiceFactory(mockService.Object) }; var attribute = new DocumentDBAttribute { CreateIfNotExists = false }; var provider = new DocumentDBAttributeBindingProvider(new JobHostConfiguration(), config); // Act await provider.TryCreateAsync(new BindingProviderContext(GetCreateIfNotExistsParameters().First(), null, CancellationToken.None)); // Assert // Nothing to assert. Since the service was null, it was never called. }
private DocumentDBConfiguration InitializeConfig(string defaultConnStr) { var config = new DocumentDBConfiguration(); var nameResolver = new TestNameResolver(); nameResolver.Values[DocumentDBConfiguration.AzureWebJobsDocumentDBConnectionStringName] = defaultConnStr; var jobHostConfig = new JobHostConfiguration(); jobHostConfig.AddService <INameResolver>(nameResolver); var context = new ExtensionConfigContext() { Config = jobHostConfig }; config.Initialize(context); return(config); }
public void CreateContext_ResolvesNames() { // Arrange var resolver = new TestNameResolver(); resolver.Values.Add("MyDatabase", "123abc"); resolver.Values.Add("MyCollection", "abc123"); var attribute = new DocumentDBAttribute("%MyDatabase%", "%MyCollection%"); var config = new DocumentDBConfiguration { ConnectionString = "AccountEndpoint=https://someuri;AccountKey=some_key" }; // Act var context = DocumentDBAttributeBindingProvider.CreateContext(config, attribute, resolver); // Assert Assert.Equal("123abc", context.ResolvedDatabaseName); Assert.Equal("abc123", context.ResolvedCollectionName); }
protected async Task <Document> WaitForDocumentAsync(string itemId, string textToMatch = null) { var docUri = UriFactory.CreateDocumentUri("ItemDb", "ItemCollection", itemId); // Get the connection string via the config var connectionString = new DocumentDBConfiguration().ConnectionString; var builder = new DbConnectionStringBuilder(); builder.ConnectionString = connectionString; var serviceUri = new Uri(builder["AccountEndpoint"].ToString()); var client = new DocumentClient(serviceUri, builder["AccountKey"].ToString()); Document doc = null; await TestHelpers.Await(() => { bool result = false; try { var response = Task.Run(() => client.ReadDocumentAsync(docUri)).Result; doc = response.Resource; if (textToMatch != null) { result = doc.GetPropertyValue <string>("text") == textToMatch; } else { result = true; } } catch (Exception) { } return(result); }); return(doc); }
private void RunTest(Type testType, string testName, IDocumentDBServiceFactory factory, TraceWriter testTrace, object argument = null, DocumentDBConfiguration documentDBConfig = null) { ExplicitTypeLocator locator = new ExplicitTypeLocator(testType); JobHostConfiguration config = new JobHostConfiguration { TypeLocator = locator, }; config.Tracing.Tracers.Add(testTrace); var arguments = new Dictionary <string, object>(); arguments.Add("triggerData", argument); if (documentDBConfig == null) { documentDBConfig = new DocumentDBConfiguration() { ConnectionString = "AccountEndpoint=https://someuri;AccountKey=some_key", DocumentDBServiceFactory = factory }; } var resolver = new TestNameResolver(); resolver.Values.Add("Database", "ResolvedDatabase"); resolver.Values.Add("Collection", "ResolvedCollection"); config.NameResolver = resolver; config.UseDocumentDB(documentDBConfig); JobHost host = new JobHost(config); host.Start(); host.Call(testType.GetMethod(testName), arguments); host.Stop(); }
public ActionResult Index() { var config = DocumentDBConfiguration.RetrieveAppSettings(); if (config.Validate()) { DocumentDBService service = new DocumentDBService(config); return(View(new AssetViewModel { Ready = true, Assets = service.GetDocuments(), Count = service.CountDocuments(), AverageCost = service.AverageCost(), LatestAssetName = service.GetLatestAssetName() })); } else { return(View(new AssetViewModel { Ready = false })); } }
private void RunTest(string testName, IDocumentDBServiceFactory factory, TraceWriter testTrace, object argument = null, DocumentDBConfiguration documentDBConfig = null) { RunTest(typeof(DocumentDBEndToEndFunctions), testName, factory, testTrace, argument, documentDBConfig); }
public DocumentDBJArrayBuilder(DocumentDBConfiguration config) { _builder = new DocumentDBEnumerableBuilder <JObject>(config); }
public DocumentDBCollectorBuilder(DocumentDBConfiguration config) { _config = config; }
public DocumentDBClientBuilder(DocumentDBConfiguration config) { _config = config; }
public ActionResult Configure(ConfigurationViewModel viewModel) { DocumentDBConfiguration.SaveAppSettings(viewModel.Configuration); viewModel.Saved = true; return(View(viewModel)); }
public void ValidateInputBindings_Throws_WithInvalidBindings(DocumentDBAttribute attribute, Type parameterType) { Assert.Throws <InvalidOperationException>(() => DocumentDBConfiguration.ValidateInputBinding(attribute, parameterType)); }