Ejemplo n.º 1
0
        public void AddBug_WhenBugTextIsValid_ShouldBeAddedToRepoWithLogDateAndStatusPending()
        {
            var bugs = new List<Bug>();

            var bug = new BugModel()
            {
                Text = "NEW TEST BUG"
            };

            var data = Mock.Create<IBugLoggerData>();

            Mock.Arrange(() => data.Bugs.All())
                .Returns(() => bugs.AsQueryable());

            Mock.Arrange(() => data.SaveChanges())
                .DoInstead(() => bugs.Add(new Bug() { Text = "NEW TEST BUG" }));

            var controller = new BugsController(data);
            this.SetupController(controller);

            //act
            controller.PostBug(bug);

            //assert
            Assert.AreEqual(data.Bugs.All().Count(), 1);
            var bugInDb = data.Bugs.All().FirstOrDefault();
            Assert.AreEqual(bug.Text, bugInDb.Text);
            Assert.IsNotNull(bugInDb.LogDate);
            Assert.AreEqual(Status.Pending, bugInDb.Status);
        }
Ejemplo n.º 2
0
        public IHttpActionResult PostBug(BugModel bug)
        {
            if (string.IsNullOrEmpty(bug.Text))
            {
                var ex = new ArgumentException();
                return this.BadRequest(ex.Message);
            }

            var newBug = new Bug
            {
                LogDate = DateTime.Now,
                Status = Status.Pending,
                Text = bug.Text
            };

            this.data.Bugs.Add(newBug);
            this.data.SaveChanges();

            var location = new Uri(this.Url.Link("DefaultApi", new { id = newBug.Id }));
            var response = this.Created(location, newBug);
            return response;
        }