Exemple #1
0
        public void CreatePoint_InvalidLongLat_400()
        {
            newUser = _tu.CreateUserObject();
            Session newSession = _tu.CreateSessionObject(newUser);

            _tu.CreateSessionInDb(newSession);

            var endpoint = API_ROUTE_LOCAL + "/api/point";

            _pointController.Request = new HttpRequestMessage
            {
                RequestUri = new Uri(endpoint)
            };

            var point = new PointCreateDTO
            {
                Longitude   = 185,
                Latitude    = 85,
                Description = "bad longitude value",
                Name        = "test bad point",
            };

            var request = new HttpRequestMessage();

            request.Headers.Add("token", newSession.Token);

            _pointController.Request = request;

            //out of range Longitude should throw InvalidPointException
            //  and return a 400
            NegotiatedContentResult <string> response = (NegotiatedContentResult <string>)_pointController.Post(point);

            Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
            Assert.AreEqual("Longitude/Latitude value invalid.", response.Content.ToString());
        }
Exemple #2
0
        public void Create_Read_Update_Delete_201_200()
        {
            newUser = _tu.CreateUserObject();
            Session newSession = _tu.CreateSessionObject(newUser);

            _tu.CreateSessionInDb(newSession);

            var createEndpoint = API_ROUTE_LOCAL + "/api/point";

            controller.Request = new HttpRequestMessage
            {
                RequestUri = new Uri(createEndpoint)
            };

            var pointPost = new PointCreateDTO
            {
                Longitude   = 179,
                Latitude    = 85,
                Description = "desc",
                Name        = "name",
            };

            var request = new HttpRequestMessage();

            request.Headers.Add("token", newSession.Token);

            controller.Request = request;

            //Create Test
            NegotiatedContentResult <Point> response = (NegotiatedContentResult <Point>)controller.Post(pointPost);

            Assert.AreEqual(response.StatusCode, System.Net.HttpStatusCode.Created);
            Assert.AreEqual(pointPost.Name, response.Content.Name);
            Assert.AreEqual(pointPost.Description, response.Content.Description);
            Assert.AreEqual(pointPost.Longitude, response.Content.Longitude);
            Assert.AreEqual(pointPost.Latitude, response.Content.Latitude);

            //Read Test1
            OkNegotiatedContentResult <Point> readResponse = (OkNegotiatedContentResult <Point>)controller.Get(response.Content.Id.ToString());

            Assert.AreEqual(response.Content.Name, readResponse.Content.Name);
            Assert.AreEqual(response.Content.Description, readResponse.Content.Description);
            Assert.AreEqual(response.Content.Longitude, readResponse.Content.Longitude);
            Assert.AreEqual(response.Content.Latitude, readResponse.Content.Latitude);
            Assert.AreEqual(response.Content.CreatedAt, readResponse.Content.CreatedAt);
            Assert.AreEqual(response.Content.UpdatedAt, readResponse.Content.UpdatedAt);

            var pointUpdatePost = new PointUpdateDTO
            {
                Longitude   = readResponse.Content.Longitude,
                Latitude    = response.Content.Latitude,
                Description = "updatedDescription",
                Name        = "updatedName",
                Id          = readResponse.Content.Id
            };

            OkNegotiatedContentResult <Point> updateResponse = (OkNegotiatedContentResult <Point>)controller.Put(pointUpdatePost);

            Assert.AreEqual(pointUpdatePost.Name, updateResponse.Content.Name);
            Assert.AreEqual(pointUpdatePost.Description, updateResponse.Content.Description);
            Assert.AreEqual(pointUpdatePost.Longitude, updateResponse.Content.Longitude);
            Assert.AreEqual(pointUpdatePost.Latitude, updateResponse.Content.Latitude);
            Assert.AreEqual(response.Content.CreatedAt, updateResponse.Content.CreatedAt);
            Assert.AreNotEqual(response.Content.UpdatedAt, updateResponse.Content.UpdatedAt);

            //Read Test2
            OkNegotiatedContentResult <Point> readResponse2 = (OkNegotiatedContentResult <Point>)controller.Get(updateResponse.Content.Id.ToString());

            Assert.AreEqual(updateResponse.Content.Name, readResponse2.Content.Name);
            Assert.AreEqual(updateResponse.Content.Description, readResponse2.Content.Description);
            Assert.AreEqual(updateResponse.Content.Longitude, readResponse2.Content.Longitude);
            Assert.AreEqual(updateResponse.Content.Latitude, readResponse2.Content.Latitude);
            Assert.AreEqual(updateResponse.Content.CreatedAt, readResponse2.Content.CreatedAt);
            Assert.AreEqual(updateResponse.Content.UpdatedAt, readResponse2.Content.UpdatedAt);

            OkResult deleteResponse = (OkResult)controller.Delete(readResponse2.Content.Id.ToString());

            Assert.IsInstanceOfType(deleteResponse, typeof(OkResult));

            NegotiatedContentResult <string> readResponse3 = (NegotiatedContentResult <string>)controller.Get(readResponse2.Content.Id.ToString());

            Assert.AreEqual(readResponse3.StatusCode, HttpStatusCode.NotFound);
        }