Esempio n. 1
0
        public async Task LookupAsync_DoesNotCreateStorageTable()
        {
            // Behavior is same for Delete, Undelete, Update and Lookup which each depend on GetCurrentItem
            var isolatedManager = new StorageDomainManagerMock(this, "lookupTableNotFound");

            try
            {
                await isolatedManager.Table.DeleteIfExistsAsync();

                Assert.False(isolatedManager.Table.Exists());

                string id = new CompositeTableKey("unknown", "item").ToString();
                HttpResponseException ex = await AssertEx.ThrowsAsync <HttpResponseException>(async() => await isolatedManager.LookupAsync(id));

                Assert.Equal(HttpStatusCode.NotFound, ex.Response.StatusCode);

                // Table.ExecuteAsync for retrieve returns TableResult with 404 status code when table is not found
                // instead of throwing exception. As a result, the lookup fails fast and we do not create the table.
                Assert.False(isolatedManager.Table.Exists());
            }
            finally
            {
                isolatedManager.Dispose();
            }
        }
Esempio n. 2
0
        public async Task ReplaceAsync_CreatesStorageTable()
        {
            var isolatedManager = new StorageDomainManagerMock(this, "replaceTableNotFound");

            try
            {
                await isolatedManager.Table.DeleteIfExistsAsync();

                Assert.False(isolatedManager.Table.Exists());

                var person      = TestData.Persons.First();
                var personClone = new Person()
                {
                    FirstName    = person.FirstName,
                    LastName     = person.LastName,
                    Age          = person.Age,
                    PartitionKey = person.LastName,
                    RowKey       = person.FirstName,
                    ETag         = "*"
                };

                // First replace attempt will fail due to table not found (404) exception. ExecuteOperationAsync will create
                // the table on retry, but the attempt will fail again due to resource not found (404). The consecutive 404s
                // verify that ExecuteOperationAsync does not continue to recurse.
                HttpResponseException ex = await AssertEx.ThrowsAsync <HttpResponseException>(async() => await isolatedManager.ReplaceAsync(personClone.Id, personClone));

                Assert.Equal(HttpStatusCode.BadRequest, ex.Response.StatusCode);

                Assert.True(isolatedManager.Table.Exists());
            }
            finally
            {
                isolatedManager.Dispose();
            }
        }
Esempio n. 3
0
        public async Task InsertAsync_CreatesStorageTable()
        {
            var isolatedManager = new StorageDomainManagerMock(this, "insertTableNotFound");

            try
            {
                await isolatedManager.Table.DeleteIfExistsAsync();

                Assert.False(isolatedManager.Table.Exists());

                var person      = TestData.Persons.First();
                var personClone = new Person()
                {
                    FirstName    = person.FirstName,
                    LastName     = person.LastName,
                    Age          = person.Age,
                    PartitionKey = person.LastName,
                    RowKey       = person.FirstName
                };

                await isolatedManager.InsertAsync(personClone);

                Assert.True(isolatedManager.Table.Exists());
            }
            finally
            {
                isolatedManager.Dispose();
            }
        }
Esempio n. 4
0
        public StorageDomainManagerTests()
        {
            string connectionStringEnvVar = Environment.GetEnvironmentVariable(ConnectionStringEnvVar);

            if (!string.IsNullOrEmpty(connectionStringEnvVar))
            {
                this.connectionString = Environment.ExpandEnvironmentVariables(connectionStringEnvVar);
            }

            if (string.IsNullOrWhiteSpace(this.connectionString))
            {
                this.connectionString = "UseDevelopmentStorage=true";
            }

            this.config   = new HttpConfiguration();
            this.settings = new MobileAppSettingsDictionary();
            this.settings.Connections.Add(ConnectionStringName, new ConnectionSettings(ConnectionStringName, this.connectionString));

            var providerMock = new Mock <IMobileAppSettingsProvider>();

            providerMock.Setup(p => p.GetMobileAppSettings()).Returns(this.settings);
            this.config.SetMobileAppSettingsProvider(providerMock.Object);

            this.request = new HttpRequestMessage(HttpMethod.Get, new Uri("http://localhost"));
            this.request.SetConfiguration(this.config);
            this.querySettings = StorageDomainManager <Person> .GetDefaultQuerySettings();

            this.validationSettings = StorageDomainManager <Person> .GetDefaultValidationSettings();

            this.manager = new StorageDomainManagerMock(this);
        }
Esempio n. 5
0
        public void Context_IsCached()
        {
            // Act
            StorageDomainManagerMock dm1 = new StorageDomainManagerMock(this);
            StorageDomainManagerMock dm2 = new StorageDomainManagerMock(this);

            // Assert
            Assert.Same(dm1.StorageAccount, dm2.StorageAccount);
        }
Esempio n. 6
0
        public async Task QueryAsync_CreatesStorageTable()
        {
            var isolatedManager = new StorageDomainManagerMock(this, "queryTableNotFound");

            try
            {
                await isolatedManager.Table.DeleteIfExistsAsync();

                Assert.False(isolatedManager.Table.Exists());

                ODataQueryContext context = new ODataQueryContext(EdmModelMock.Create <Person>("Persons"), typeof(Person));
                ODataQueryOptions query   = new ODataQueryOptions(context, this.request);

                IEnumerable <Person> actual = await isolatedManager.QueryAsync(query);

                Assert.Equal(0, actual.Count());

                Assert.True(isolatedManager.Table.Exists());
            }
            finally
            {
                isolatedManager.Dispose();
            }
        }