Exemplo n.º 1
0
        public static async Task ConcurrentAlbumCreates(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 storageProvider = new AzureStorageProvider("Test", new Logger("Test"));

            var userController = new UserController();
            var createResult   = await userController.CreateUser(userName, emailAddress, phoneNumber, mailingAddress, billingAddress);

            Assert(createResult.Success);
            CheckUser(createResult.Response);
            Assert(!await storageProvider.DoesAccountExits(userName));

            var galleryController = new GalleryController();
            var createAlbumTask1  = galleryController.CreateAlbum(userName, albumName);
            var createAlbumTask2  = galleryController.CreateAlbum(userName, albumName);

            await Task.WhenAll(createAlbumTask1, createAlbumTask2);

            Assert(createAlbumTask1.Result.Success ^ createAlbumTask2.Result.Success);
            Assert(await storageProvider.DoesAccountExits(userName));
            Assert(await storageProvider.DoesContainerExist(userName, albumName));

            var album = createAlbumTask1.Result.Success ?
                        createAlbumTask1.Result.Response :
                        createAlbumTask2.Result.Response;

            CheckAlbum(album);
        }
Exemplo n.º 2
0
        public async Task <ActionResult <Picture> > DeletePicture(string userName, string albumName, string pictureName)
        {
            var logger = new Logger(nameof(GalleryController));

            logger.Write("Deleting picture " + userName + ", " + albumName + ", " + pictureName);

            var db      = new DatabaseProvider("DeletePicture", logger);
            var storage = new AzureStorageProvider("DeletePicture", logger);

            // TODO: Implement the logic

            return(null);
        }
Exemplo n.º 3
0
        public async Task <ActionResult <Album> > CreateAlbum(string userName, string albumName)
        {
            var logger = new Logger(nameof(GalleryController));

            logger.Write("Creating album " + userName + ", " + albumName);

            var db      = new DatabaseProvider("CreateAlbum", logger);
            var storage = new AzureStorageProvider("CreateAlbum", logger);

            // TODO: Implement the logic

            // Remember to lazily create the storage account for the user if it doesn't exist
            // Also, don't forget to delete that storage account when the user is deleted in the UserController

            return(null);
        }
Exemplo n.º 4
0
        // 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)
            });
        }
Exemplo n.º 5
0
        public static async Task ConcurrentAlbumDeletes(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 storageProvider = new AzureStorageProvider("Test", new Logger("Test"));

            var userController = new UserController();
            var createResult   = await userController.CreateUser(userName, emailAddress, phoneNumber, mailingAddress, billingAddress);

            Assert(createResult.Success);
            CheckUser(createResult.Response);
            Assert(!await storageProvider.DoesAccountExits(userName));

            var galleryController = new GalleryController();
            var createAlbumResult = await galleryController.CreateAlbum(userName, albumName);

            Assert(createAlbumResult.Success);
            CheckAlbum(createAlbumResult.Response);
            Assert(await storageProvider.DoesAccountExits(userName));

            var albumDeleteTask1 = galleryController.DeleteAlbum(userName, albumName);
            var albumDeleteTask2 = galleryController.DeleteAlbum(userName, albumName);
            await Task.WhenAll(albumDeleteTask1, albumDeleteTask2);

            Assert(albumDeleteTask1.Result.Success ^ albumDeleteTask2.Result.Success);
            var album = albumDeleteTask1.Result.Success ?
                        albumDeleteTask1.Result.Response :
                        albumDeleteTask2.Result.Response;

            CheckAlbum(album);

            // Assert that even though the album has been deleted the storage account is still there
            // as it should only be deleted when the user is deleted
            Assert(await storageProvider.DoesAccountExits(userName));
        }
Exemplo n.º 6
0
 public static void IterationCleanup()
 {
     DatabaseProvider.Cleanup();
     AzureStorageProvider.Cleanup();
     Logger.ResetNextLoggerId();
 }
Exemplo n.º 7
0
        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]));
        }