Example #1
0
        public void InitializeAnonymous()
        {
            var mock = new Mock <ISmugMugAPI>();

            Album invalidAlbum = null;
            Album validAlbum   = new Album()
            {
                Name = "ValidAlbum", ImageCount = 5
            };

            mock.Setup(api => api.GetAlbum("ValidAlbum")).ReturnsAsync(validAlbum);
            mock.Setup(api => api.GetAlbum("InvalidAlbum")).ReturnsAsync(invalidAlbum);

            AlbumImage nullImage  = null;
            AlbumImage validImage = new AlbumImage()
            {
                FileName = "ValidFileName.jpg", Title = "Valid Image", Format = "JPG"
            };

            mock.Setup(api => api.GetAlbumImage(validAlbum, "ValidImage")).ReturnsAsync(validImage);
            mock.Setup(api => api.GetAlbumImage(validAlbum, "InvalidImage")).ReturnsAsync(nullImage);
            mock.Setup(api => api.GetAlbumImage(invalidAlbum, "ValidImage")).ReturnsAsync(nullImage);
            mock.Setup(api => api.GetAlbumImage(invalidAlbum, "InvalidImage")).ReturnsAsync(nullImage);

            List <AlbumImage> validAlbumImages = new List <AlbumImage>()
            {
                new AlbumImage()
                {
                    FileName = "ValidFileName.jpg", Title = "Valid Image", Format = "JPG"
                }, new AlbumImage()
                {
                    FileName = "AnotherValidFileName.jpg", Title = "Another Valid Image", Format = "JPG"
                }, new AlbumImage()
                {
                    FileName = "ThirdValidFileName.png", Title = "Third Valid Image", Format = "PNG"
                }
            };
            List <AlbumImage> invalidAlbumImages = null;

            mock.Setup(api => api.GetAlbumImages(validAlbum, It.IsInRange <int>(0, int.MaxValue, Range.Inclusive))).ReturnsAsync(validAlbumImages);
            mock.Setup(api => api.GetAlbumImages(validAlbum, It.IsInRange <int>(int.MinValue, 0, Range.Inclusive))).ReturnsAsync(invalidAlbumImages);
            mock.Setup(api => api.GetAlbumImages(invalidAlbum, It.IsInRange <int>(0, int.MaxValue, Range.Inclusive))).ReturnsAsync(invalidAlbumImages);
            mock.Setup(api => api.GetAlbumImages(invalidAlbum, It.IsInRange <int>(int.MinValue, 0, Range.Inclusive))).ReturnsAsync(invalidAlbumImages);
            api = mock.Object;
        }
Example #2
0
        public void InitializeAnonymous()
        {
            var mock = new Mock <ISmugMugAPI>();

            User invalidUser = null;
            User validUser   = new User()
            {
                Name = "Valid User", NickName = "ValidUser"
            };

            mock.Setup(api => api.GetUser("ValidUser")).ReturnsAsync(validUser);
            mock.Setup(api => api.GetUser("InvalidUser")).ReturnsAsync(invalidUser);

            Folder invalidFolder = null;
            Folder validFolder   = new Folder()
            {
                Name = "ValidFolder", NodeID = "ABCDE"
            };

            mock.Setup(api => api.GetFolder("ValidUser", "ValidFolder")).ReturnsAsync(validFolder);
            mock.Setup(api => api.GetFolder("ValidUser", "InvalidFolder")).ReturnsAsync(invalidFolder);

            Album invalidAlbum = null;
            Album validAlbum   = new Album()
            {
                Name = "ValidAlbum", ImageCount = 5
            };
            Album validAlbumWithArguments = new Album()
            {
                Name = "ValidAlbum", ImageCount = 5, Description = "Description"
            };
            Album unownedAlbum = new Album()
            {
                Name = "UnownedAlbum", ImageCount = 5, Privacy = PrivacyType.Private
            };
            Album updatedAlbum = new Album()
            {
                Name = "Updated album", ImageCount = 5
            };

            mock.Setup(api => api.GetAlbum("ValidAlbum")).ReturnsAsync(validAlbum);
            mock.Setup(api => api.GetAlbum("InvalidAlbum")).ReturnsAsync(invalidAlbum);
            mock.Setup(api => api.GetAlbum("UnownedAlbum")).ReturnsAsync(unownedAlbum);

            mock.Setup(api => api.CreateAlbum(It.IsAny <string>(), "ValidUser", "ValidPath", null)).ReturnsAsync(validAlbum);

            mock.Setup(api => api.CreateAlbum(It.IsAny <string>(), "ValidUser", "ValidPath", It.Is <Dictionary <string, string> >(i => i.ContainsKey("Invalid")))).ReturnsAsync(invalidAlbum);
            mock.Setup(api => api.CreateAlbum(It.IsAny <string>(), "ValidUser", "ValidPath", It.Is <Dictionary <string, string> >(i => i.ContainsKey("Description")))).ReturnsAsync(validAlbumWithArguments);
            mock.Setup(api => api.CreateAlbum(It.IsAny <string>(), "ValidUser", "ValidPath", It.Is <Dictionary <string, string> >(i => !i.ContainsKey("Invalid") && !i.ContainsKey("Description")))).ReturnsAsync(validAlbum);

            mock.Setup(api => api.CreateAlbum(It.IsAny <string>(), "ValidUser", "InvalidPath", null)).ReturnsAsync(invalidAlbum);
            mock.Setup(api => api.CreateAlbum(It.IsAny <string>(), "InvalidUser", "ValidPath", null)).ReturnsAsync(invalidAlbum);
            mock.Setup(api => api.CreateAlbum(It.IsAny <string>(), "InvalidUser", "InvalidPath", null)).ReturnsAsync(invalidAlbum);

            mock.Setup(api => api.CreateAlbum(It.IsAny <string>(), validUser, "ValidPath", null)).ReturnsAsync(validAlbum);
            mock.Setup(api => api.CreateAlbum(It.IsAny <string>(), validUser, "ValidPath", It.Is <Dictionary <string, string> >(i => i.ContainsKey("Invalid")))).ReturnsAsync(invalidAlbum);
            mock.Setup(api => api.CreateAlbum(It.IsAny <string>(), validUser, "ValidPath", It.Is <Dictionary <string, string> >(i => i.ContainsKey("Description")))).ReturnsAsync(validAlbumWithArguments);
            mock.Setup(api => api.CreateAlbum(It.IsAny <string>(), validUser, "ValidPath", It.Is <Dictionary <string, string> >(i => !i.ContainsKey("Invalid") && !i.ContainsKey("Description")))).ReturnsAsync(validAlbum);

            mock.Setup(api => api.CreateAlbum(It.IsAny <string>(), validUser, "InvalidPath", null)).ReturnsAsync(invalidAlbum);
            mock.Setup(api => api.CreateAlbum(It.IsAny <string>(), invalidUser, "ValidPath", null)).ReturnsAsync(invalidAlbum);
            mock.Setup(api => api.CreateAlbum(It.IsAny <string>(), invalidUser, "InvalidPath", null)).ReturnsAsync(invalidAlbum);

            mock.Setup(api => api.CreateAlbum(It.IsAny <string>(), validFolder, null)).ReturnsAsync(validAlbum);
            mock.Setup(api => api.CreateAlbum(It.IsAny <string>(), validFolder, It.Is <Dictionary <string, string> >(i => i.ContainsKey("Invalid")))).ReturnsAsync(invalidAlbum);
            mock.Setup(api => api.CreateAlbum(It.IsAny <string>(), validFolder, It.Is <Dictionary <string, string> >(i => i.ContainsKey("Description")))).ReturnsAsync(validAlbumWithArguments);
            mock.Setup(api => api.CreateAlbum(It.IsAny <string>(), validFolder, It.Is <Dictionary <string, string> >(i => !i.ContainsKey("Invalid") && !i.ContainsKey("Description")))).ReturnsAsync(validAlbum);

            mock.Setup(api => api.CreateAlbum(It.IsAny <string>(), invalidFolder, null)).ReturnsAsync(invalidAlbum);
            mock.Setup(api => api.CreateAlbum(It.IsAny <string>(), invalidFolder, null)).ReturnsAsync(invalidAlbum);
            mock.Setup(api => api.CreateAlbum(It.IsAny <string>(), invalidFolder, null)).ReturnsAsync(invalidAlbum);

            mock.Setup(api => api.DeleteAlbum(invalidAlbum)).Throws <ArgumentNullException>();
            mock.Setup(api => api.DeleteAlbum(unownedAlbum)).Throws <HttpRequestException>();

            mock.Setup(api => api.UpdateAlbum(validAlbum, It.Is <Dictionary <string, string> >(i => i.ContainsKey("Name")))).ReturnsAsync(updatedAlbum);
            mock.Setup(api => api.UpdateAlbum(validAlbum, It.Is <Dictionary <string, string> >(i => i.ContainsKey("Invalid")))).Throws <HttpRequestException>();

            mock.Setup(api => api.UpdateAlbum((Album)null, It.IsAny <Dictionary <string, string> >())).Throws <ArgumentNullException>();
            mock.Setup(api => api.UpdateAlbum(validAlbum, null)).Throws <ArgumentNullException>();

            api = mock.Object;
        }
Example #3
0
        public void InitializeAnonymous()
        {
            var mock = new Mock <ISmugMugAPI>();

            Image invalidImage = null;
            Image validImage   = new Image()
            {
                FileName = "ValidFileName.jpg", Title = "Valid Image", Format = "JPG"
            };
            Image unownedImage = new Image()
            {
                FileName = "UnownedFileName.png", Title = "Unowned Image", Format = "PNG"
            };
            Image updatedImage = new Image()
            {
                FileName = "UnownedFileName.png", Title = "Unowned Image", Format = "PNG", Caption = "Updated caption"
            };

            ImageUpload invalidImageUpload = null;
            ImageUpload validImageUpload   = new ImageUpload()
            {
            };

            mock.Setup(api => api.GetImage("ValidImage")).ReturnsAsync(validImage);
            mock.Setup(api => api.GetImage("InvalidImage")).ReturnsAsync(invalidImage);
            mock.Setup(api => api.GetImage("UnownedImage")).ReturnsAsync(unownedImage);

            mock.Setup(api => api.UploadImage("ValidAlbum", "ValidImage")).ReturnsAsync(validImageUpload);
            mock.Setup(api => api.UploadImage("ValidAlbum", "InvalidImage")).ReturnsAsync(invalidImageUpload);

            Node invalidNode = null;
            Node validNode   = new Node()
            {
                Name = "ValidNode", NodeID = "ABCDE", HasChildren = true
            };

            mock.Setup(api => api.GetNode("ValidNode")).ReturnsAsync(validNode);
            mock.Setup(api => api.GetNode("InvalidNode")).ReturnsAsync(invalidNode);
            mock.Setup(api => api.UploadImage(validNode, "ValidImage")).ReturnsAsync(validImageUpload);
            mock.Setup(api => api.UploadImage(validNode, "InvalidImage")).ReturnsAsync(invalidImageUpload);
            mock.Setup(api => api.UploadImage(invalidNode, "ValidImage")).Throws <ArgumentNullException>();
            mock.Setup(api => api.UploadImage(invalidNode, "InvalidImage")).Throws <ArgumentNullException>();

            Album invalidAlbum = null;
            Album validAlbum   = new Album()
            {
                Name = "ValidAlbum", ImageCount = 5
            };

            mock.Setup(api => api.GetAlbum("ValidAlbum")).ReturnsAsync(validAlbum);
            mock.Setup(api => api.GetAlbum("InvalidAlbum")).ReturnsAsync(invalidAlbum);
            mock.Setup(api => api.UploadImage(validAlbum, "ValidImage")).ReturnsAsync(validImageUpload);
            mock.Setup(api => api.UploadImage(validAlbum, "InvalidImage")).ReturnsAsync(invalidImageUpload);
            mock.Setup(api => api.UploadImage(invalidAlbum, "ValidImage")).Throws <ArgumentNullException>();
            mock.Setup(api => api.UploadImage(invalidAlbum, "InvalidImage")).Throws <ArgumentNullException>();

            mock.Setup(api => api.GetImage(validImageUpload)).ReturnsAsync(validImage);
            mock.Setup(api => api.GetImage(invalidImageUpload)).Throws <ArgumentNullException>();

            mock.Setup(api => api.UpdateImage(validImage, It.Is <Dictionary <string, string> >(i => i.ContainsKey("Caption")))).ReturnsAsync(updatedImage);
            mock.Setup(api => api.UpdateImage(validImage, It.Is <Dictionary <string, string> >(i => i.ContainsKey("Invalid")))).Throws <HttpRequestException>();

            mock.Setup(api => api.UpdateImage((Image)null, It.IsAny <Dictionary <string, string> >())).Throws <ArgumentNullException>();
            mock.Setup(api => api.UpdateImage(validImage, null)).Throws <ArgumentNullException>();

            mock.Setup(api => api.DeleteImage(invalidImage)).Throws <ArgumentNullException>();
            mock.Setup(api => api.DeleteImage(unownedImage)).Throws <HttpRequestException>();

            api = mock.Object;
        }