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
        // 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)
            });
        }