コード例 #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();
            }
        }
コード例 #2
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();
            }
        }
コード例 #3
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();
            }
        }
コード例 #4
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();
            }
        }