private Bug GetValidTestBug()
 {
     var bug = new Bug()
     {
         Text = "Test New bug",
         LogDate = DateTime.Now,
         Status = Status.Pending
     };
     return bug;
 }
        public void PostNewBug_WhenTextIsEmpty_ShouldReturn400()
        {
            IRepository<Bug> repo = Mock.Create<IRepository<Bug>>();

            Bug bug = new Bug()
            {
                Text = ""
            };

            var server = new InMemoryHttpServer<Bug>(this.inMemoryServerUrl, repo);

            var response = server.CreatePostRequest("/api/bugs", bug);

            Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
        }
        public HttpResponseMessage PostBug(Bug bug)
        {
            if (string.IsNullOrEmpty(bug.Text))
            {
                var ex = new ArgumentException();
                return this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex);
            }

            bug.LogDate = DateTime.Now;
            bug.Status = Status.Pending;
            this.repo.Add(bug);
            this.repo.Save();

            var response = this.Request.CreateResponse(HttpStatusCode.Created, bug);
            response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = bug.Id }));
            return response;
        }
        public void AddBug_WhenBugTextIsValid_ShouldBeAddedToRepoWithLogDateAndStatusPending()
        {
            //arrange
            var repo = new FakeRepository<Bug>();
            repo.IsSaveCalled = false;
            repo.Entities = new List<Bug>();
            var bug = new Bug() { Text = "NEW TEST BUG" };
            var controller = new BugsController(repo);
            this.SetupController(controller);

            //act
            controller.PostBug(bug);

            //assert
            Assert.AreEqual(repo.Entities.Count, 1);
            var bugInDb = repo.Entities.First();
            Assert.AreEqual(bug.Text, bugInDb.Text);
            Assert.IsNotNull(bugInDb.LogDate);
            Assert.AreEqual(Status.Pending, bugInDb.Status);
            Assert.IsTrue(repo.IsSaveCalled);
        }
        public void UpdateBugStatus_WhenStatusIsPending_ShouldReturnStatusFixed_WithMocks()
        {
            //arrange
            var repo = new FakeRepository<Bug>();
            repo.IsSaveCalled = false;
            repo.Entities = new List<Bug>();
            var bug = new Bug()
            {
                Text = "NEW TEST BUG",
                Status =Status.Pending
            };
            repo.Entities.Add(bug);
            var controller = new BugsController(repo);
            this.SetupController(controller);

            //act
            var result = controller.UpdateBugStatus(0, Status.Fixed);

            //assert
            Assert.AreEqual(Status.Fixed, repo.Entities[0].Status, "The status of the bug should be changed from Pending to Fixed.");
        }
 public Bug Add(Bug entity)
 {
     //validation
     this.dbContext.Set<Bug>().Add(entity);
     return entity;
 }
 public void Update(Bug entity)
 {
     throw new NotImplementedException();
 }