Ejemplo n.º 1
0
        public void CreateContext_AttributeKey_Wins(string attributeKey, string configKey, string expectedKey)
        {
            // Arrange
            var attribute = new EasyTableAttribute
            {
                ApiKey = attributeKey
            };

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

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

            // 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);
        }
Ejemplo n.º 2
0
        public void CreateContext_AttributeUri_Wins(string attributeUriString, string configUriString, string expectedUriString)
        {
            // Arrange
            var attribute = new EasyTableAttribute
            {
                MobileAppUri = attributeUriString
            };

            var mockFactory = new Mock <IMobileServiceClientFactory>();

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

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

            // Act
            EasyTableAttributeBindingProvider.CreateContext(config, attribute, null);

            // Assert
            mockFactory.VerifyAll();
        }
Ejemplo n.º 3
0
        public async Task InvalidParameter_Returns_Null(ParameterInfo parameter)
        {
            // Arrange
            var provider = new EasyTableAttributeBindingProvider(_jobConfig, _easyTableConfig, _jobConfig.NameResolver);
            var context  = new BindingProviderContext(parameter, null, CancellationToken.None);

            // Act
            IBinding binding = await provider.TryCreateAsync(context);

            // Assert
            Assert.Null(binding);
        }
Ejemplo n.º 4
0
        public async Task ValidParameter_Returns_CorrectBinding(ParameterInfo parameter, Type expectedBindingType)
        {
            // Arrange
            var provider = new EasyTableAttributeBindingProvider(_jobConfig, _easyTableConfig, _jobConfig.NameResolver);
            var context  = new BindingProviderContext(parameter, null, CancellationToken.None);

            // Act
            IBinding binding = await provider.TryCreateAsync(context);

            // Assert
            Assert.Equal(expectedBindingType, binding.GetType());
        }
Ejemplo n.º 5
0
        public async Task ValidOutputParameter_Returns_CorrectValueProvider(ParameterInfo parameter, Type expectedBindingType)
        {
            // Note: this test is mostly testing the GenericBinder scenarios that EasyTable uses for output bindings.
            // It should eventually make its way to those unit tests.

            // Arrange
            var      provider = new EasyTableAttributeBindingProvider(_jobConfig, _easyTableConfig, _jobConfig.NameResolver);
            var      context  = new BindingProviderContext(parameter, null, CancellationToken.None);
            IBinding binding  = await provider.TryCreateAsync(context);

            // Act
            IValueProvider valueProvider = await binding.BindAsync(null, null);

            // Assert
            Assert.Equal(expectedBindingType, valueProvider.GetType());
        }
Ejemplo n.º 6
0
        public async Task CreateMobileServiceClient_AddsHandler(string apiKey, bool expectHeader)
        {
            // Arrange
            var handler = new TestHandler();
            var factory = new TestMobileServiceClientFactory(handler);
            var client  = EasyTableAttributeBindingProvider.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());
            }
        }
Ejemplo n.º 7
0
        public void CreateContext_ResolvesNames()
        {
            // Arrange
            var resolver = new TestNameResolver();

            resolver.Values.Add("MyTableName", "TestTable");
            resolver.Values.Add("MyId", "abc123");

            var attribute = new EasyTableAttribute
            {
                TableName = "%MyTableName%",
                Id        = "%MyId%"
            };

            // Act
            var context = EasyTableAttributeBindingProvider.CreateContext(_easyTableConfig, attribute, resolver);

            // Assert
            Assert.Equal("TestTable", context.ResolvedTableName);
            Assert.Equal("abc123", context.ResolvedId);
        }