public void When_GetById_Expect_Equal()
        {
            // Arrange
            var controller      = new TimeBookerController(_dbRepository);
            var expectedBooking = new TimeBooker
            {
                Id        = 4,
                IsRemoved = false,
                Created   = new DateTime(2017, 12, 15, 16, 22, 33),
                Project   = "Project Four",
                Time      = "5.3"
            };


            // Act
            var result        = controller.Get(4);
            var contentResult = result as OkNegotiatedContentResult <TimeBooker>;

            // Assert
            Assert.IsNotNull(contentResult);
            Assert.IsNotNull(contentResult.Content);
            Assert.AreEqual(expectedBooking.Id, contentResult.Content.Id);
            Assert.AreEqual(expectedBooking.IsRemoved, contentResult.Content.IsRemoved);
            Assert.AreEqual(expectedBooking.Created, contentResult.Content.Created);
            Assert.AreEqual(expectedBooking.Project, contentResult.Content.Project);
            Assert.AreEqual(expectedBooking.Time, contentResult.Content.Time);
        }
        public void When_Put_Expect_Success()
        {
            // Arrange
            var controller = new TimeBookerController(_dbRepository);

            var updatedBooking = new TimeBooker
            {
                Id        = 3,
                IsRemoved = false,
                Created   = new DateTime(2017, 12, 14, 15, 22, 33),
                Project   = "Project Three",
                Time      = "18"
            };

            // Act
            var result             = controller.Put(3, updatedBooking) as OkResult;
            var checkResult        = controller.Get(3);
            var checkContentResult = checkResult as OkNegotiatedContentResult <TimeBooker>;

            // Assert
            Assert.IsNotNull(result);
            Assert.IsNotNull(checkContentResult);
            Assert.IsInstanceOfType(result, typeof(OkResult));
            Assert.AreEqual(updatedBooking.Time, checkContentResult.Content.Time);
        }
Пример #3
0
        // POST api/TimeBooker
        public IHttpActionResult Post([FromBody] TimeBooker newBooking)
        {
            if (ModelState.IsValid)
            {
                _timeBookerRepository.Insert(newBooking);
                _timeBookerRepository.Save();

                return(Ok(newBooking.Id));
            }
            else
            {
                return(BadRequest(ModelState));
            }
        }
Пример #4
0
        // PUT api/TimeBooker/3
        public IHttpActionResult Put(int id, [FromBody] TimeBooker updatedBooking)
        {
            if (ModelState.IsValid && id == updatedBooking.Id)
            {
                var result = _timeBookerRepository.Update(updatedBooking);

                if (result)
                {
                    _timeBookerRepository.Save();
                    return(Ok());
                }
                else
                {
                    return(NotFound());
                }
            }
            else
            {
                return(BadRequest(ModelState));
            }
        }
        public void When_Post_Expect_Success()
        {
            // Arrange
            var controller = new TimeBookerController(_dbRepository);

            var newBooking = new TimeBooker
            {
                Id        = 5,
                IsRemoved = false,
                Created   = new DateTime(),
                Project   = "Project Five",
                Time      = "8"
            };

            // Act
            var result        = controller.Post(newBooking);
            var contentResult = result as OkNegotiatedContentResult <int>;

            // Assert
            Assert.IsNotNull(result);
            Assert.IsNotNull(contentResult);
            Assert.IsInstanceOfType(result, typeof(OkNegotiatedContentResult <int>));
            Assert.AreEqual(5, contentResult.Content);
        }