public async Async.Task CanPost_New() { var meta = new Dictionary <string, string> { { "some", "value" } }; var containerName = "test"; var msg = TestHttpRequestData.FromJson("POST", new ContainerCreate(new Container(containerName), meta)); var auth = new TestEndpointAuthorization(RequestType.User, Logger, Context); var func = new ContainersFunction(Logger, auth, Context); var result = await func.Run(msg); Assert.Equal(HttpStatusCode.OK, result.StatusCode); // container should be created with metadata: var client = GetContainerClient(containerName); Assert.True(await client.ExistsAsync()); var props = await client.GetPropertiesAsync(); Assert.Equal(meta, props.Value.Metadata); var response = BodyAs <ContainerInfo>(result); await AssertCanCRUD(response.SasUrl); }
public async Async.Task List_Existing() { var meta1 = new Dictionary <string, string> { { "key1", "value1" } }; var meta2 = new Dictionary <string, string> { { "key2", "value2" } }; await GetContainerClient("one").CreateIfNotExistsAsync(metadata: meta1); await GetContainerClient("two").CreateIfNotExistsAsync(metadata: meta2); var msg = TestHttpRequestData.Empty("GET"); // this means list all var auth = new TestEndpointAuthorization(RequestType.User, Logger, Context); var func = new ContainersFunction(Logger, auth, Context); var result = await func.Run(msg); Assert.Equal(HttpStatusCode.OK, result.StatusCode); var list = BodyAs <ContainerInfoBase[]>(result); // other tests can run in parallel, so filter to just our containers: var cs = list.Where(ci => ci.Name.ContainerName.StartsWith(Context.ServiceConfiguration.OneFuzzStoragePrefix)).ToList(); Assert.Equal(2, cs.Count); // ensure correct metadata was returned. // these will be in order as "one"<"two" Assert.Equal(meta1, cs[0].Metadata); Assert.Equal(meta2, cs[1].Metadata); }
public async Async.Task Get_Missing_Fails() { var msg = TestHttpRequestData.FromJson("GET", new ContainerGet(new Container("container"))); var auth = new TestEndpointAuthorization(RequestType.User, Logger, Context); var func = new ContainersFunction(Logger, auth, Context); var result = await func.Run(msg); Assert.Equal(HttpStatusCode.BadRequest, result.StatusCode); }
public async Async.Task WithoutAuthorization_IsRejected(string method) { var auth = new TestEndpointAuthorization(RequestType.NoAuthorization, Logger, Context); var func = new ContainersFunction(Logger, auth, Context); var result = await func.Run(TestHttpRequestData.Empty(method)); Assert.Equal(HttpStatusCode.Unauthorized, result.StatusCode); var err = BodyAs <Error>(result); Assert.Equal(ErrorCode.UNAUTHORIZED, err.Code); }
public async Async.Task CanDelete() { var containerName = "test"; var client = GetContainerClient(containerName); await client.CreateIfNotExistsAsync(); var msg = TestHttpRequestData.FromJson("DELETE", new ContainerDelete(new Container(containerName))); var auth = new TestEndpointAuthorization(RequestType.User, Logger, Context); var func = new ContainersFunction(Logger, auth, Context); var result = await func.Run(msg); Assert.Equal(HttpStatusCode.OK, result.StatusCode); // container should be gone Assert.False(await client.ExistsAsync()); }
public async Async.Task Get_Existing() { var containerName = "test"; { var client = GetContainerClient(containerName); await client.CreateIfNotExistsAsync(); } var msg = TestHttpRequestData.FromJson("GET", new ContainerGet(new Container(containerName))); var auth = new TestEndpointAuthorization(RequestType.User, Logger, Context); var func = new ContainersFunction(Logger, auth, Context); var result = await func.Run(msg); Assert.Equal(HttpStatusCode.OK, result.StatusCode); // we should get back a SAS URI that works (create, delete, list, read): var info = BodyAs <ContainerInfo>(result); await AssertCanCRUD(info.SasUrl); }