Ejemplo n.º 1
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;
        }
Ejemplo n.º 2
0
        public void InitializeAnonymous()
        {
            var mock = new Mock <ISmugMugAPI>();

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

            mock.Setup(api => api.GetNode("ValidNode")).ReturnsAsync(validNode);
            mock.Setup(api => api.GetNode("InvalidNode")).ReturnsAsync(invalidNode);
            mock.Setup(api => api.GetNode("UnownedNode")).ReturnsAsync(unownedNode);
            mock.Setup(api => api.GetNode("ValidNodeNoChildren")).ReturnsAsync(validNodeNoChildren);

            User nullUser  = 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(nullUser);

            mock.Setup(api => api.GetRootNode(validUser)).ReturnsAsync(validNode);
            mock.Setup(api => api.GetRootNode(nullUser)).ReturnsAsync(invalidNode);

            Node folderNode = new Node()
            {
                Type = NodeType.Folder, Name = "FolderNode", NodeID = "ABCDE"
            };
            Node folderNodeWithArugments = new Node()
            {
                Type = NodeType.Folder, Name = "FolderNode", NodeID = "ABCDE", Description = "Description"
            };
            Node albumNode = new Node()
            {
                Type = NodeType.Album, Name = "AlbumNode", NodeID = "ABCDE"
            };
            Node pageNode = new Node()
            {
                Type = NodeType.Page, Name = "PageNode", NodeID = "ABCDE"
            };
            Node nullNode    = null;
            Node updatedNode = new Node()
            {
                Type = NodeType.Folder, Name = "Updated node", NodeID = "ABCDE"
            };

            mock.Setup(api => api.CreateNode(NodeType.Folder, It.IsAny <string>(), "ValidPath", It.Is <Dictionary <string, string> >(i => i.ContainsKey("Invalid")))).ReturnsAsync(nullNode);
            mock.Setup(api => api.CreateNode(NodeType.Folder, It.IsAny <string>(), "ValidPath", It.Is <Dictionary <string, string> >(i => i.ContainsKey("Description")))).ReturnsAsync(folderNodeWithArugments);
            mock.Setup(api => api.CreateNode(NodeType.Folder, It.IsAny <string>(), "ValidPath", It.Is <Dictionary <string, string> >(i => !i.ContainsKey("Invalid") && !i.ContainsKey("Description")))).ReturnsAsync(folderNode);
            mock.Setup(api => api.CreateNode(NodeType.Folder, It.IsAny <string>(), "InvalidPath", It.IsAny <Dictionary <string, string> >())).ReturnsAsync(nullNode);

            mock.Setup(api => api.CreateNode(NodeType.Album, It.IsAny <string>(), "ValidPath", null)).ReturnsAsync(albumNode);
            mock.Setup(api => api.CreateNode(NodeType.Album, It.IsAny <string>(), "InvalidPath", It.IsAny <Dictionary <string, string> >())).ReturnsAsync(nullNode);

            mock.Setup(api => api.CreateNode(NodeType.Page, It.IsAny <string>(), "ValidPath", null)).ReturnsAsync(pageNode);
            mock.Setup(api => api.CreateNode(NodeType.Page, It.IsAny <string>(), "InvalidPath", It.IsAny <Dictionary <string, string> >())).ReturnsAsync(nullNode);

            List <Node> validNodes = new List <Node>()
            {
                folderNode, albumNode, pageNode
            };
            List <Node> invalidNodes = null;

            mock.Setup(api => api.GetChildNodes(validNode, It.IsInRange <int>(0, int.MaxValue, Range.Inclusive))).ReturnsAsync(validNodes);
            mock.Setup(api => api.GetChildNodes(validNode, It.IsInRange <int>(int.MinValue, 0, Range.Inclusive))).ReturnsAsync(invalidNodes);
            mock.Setup(api => api.GetChildNodes(invalidNode, It.IsInRange <int>(0, int.MaxValue, Range.Inclusive))).ReturnsAsync(invalidNodes);
            mock.Setup(api => api.GetChildNodes(invalidNode, It.IsInRange <int>(int.MinValue, 0, Range.Inclusive))).ReturnsAsync(invalidNodes);
            mock.Setup(api => api.GetChildNodes(validNodeNoChildren, It.IsInRange <int>(int.MinValue, int.MaxValue, Range.Inclusive))).ReturnsAsync(invalidNodes);

            mock.Setup(api => api.DeleteNode(invalidNode)).Throws <ArgumentNullException>();
            mock.Setup(api => api.DeleteNode(unownedNode)).Throws <HttpRequestException>();

            mock.Setup(api => api.UpdateNode(validNode, It.Is <Dictionary <string, string> >(i => i.ContainsKey("Name")))).ReturnsAsync(updatedNode);
            mock.Setup(api => api.UpdateNode(validNode, It.Is <Dictionary <string, string> >(i => i.ContainsKey("Invalid")))).Throws <HttpRequestException>();

            mock.Setup(api => api.UpdateNode((Node)null, It.IsAny <Dictionary <string, string> >())).Throws <ArgumentNullException>();
            mock.Setup(api => api.UpdateNode(validNode, null)).Throws <ArgumentNullException>();

            api = mock.Object;
        }