Ejemplo n.º 1
0
        public void DeleteShouldReturnForbiddenTest()
        {
            StatusesRepositorySpy spy_repository = new StatusesRepositorySpy();
            CredentialsCheckerSpy_AlwaysFail spy_checker = new CredentialsCheckerSpy_AlwaysFail();
            StatusesController target = new StatusesController(spy_repository, spy_checker);
            spy_repository.GetSingleTweetResult = new Tweet() { Content = "Twit 1", DateAndTime = new DateTime(2012, 10, 20), Id = 10, UserId = 1 };

            var config = new HttpConfiguration();
            var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/api/1.0/statuses/delete");
            var route = config.Routes.MapHttpRoute("TestApi", "api/1.0/{controller}/{action}");
            var routeData = new HttpRouteData(route, new HttpRouteValueDictionary { { "controller", "statuses" }, { "action", "delete" } });
            target.ControllerContext = new HttpControllerContext(config, routeData, request);
            target.Request = request;
            target.Request.Properties[HttpPropertyKeys.HttpConfigurationKey] = config;

            var actual = target.Delete(10);

            Assert.AreEqual(HttpStatusCode.Forbidden, actual.StatusCode);
        }
Ejemplo n.º 2
0
        public void ChangePasswordShouldRiseExceptionTest()
        {
            UserRepositorySpy spy_repository = new UserRepositorySpy();
            CredentialsCheckerSpy_AlwaysFail spy_checker = new CredentialsCheckerSpy_AlwaysFail();
            UsersController target = new UsersController(spy_repository, spy_checker);
            UserChangePasswordData user = new UserChangePasswordData() { NewPassword = "new_password", OldPassword = "old_password" };
            spy_repository.GetSingleUserResult = new User() { Id = 1, Login = "Login1" };

            var config = new HttpConfiguration();
            var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/api/1.0/users/changepassword");
            var route = config.Routes.MapHttpRoute("TestApi", "api/1.0/{controller}/{action}");
            var routeData = new HttpRouteData(route, new HttpRouteValueDictionary { { "controller", "users" }, { "action", "changepasword" } });
            target.ControllerContext = new HttpControllerContext(config, routeData, request);
            target.Request = request;
            target.Request.Properties[HttpPropertyKeys.HttpConfigurationKey] = config;

            try
            {
                HttpResponseMessage actual = target.ChangePassword(user);
                Assert.IsTrue(false);
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(HttpResponseException));
            }
        }