コード例 #1
0
 public void Register_WhenUserModelValid_ShouldSaveToDatabase()
 {
     var testUser = new UserDto()
     {
         Username = "VALIDUSER",
         Nickname = "VALIDNICK",
         AuthCode = new string('b', 40)
     };
     //var httpServer = new InMemoryHttpServer("http://localhost/");
     var model = this.RegisterTestUser(httpServer, testUser);
     Assert.AreEqual(testUser.Nickname, model.Nickname);
     Assert.IsNotNull(model.SessionKey);
 }
コード例 #2
0
        public void GetAll_WhenDataInDatabase_ShouldReturnData()
        {
            var testUser = new UserDto()
            {
                Username = "VALIDUSER",
                Nickname = "VALIDNICK",
                AuthCode = new string('b', 40)
            };

            UserLogedDto userModel = RegisterTestUser(httpServer, testUser);
            var response = httpServer.Get("api/threads/" + userModel.SessionKey);

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            Assert.IsNotNull(response.Content);
        }
コード例 #3
0
 private UserLogedDto RegisterTestUser(InMemoryHttpServer httpServer, UserDto testUser)
 {
     var response = httpServer.Post("api/users/register", testUser);
     var contentString = response.Content.ReadAsStringAsync().Result;
     var userModel = JsonConvert.DeserializeObject<UserLogedDto>(contentString);
     return userModel;
 }
コード例 #4
0
        public void GetAllPosts_WhenDataInDatabase_ShouldReturnData_CustomAttributes()
        {
            var testUser = new UserDto()
            {
                Username = "VALIDUSER",
                Nickname = "VALIDNICK",
                AuthCode = new string('b', 40)
            };

            var routes = new List<Route>
            {
                new Route(
                    "CustomThreadsApi",
                    "api/threads/{sessionKey}/{id}/posts",
                    new
                    {
                        controller = "threads",
                        sessionKey = RouteParameter.Optional,
                        id = RouteParameter.Optional
                    }),
                    new Route(
                    "CustomThreadsApiGetAll",
                    "api/threads/{sessionKey}",
                    new
                    {
                        controller = "threads",
                        sessionKey = RouteParameter.Optional
                    }),
                new Route(
                     "UsersApi",
                     "api/{controller}/{action}/{sessionKey}",
                     new
                        {
                            sessionKey = RouteParameter.Optional
                        })
            };

            this.httpServer = new InMemoryHttpServer("http://localhost/", routes);

            UserLogedDto userModel = RegisterTestUser(httpServer, testUser);

            //api/threads/sessionKey
            string urlGetAllThreads = "api/threads/" + userModel.SessionKey;
            var responseAllThreads = httpServer.Get(urlGetAllThreads).Content.ReadAsStringAsync().Result;
            var threads = JsonConvert.DeserializeObject<IEnumerable<ThreadDto>>(responseAllThreads);
            ThreadDto firstThread = new ThreadDto();
            if (threads != null)
            {
                foreach (var thr in threads)
                {
                    firstThread = thr;
                    break;
                }
            }

            //api/threads/sessionKey/1/posts
            string url = "api/threads/" + userModel.SessionKey + "/" + firstThread.Id + "/posts";
            var response = httpServer.Get(url);

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            Assert.IsNotNull(response.Content);
        }