コード例 #1
0
        // POST: api/Hreppur
        /// <summary>
        /// Add a new hreppur
        /// </summary>
        /// <param name="hreppur"></param>
        public HttpResponseMessage Post([FromBody]HreppurDto hreppur)
        {
            if (!ModelState.IsValid)
                return Request.CreateResponse(HttpStatusCode.BadRequest);

            var newHreppur = new HreppurService().AddHreppur(hreppur);
            var response = Request.CreateResponse(HttpStatusCode.Created, newHreppur);
            response.Headers.Location = new Uri(Url.Link(ApiRouteNames.RestApi.ToString(), new { id = newHreppur.HreppurId}));
            return response;
        }
コード例 #2
0
        public void RemoveHreppurTest()
        {
            var svc = new HreppurService();
            var expectedCount = svc.GetAllHreppurs().Count;
            var hreppurToDelete = svc.AddHreppur(new HreppurDto {Name = "MyName"});

            if (svc.GetAllHreppurs().Count == 0)
                Assert.Inconclusive("There are no hreppurs in the repository to delete");

            svc.RemoveHreppur(hreppurToDelete.HreppurId);
            Assert.AreEqual(expectedCount, svc.GetAllHreppurs().Count);
        }
コード例 #3
0
        public void UpdateHreppurTest()
        {
            var svc = new HreppurService();

            var hreppur = new HreppurDto
            {
                Name = "InitialName"
            };

            var actualHreppur = svc.AddHreppur(hreppur);
            var hreppurId = actualHreppur.HreppurId;
            var countBeforeUpdate = svc.GetAllHreppurs().Count;

            actualHreppur.Name = "UpdatedName";

            svc.UpdateHreppur(actualHreppur);
            var countAfterUpdate = svc.GetAllHreppurs().Count;

            Assert.AreEqual(countBeforeUpdate, countAfterUpdate, "Updating a hreppur should not change the totalt count of hreppurs in the repository");

            var updatedHreppur = svc.GetHreppurById(hreppurId);
            Assert.AreEqual("UpdatedName", updatedHreppur.Name);
        }