示例#1
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"
            };
            Folder validFolderWithArguments = new Folder()
            {
                Name = "ValidFolder", NodeID = "ABCDE", Description = "Description"
            };
            Folder unownedFolder = new Folder()
            {
                Name = "UnownedFolder", NodeID = "ABCDE", Privacy = PrivacyType.Private
            };
            Folder updatedFolder = new Folder()
            {
                Name = "Updated folder", NodeID = "ABCDE"
            };

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

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

            mock.Setup(api => api.CreateFolder(It.IsAny <string>(), It.IsAny <string>(), "ValidPath", null)).ReturnsAsync(validFolder);

            mock.Setup(api => api.CreateFolder(It.IsAny <string>(), It.IsAny <string>(), "ValidPath", It.Is <Dictionary <string, string> >(i => i.ContainsKey("Invalid")))).ReturnsAsync(invalidFolder);
            mock.Setup(api => api.CreateFolder(It.IsAny <string>(), It.IsAny <string>(), "ValidPath", It.Is <Dictionary <string, string> >(i => i.ContainsKey("Description")))).ReturnsAsync(validFolderWithArguments);
            mock.Setup(api => api.CreateFolder(It.IsAny <string>(), It.IsAny <string>(), "ValidPath", It.Is <Dictionary <string, string> >(i => !i.ContainsKey("Invalid") && !i.ContainsKey("Description")))).ReturnsAsync(validFolder);

            mock.Setup(api => api.CreateFolder(It.IsAny <string>(), It.IsAny <string>(), "InvalidPath", null)).ReturnsAsync(invalidFolder);
            mock.Setup(api => api.CreateFolder(It.IsAny <string>(), It.IsAny <string>(), "InvalidPath", It.IsNotNull <Dictionary <string, string> >())).ReturnsAsync(invalidFolder);

            mock.Setup(api => api.CreateFolder(It.IsAny <string>(), validUser, "ValidPath", null)).ReturnsAsync(validFolder);
            mock.Setup(api => api.CreateFolder(It.IsAny <string>(), validUser, "InvalidPath", null)).ReturnsAsync(invalidFolder);

            mock.Setup(api => api.CreateFolder(It.IsAny <string>(), validUser, "ValidPath", It.Is <Dictionary <string, string> >(i => i.ContainsKey("Invalid")))).ReturnsAsync(invalidFolder);
            mock.Setup(api => api.CreateFolder(It.IsAny <string>(), validUser, "ValidPath", It.Is <Dictionary <string, string> >(i => i.ContainsKey("Description")))).ReturnsAsync(validFolderWithArguments);
            mock.Setup(api => api.CreateFolder(It.IsAny <string>(), validUser, "ValidPath", It.Is <Dictionary <string, string> >(i => !i.ContainsKey("Invalid") && !i.ContainsKey("Description")))).ReturnsAsync(validFolder);

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

            mock.Setup(api => api.CreateFolder(It.IsAny <string>(), validFolder, It.Is <Dictionary <string, string> >(i => i.ContainsKey("Invalid")))).ReturnsAsync(invalidFolder);
            mock.Setup(api => api.CreateFolder(It.IsAny <string>(), validFolder, It.Is <Dictionary <string, string> >(i => i.ContainsKey("Description")))).ReturnsAsync(validFolderWithArguments);
            mock.Setup(api => api.CreateFolder(It.IsAny <string>(), validFolder, It.Is <Dictionary <string, string> >(i => !i.ContainsKey("Invalid") && !i.ContainsKey("Description")))).ReturnsAsync(validFolder);

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

            mock.Setup(api => api.DeleteFolder(invalidFolder)).Throws <ArgumentNullException>();
            mock.Setup(api => api.DeleteFolder(unownedFolder)).Throws <HttpRequestException>();

            mock.Setup(api => api.UpdateFolder(validFolder, It.Is <Dictionary <string, string> >(i => i.ContainsKey("Name")))).ReturnsAsync(updatedFolder);
            mock.Setup(api => api.UpdateFolder(validFolder, It.Is <Dictionary <string, string> >(i => i.ContainsKey("Invalid")))).Throws <HttpRequestException>();

            mock.Setup(api => api.UpdateFolder((Folder)null, It.IsAny <Dictionary <string, string> >())).Throws <ArgumentNullException>();
            mock.Setup(api => api.UpdateFolder(validFolder, null)).Throws <ArgumentNullException>();

            api = mock.Object;
        }