Exemple #1
0
        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;
        }