// This method returns a user, if the user exists. // If the user exists, it should return ActionResult<User> { Success = true, Response = user-object } // If the user doesn't exist, it should return ActionResult<User> { Success = false, Response = null } // // Remember that you are not supposed to have any try/catch blocks in your code. public async Task <ActionResult <User> > GetUser(string userName) { // This method has been implemented for you as a reference. // It teaches you how to use the various APIs and helper functions but is not // guaranteed to be correct. var logger = new Logger(nameof(UserController)); logger.Write("Get user " + userName); var db = new DatabaseProvider("GetUser", logger); if (!await db.DoesDocumentExist(Constants.UserCollection, userName)) { return(new ActionResult <User>() { Success = false }); } var userDoc = await db.GetDocument(Constants.UserCollection, userName); return(new ActionResult <User>() { Success = true, Response = new User(userName, userDoc) }); }
// This method should retrive the requested picture from the album, if it exists. // It should look up the album and picture information through Azure Storage Provider APIs. public async Task <ActionResult <Picture> > RetrievePicture(string userName, string albumName, string pictureName) { // This method has been implemented for you as a reference. // It teaches you how to use the various APIs and helper functions but is not // guaranteed to be correct. var logger = new Logger(nameof(GalleryController)); logger.Write("Retrieving picture " + userName + ", " + albumName + ", " + pictureName); var db = new DatabaseProvider("RetrievePicture", logger); var storage = new AzureStorageProvider("RetrievePicture", logger); if (!await db.DoesDocumentExist(Constants.UserCollection, userName)) { return(new ActionResult <Picture>() { Success = false }); } var userDoc = await db.GetDocument(Constants.UserCollection, userName); if (!await storage.DoesContainerExist(userName, albumName)) { return(new ActionResult <Picture>() { Success = false }); } if (!await storage.DoesBlobExist(userName, albumName, pictureName)) { return(new ActionResult <Picture>() { Success = false }); } var pictureContents = await storage.GetBlobContents(userName, albumName, pictureName); return(new ActionResult <Picture>() { Success = true, Response = new Picture(new Album(new User(userName, userDoc), albumName), pictureName, pictureContents) }); }
public static async Task DeleteWithConcurrentAPIs(ICoyoteRuntime runtime) { var userName = "******"; var emailAddress = "*****@*****.**"; var phoneNumber = "425-123-1234"; var mailingAddress = "101 100th Ave NE Redmond WA"; var billingAddress = "101 100th Ave NE Redmond WA"; var albumName = "myAlbum"; var pictureName = "pic.jpg"; var pictureContents = "0x2321"; var userController = new UserController(); var galleryController = new GalleryController(); var logger = new Logger("DeleteWithConcurrentAPIs"); var db = new DatabaseProvider("Test", logger); var storage = new AzureStorageProvider("Test", logger); var createResult = await userController.CreateUser(userName, emailAddress, phoneNumber, mailingAddress, billingAddress); Assert(createResult.Success); Assert(createResult.Response.UserName == userName && createResult.Response.EmailAddress == emailAddress); var doc = await db.GetDocument(Constants.UserCollection, userName); Assert(doc[Constants.EmailAddress] == emailAddress); var tasks = new List <Task>(); // We start the delete operation, along with a number of concurrenct APIs in the background // which should not interfere with the invariant we check at the end of the delete operation var deleteResultTask = userController.DeleteUser(userName); tasks.Add(deleteResultTask); const int transcriptLength = 7; for (int i = 0; i < transcriptLength; i++) { var choice = runtime.RandomInteger(transcriptLength); switch (choice) { case 0: tasks.Add(userController.UpdateUserAddress(userName, mailingAddress, billingAddress)); break; case 1: tasks.Add(userController.GetUser(userName)); break; case 2: tasks.Add(galleryController.CreateAlbum(userName, albumName)); break; case 3: tasks.Add(galleryController.DeleteAlbum(userName, albumName)); break; case 4: tasks.Add(galleryController.UploadPicture(userName, albumName, pictureName, pictureContents)); break; case 5: tasks.Add(galleryController.RetrievePicture(userName, albumName, pictureName)); break; case 6: tasks.Add(galleryController.DeletePicture(userName, albumName, pictureName)); break; } } Task.WaitAll(tasks.ToArray()); var deleteResult = deleteResultTask.Result; Assert(deleteResult.Success); Assert(!await db.DoesDocumentExist(Constants.UserCollection, userName)); Assert(!await storage.DoesAccountExits(doc[Constants.UniqueId])); }