예제 #1
0
        public void Post_Should_Add_Page()
        {
            // Arrange
            PageViewModel page = new PageViewModel()
            {
                Title     = "Hello",
                CreatedBy = "admin",
                CreatedOn = DateTime.UtcNow,
                Content   = "some content",
                RawTags   = "tag1,tag2"
            };

            WebApiClient apiclient = new WebApiClient();

            apiclient.Login();

            // Act
            WebApiResponse response = apiclient.Post <PageViewModel>("Pages", page);

            // Assert
            IRepository        repository = GetRepository();
            IEnumerable <Page> pages      = repository.AllPages();

            Assert.That(pages.Count(), Is.EqualTo(1), response);
        }
예제 #2
0
		public void GetUsers_Should_Return_All_Users()
		{
			// Arrange
			WebApiClient apiclient = new WebApiClient();
			apiclient.Login();

			// Act
			WebApiResponse<List<UserViewModel>> response = apiclient.Get<List<UserViewModel>>("User");

			// Assert
			List<UserViewModel> results = response.Result;
			Assert.That(results.Count(), Is.EqualTo(2), response);
		}
예제 #3
0
		public void Logout_Should_Remove_Auth_Cookie()
		{
			// Arrange
			WebApiClient apiclient = new WebApiClient();
			apiclient.Login();
			apiclient.Get("Logout");
			apiclient.Get("User");

			// Act
			apiclient.Login();
			apiclient.Get("Logout");
			WebApiResponse response = apiclient.Get("User");

			// Assert
			Assert.That(response.HttpStatusCode, Is.EqualTo(HttpStatusCode.Unauthorized), response);
		}
예제 #4
0
        public void Get_Should_Return_All_Pages()
        {
            // Arrange
            AddPage("test", "this is page 1");
            AddPage("page 2", "this is page 2");

            WebApiClient apiclient = new WebApiClient();

            apiclient.Login();

            // Act
            WebApiResponse <List <PageViewModel> > response = apiclient.Get <List <PageViewModel> >("Pages");

            // Assert
            IEnumerable <PageViewModel> pages = response.Result;

            Assert.That(pages.Count(), Is.EqualTo(2), response);
        }
예제 #5
0
		public void Authenticate_Should_Return_False_For_Unknown_User()
		{
			// Arrange
			UserController.UserInfo info = new UserController.UserInfo()
			{
				Email = "badlogin@localhost",
				Password = ADMIN_PASSWORD
			};

			WebApiClient apiclient = new WebApiClient();
			apiclient.Login();

			// Act
			WebApiResponse response = apiclient.Post<UserController.UserInfo>("Authenticate", info);

			// Assert
			Assert.That(response.Content, Is.EqualTo("false"), response);
		}
예제 #6
0
        public void authenticate_should_return_true_for_known_user()
        {
            // Arrange
            UserController.UserInfo info = new UserController.UserInfo()
            {
                Email    = ADMIN_EMAIL,
                Password = ADMIN_PASSWORD
            };

            WebApiClient apiclient = new WebApiClient();

            apiclient.Login();

            // Act
            WebApiResponse response = apiclient.Post <UserController.UserInfo>("Authenticate", info);

            // Assert
            Assert.That(response.Content, Is.EqualTo("true"), response);
        }
예제 #7
0
		public void GetUser_Should_Return_Admin_User()
		{
			// Arrange
			var queryString = new Dictionary<string, string>()
			{ 
				{ "Id", ADMIN_ID.ToString() }
			};

			WebApiClient apiclient = new WebApiClient();
			apiclient.Login();	

			// Act
			WebApiResponse<UserViewModel> response = apiclient.Get<UserViewModel>("User", queryString);

			// Assert
			UserViewModel userViewModel = response.Result;
			Assert.That(userViewModel, Is.Not.Null, response);
			Assert.That(userViewModel.Id, Is.EqualTo(ADMIN_ID), response);
		}
예제 #8
0
        public void Put_Should_Update_Page()
        {
            // Arrange
            PageContent   pageContent = AddPage("test", "this is page 1");
            PageViewModel viewModel   = new PageViewModel(pageContent.Page);

            viewModel.Title = "New title";

            WebApiClient apiclient = new WebApiClient();

            apiclient.Login();

            // Act
            WebApiResponse response = apiclient.Put <PageViewModel>("Pages/Put", viewModel);

            // Assert
            IRepository repository = GetRepository();
            Page        page       = repository.AllPages().FirstOrDefault();

            Assert.That(page.Title, Is.EqualTo("New title"), response);
        }
예제 #9
0
        public void Get_With_Id_Should_Return_Correct_Page()
        {
            // Arrange
            PageContent expectedPage = AddPage("test", "this is page 1");
            var         queryString  = new Dictionary <string, string>()
            {
                { "Id", expectedPage.Page.Id.ToString() }
            };
            WebApiClient apiclient = new WebApiClient();

            apiclient.Login();

            // Act
            WebApiResponse <PageViewModel> response = apiclient.Get <PageViewModel>("Pages", queryString);

            // Assert
            PageViewModel actualPage = response.Result;

            Assert.That(actualPage, Is.Not.Null, response.ToString());
            Assert.That(actualPage.Id, Is.EqualTo(expectedPage.Page.Id), response.ToString());
        }
예제 #10
0
        public void search_should_return_result_based_on_query()
        {
            // Arrange
            AddPage("test", "this is page 1");
            AddPage("page 2", "this is page 2");
            var queryString = new Dictionary <string, string>()
            {
                { "query", "test" }
            };

            WebApiClient apiclient = new WebApiClient();

            apiclient.Login();

            // Act
            apiclient.Get("Search/CreateIndex");
            WebApiResponse <List <PageViewModel> > response = apiclient.Get <List <PageViewModel> >("Search", queryString);

            // Assert
            IEnumerable <PageViewModel> pages = response.Result;

            Assert.That(pages.Count(), Is.EqualTo(1), response);
        }