public void InitializeAnonymous() { var mock = new Mock <ISmugMugAPI>(); UserProfile nullUserProfile = null; UserProfile validUserProfile = new UserProfile() { DisplayName = "Valid User", BioText = "Valid bio" }; UserProfile updatedUserProfile = new UserProfile() { DisplayName = "Valid User", BioText = "Updated bio" }; 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.GetUserProfile("ValidUser")).ReturnsAsync(validUserProfile); mock.Setup(api => api.GetUserProfile("InvalidUser")).ReturnsAsync(nullUserProfile); mock.Setup(api => api.GetUserProfile(validUser)).ReturnsAsync(validUserProfile); mock.Setup(api => api.GetUserProfile(nullUser)).ReturnsAsync(nullUserProfile); mock.Setup(api => api.UpdateUserProfile(validUser, It.Is <Dictionary <string, string> >(i => i.ContainsKey("BioText")))).ReturnsAsync(updatedUserProfile); mock.Setup(api => api.UpdateUserProfile(validUser, It.Is <Dictionary <string, string> >(i => i.ContainsKey("Invalid")))).Throws <HttpRequestException>(); mock.Setup(api => api.UpdateUserProfile(validUserProfile, It.Is <Dictionary <string, string> >(i => i.ContainsKey("BioText")))).ReturnsAsync(updatedUserProfile); mock.Setup(api => api.UpdateUserProfile(validUserProfile, It.Is <Dictionary <string, string> >(i => i.ContainsKey("Invalid")))).Throws <HttpRequestException>(); mock.Setup(api => api.UpdateUserProfile((User)null, It.IsAny <Dictionary <string, string> >())).Throws <ArgumentNullException>(); mock.Setup(api => api.UpdateUserProfile(validUser, null)).Throws <ArgumentNullException>(); api = mock.Object; }
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; }
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; }
public void InitializeAnonymous() { var mock = new Mock <ISmugMugAPI>(); SmugMugUri defaultNodeUri = new SmugMugUri() { Uri = "/api/v2/node/ABCDE" }; User nullUser = null; User validUser = new User() { Name = "Valid User", NickName = "ValidUser", Uris = new UserUris { Node = defaultNodeUri } }; User updatedUser = new User() { Name = "Valid User", NickName = "NickName" }; mock.Setup(api => api.GetUser("ValidUser")).ReturnsAsync(validUser); mock.Setup(api => api.GetUser("InvalidUser")).ReturnsAsync(nullUser); mock.Setup(api => api.GetDefaultNodeID(validUser)).Returns("ABCDE"); List <Album> validAlbums = new List <Album>() { new Album() { Name = "ValidAlbum", ImageCount = 5 }, new Album() { Name = "AnotherValidAlbum", ImageCount = 10 }, new Album() { Name = "ThirdValidAlbum", ImageCount = 15 } }; List <Album> invalidAlbums = null; mock.Setup(api => api.GetAlbums(validUser, It.IsInRange <int>(0, int.MaxValue, Range.Inclusive))).ReturnsAsync(validAlbums); mock.Setup(api => api.GetAlbums(validUser, It.IsInRange <int>(int.MinValue, 0, Range.Inclusive))).ReturnsAsync(invalidAlbums); mock.Setup(api => api.GetAlbums(nullUser, It.IsInRange <int>(0, int.MaxValue, Range.Inclusive))).ReturnsAsync(invalidAlbums); mock.Setup(api => api.GetAlbums(nullUser, It.IsInRange <int>(int.MinValue, 0, Range.Inclusive))).ReturnsAsync(invalidAlbums); mock.Setup(api => api.GetFeaturedAlbums(validUser, It.IsInRange <int>(0, int.MaxValue, Range.Inclusive))).ReturnsAsync(validAlbums); mock.Setup(api => api.GetFeaturedAlbums(validUser, It.IsInRange <int>(int.MinValue, 0, Range.Inclusive))).ReturnsAsync(invalidAlbums); mock.Setup(api => api.GetFeaturedAlbums(nullUser, It.IsInRange <int>(0, int.MaxValue, Range.Inclusive))).ReturnsAsync(invalidAlbums); mock.Setup(api => api.GetFeaturedAlbums(nullUser, It.IsInRange <int>(int.MinValue, 0, Range.Inclusive))).ReturnsAsync(invalidAlbums); api = mock.Object; }
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; }