public void CreateContext_AttributeUri_Wins(string attributeUriString, string configUriString, string expectedUriString)
        {
            // Arrange
            var attribute = new MobileTableAttribute
            {
                MobileAppUri = attributeUriString
            };

            var mockFactory = new Mock <IMobileServiceClientFactory>();

            mockFactory
            .Setup(f => f.CreateClient(new Uri(expectedUriString), null))
            .Returns <IMobileServiceClient>(null);

            var config = new MobileAppsConfiguration
            {
                MobileAppUri  = new Uri(configUriString),
                ClientFactory = mockFactory.Object
            };

            // Act
            config.CreateContext(attribute);

            // Assert
            mockFactory.VerifyAll();
        }
Beispiel #2
0
        private void RunTest(string testName, IMobileServiceClientFactory factory, TraceWriter testTrace, object argument = null)
        {
            Type testType = typeof(MobileTableEndToEndFunctions);
            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 mobileAppsConfig = new MobileAppsConfiguration
            {
                MobileAppUri  = new Uri("https://someuri"),
                ApiKey        = "api_key",
                ClientFactory = factory
            };

            var resolver = new TestNameResolver();

            config.NameResolver = resolver;

            config.UseMobileApps(mobileAppsConfig);

            JobHost host = new JobHost(config);

            host.Start();
            host.Call(testType.GetMethod(testName), arguments);
            host.Stop();
        }
Beispiel #3
0
        private MobileAppsConfiguration InitializeConfig(string configApiKey, Uri configMobileAppUri)
        {
            var config = new MobileAppsConfiguration
            {
                ApiKey       = configApiKey,
                MobileAppUri = configMobileAppUri
            };

            var nameResolver = new TestNameResolver();

            nameResolver.Values[MobileAppsConfiguration.AzureWebJobsMobileAppApiKeyName] = "Default";
            nameResolver.Values[MobileAppsConfiguration.AzureWebJobsMobileAppUriName]    = "https://default";
            nameResolver.Values["Attribute"] = "ResolvedAttribute";

            var jobHostConfig = new JobHostConfiguration();

            jobHostConfig.NameResolver = nameResolver;

            var context = new ExtensionConfigContext
            {
                Config = jobHostConfig
            };

            config.Initialize(context);

            return(config);
        }
        public void CreateContext_AttributeKey_Wins(string attributeKey, string configKey, string expectedKey)
        {
            // Arrange
            var attribute = new MobileTableAttribute
            {
                ApiKey = attributeKey
            };

            var handler = new TestHandler();
            var config  = new MobileAppsConfiguration
            {
                MobileAppUri  = new Uri("https://someuri"),
                ApiKey        = configKey,
                ClientFactory = new TestMobileServiceClientFactory(handler)
            };

            // Act
            var context = config.CreateContext(attribute);

            // Assert
            // Issue a request to check the header that's being sent.
            context.Client.GetTable("Test").LookupAsync("123");

            IEnumerable <string> values = null;
            string actualKey            = null;

            if (handler.IssuedRequest.Headers.TryGetValues("ZUMO-API-KEY", out values))
            {
                actualKey = values.Single();
            }

            Assert.Equal(expectedKey, actualKey);
        }
Beispiel #5
0
        public void GetClient_Caches()
        {
            var mockFactory = new Mock <IMobileServiceClientFactory>(MockBehavior.Strict);
            Uri uri1        = new Uri("https://someuri1");
            Uri uri2        = new Uri("https://someuri2");

            mockFactory
            .Setup(f => f.CreateClient(It.IsAny <Uri>(), null))
            .Returns <Uri, HttpMessageHandler[]>((uri, handlers) => new MobileServiceClient(uri, handlers));

            var config = new MobileAppsConfiguration
            {
                ClientFactory = mockFactory.Object
            };

            var client1 = config.GetClient(uri1, null);
            var client2 = config.GetClient(uri1, null);
            var client3 = config.GetClient(uri2, null);
            var client4 = config.GetClient(uri1, null);

            Assert.Same(client1, client2);
            Assert.Same(client2, client4);
            Assert.NotSame(client1, client3);
            mockFactory.Verify(f => f.CreateClient(uri1, null), Times.Once);
            mockFactory.Verify(f => f.CreateClient(uri2, null), Times.Once);
        }
        public async Task BindForQuery_ReturnsCorrectType()
        {
            var attribute = new MobileTableAttribute();
            var config    = new MobileAppsConfiguration();

            var query = await config.BindForQueryAsync(attribute, typeof(IMobileServiceTableQuery <TodoItem>));

            Assert.True(typeof(IMobileServiceTableQuery <TodoItem>).IsAssignableFrom(query.GetType()));
        }
Beispiel #7
0
        public void NoUri()
        {
            var config = new MobileAppsConfiguration
            {
                MobileAppUri = null
            };
            var ex = Assert.Throws <FunctionIndexingException>(() => IndexBindings(typeof(MobileTableNoUri), config));

            Assert.IsType <InvalidOperationException>(ex.InnerException);
        }
        public void Resolve_FallsBackToNull()
        {
            // Arrange
            ClearEnvironment();

            // Act
            var mobileAppUri = MobileAppsConfiguration.GetSettingFromConfigOrEnvironment(NeitherKey);

            // Assert
            Assert.Null(mobileAppUri);
        }
Beispiel #9
0
        public void CreateCacheKey_SucceedsWith_NullApiKey()
        {
            // Arrange
            Uri uri = new Uri("http://someuri");

            // Act
            string key = MobileAppsConfiguration.GetCacheKey(uri, null);

            // Assert
            Assert.Equal(uri.ToString() + ";", key);
        }
        public void Resolve_UsesAppSettings_First()
        {
            // Arrange
            SetEnvironment(AppSettingKey);

            // Act
            var mobileAppUri = MobileAppsConfiguration.GetSettingFromConfigOrEnvironment(AppSettingKey);

            // Assert
            Assert.Equal("https://fromappsettings/", mobileAppUri.ToString());

            ClearEnvironment();
        }
Beispiel #11
0
        public void BindForQuery_ReturnsCorrectType()
        {
            var attribute = new MobileTableAttribute();
            var config    = new MobileAppsConfiguration
            {
                MobileAppUri = new Uri("https://someuri/")
            };

            var queryBuilder = new MobileTableQueryBuilder <TodoItem>(config);
            var query        = queryBuilder.Convert(attribute);

            Assert.True(typeof(IMobileServiceTableQuery <TodoItem>).IsAssignableFrom(query.GetType()));
        }
        public async Task BindForTable_Poco_ReturnsCorrectTable()
        {
            // Arrange
            var attribute = new MobileTableAttribute();
            var config    = new MobileAppsConfiguration();

            // Act
            var table = await config.BindForTableAsync(attribute, typeof(IMobileServiceTable <TodoItem>)) as IMobileServiceTable <TodoItem>;

            // Assert
            Assert.NotNull(table);
            Assert.Equal("TodoItem", table.TableName);
        }
        public void Resolve_UsesEnvironment_Second()
        {
            // Arrange
            SetEnvironment(EnvironmentKey);

            // Act
            var mobileAppUri = MobileAppsConfiguration.GetSettingFromConfigOrEnvironment(EnvironmentKey);

            // Assert
            Assert.Equal("https://fromenvironment/", mobileAppUri.ToString());

            ClearEnvironment();
        }
        public async Task BindForQuery_WithTableName_ReturnsCorrectType()
        {
            var attribute = new MobileTableAttribute
            {
                TableName = "SomeOtherTable"
            };

            var config = new MobileAppsConfiguration();

            var query = await config.BindForQueryAsync(attribute, typeof(IMobileServiceTableQuery <TodoItem>)) as IMobileServiceTableQuery <TodoItem>;

            Assert.NotNull(query);
            Assert.Equal("SomeOtherTable", query.Table.TableName);
        }
Beispiel #15
0
        /// <summary>
        /// Enables use of the Mobile App extensions.
        /// </summary>
        /// <param name="config">The <see cref="JobHostConfiguration"/> to configure.</param>
        /// <param name="mobileAppsConfig">The <see cref="MobileAppsConfiguration"/> to use.</param>
        public static void UseMobileApps(this JobHostConfiguration config, MobileAppsConfiguration mobileAppsConfig = null)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            if (mobileAppsConfig == null)
            {
                mobileAppsConfig = new MobileAppsConfiguration();
            }

            config.RegisterExtensionConfigProvider(mobileAppsConfig);
        }
Beispiel #16
0
        public void CreateCacheKey_MatchesUri_DifferentCasing()
        {
            // Arrange
            Uri uri1 = new Uri("http://someuri");
            Uri uri2 = new Uri("http://SOMEURI");

            string apiKey = "api_key";

            // Act
            string key1 = MobileAppsConfiguration.GetCacheKey(uri1, apiKey);
            string key2 = MobileAppsConfiguration.GetCacheKey(uri2, apiKey);

            // Assert
            Assert.Equal(key1, key2);
        }
        private async Task RunTestAsync(string testName, IMobileServiceClientFactory factory, TraceWriter testTrace, object argument = null,
                                        Uri configUri = null, string configKey = null, bool includeDefaultKey = true, bool includeDefaultUri = true)
        {
            Type testType = typeof(MobileTableEndToEndFunctions);
            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 mobileAppsConfig = new MobileAppsConfiguration
            {
                MobileAppUri  = configUri,
                ApiKey        = configKey,
                ClientFactory = factory
            };

            var resolver = new TestNameResolver();

            resolver.Values.Add("MyUri", AttributeUri);
            resolver.Values.Add("MyKey", AttributeKey);
            if (includeDefaultUri)
            {
                resolver.Values.Add(MobileAppsConfiguration.AzureWebJobsMobileAppUriName, DefaultUri);
            }
            if (includeDefaultKey)
            {
                resolver.Values.Add(MobileAppsConfiguration.AzureWebJobsMobileAppApiKeyName, DefaultKey);
            }

            config.NameResolver = resolver;

            config.UseMobileApps(mobileAppsConfig);

            JobHost host = new JobHost(config);

            await host.StartAsync();

            await host.CallAsync(testType.GetMethod(testName), arguments);

            await host.StopAsync();
        }
        public void BindForTable_JObject_ReturnsCorrectTable()
        {
            // Arrange
            var attribute = new MobileTableAttribute
            {
                TableName = "TodoItem"
            };
            var config = new MobileAppsConfiguration();

            // Act
            var table = config.BindForTable(attribute);

            // Assert
            Assert.NotNull(table);
            Assert.Equal("TodoItem", table.TableName);
        }
Beispiel #19
0
        private void IndexBindings(Type testType, MobileAppsConfiguration mobileConfig = null)
        {
            // Just start the jobhost -- this should fail if function indexing fails.

            ExplicitTypeLocator  locator = new ExplicitTypeLocator(testType);
            JobHostConfiguration config  = new JobHostConfiguration
            {
                TypeLocator = locator,
            };

            config.UseMobileApps(mobileConfig);

            JobHost host = new JobHost(config);

            host.Start();
            host.Stop();
        }
Beispiel #20
0
        public void BindForTable_Poco_ReturnsCorrectTable()
        {
            // Arrange
            var attribute = new MobileTableAttribute();
            var config    = new MobileAppsConfiguration
            {
                MobileAppUri = new Uri("https://someuri/")
            };

            // Act
            var tableBuilder = new MobileTablePocoTableBuilder <TodoItem>(config);
            var table        = tableBuilder.Convert(attribute);

            // Assert
            Assert.NotNull(table);
            Assert.Equal("TodoItem", table.TableName);
        }
        public async Task GetValue_PocoWithTableName_ReturnsCorrectTable()
        {
            // Arrange
            var attribute = new MobileTableAttribute
            {
                TableName = "SomeOtherTable"
            };
            var config = new MobileAppsConfiguration
            {
                MobileAppUri = new Uri("https://someuri/")
            };
            // Act
            var table = await config.BindForTableAsync(attribute, typeof(IMobileServiceTable <TodoItem>)) as IMobileServiceTable <TodoItem>;

            // Assert
            Assert.NotNull(table);
            Assert.Equal("SomeOtherTable", table.TableName);
        }
Beispiel #22
0
        public void BindForQuery_WithTableName_ReturnsCorrectType()
        {
            var attribute = new MobileTableAttribute
            {
                TableName = "SomeOtherTable"
            };

            var config = new MobileAppsConfiguration
            {
                MobileAppUri = new Uri("https://someuri/")
            };

            var queryBuilder = new MobileTableQueryBuilder <TodoItem>(config);
            var query        = queryBuilder.Convert(attribute);

            Assert.NotNull(query);
            Assert.Equal("SomeOtherTable", query.Table.TableName);
        }
Beispiel #23
0
        public void GetValue_PocoWithTableName_ReturnsCorrectTable()
        {
            // Arrange
            var attribute = new MobileTableAttribute
            {
                TableName = "SomeOtherTable"
            };
            var config = new MobileAppsConfiguration
            {
                MobileAppUri = new Uri("https://someuri/")
            };
            // Act
            var tableBuilder = new MobileTablePocoTableBuilder <TodoItem>(config);
            var table        = tableBuilder.Convert(attribute);

            // Assert
            Assert.NotNull(table);
            Assert.Equal("SomeOtherTable", table.TableName);
        }
Beispiel #24
0
        public async Task CreateMobileServiceClient_AddsHandler(string apiKey, bool expectHeader)
        {
            // Arrange
            var handler = new TestHandler();
            var factory = new TestMobileServiceClientFactory(handler);
            var client  = MobileAppsConfiguration.CreateMobileServiceClient(factory, new Uri("https://someuri/"), apiKey);
            var table   = client.GetTable("FakeTable");

            // Act
            await table.ReadAsync(string.Empty);

            // Assert
            IEnumerable <string> values = null;
            bool foundHeader            = handler.IssuedRequest.Headers.TryGetValues(MobileServiceApiKeyHandler.ZumoApiKeyHeaderName, out values);

            Assert.Equal(expectHeader, foundHeader);
            if (expectHeader)
            {
                Assert.Equal("my_api_key", values.Single());
            }
        }
        protected async Task <JToken> WaitForMobileTableRecordAsync(string tableName, string itemId, string textToMatch = null)
        {
            // Get the URI by creating a config.
            var    config = new MobileAppsConfiguration();
            var    client = new MobileServiceClient(config.MobileAppUri);
            JToken item   = null;
            var    table  = client.GetTable(tableName);
            await TestHelpers.Await(() =>
            {
                bool result = false;
                try
                {
                    item = Task.Run(() => table.LookupAsync(itemId)).Result;
                    if (textToMatch != null)
                    {
                        result = item["Text"].ToString() == textToMatch;
                    }
                    else
                    {
                        result = true;
                    }
                }
                catch (AggregateException aggEx)
                {
                    var ex = (MobileServiceInvalidOperationException)aggEx.InnerException;
                    if (ex.Response.StatusCode != HttpStatusCode.NotFound)
                    {
                        throw;
                    }
                }

                return(result);
            });

            return(item);
        }
 public MobileTableQueryBuilder(MobileAppsConfiguration config)
 {
     _config = config;
 }
 public MobileTablePocoTableBuilder(MobileAppsConfiguration config)
 {
     _config = config;
 }
 public MobileTableJObjectTableBuilder(MobileAppsConfiguration config)
 {
     _config = config;
 }
Beispiel #29
0
 public MobileTableCollectorBuilder(MobileAppsConfiguration config)
 {
     _config = config;
 }
Beispiel #30
0
 public MobileTableClientBuilder(MobileAppsConfiguration config)
 {
     _config = config;
 }