public void EditBug_InvalidBugData_ShouldReturn400BadRequest()
        {
            // Arrange -> create a few bugs
            var dataLayerMock = new BugTrackerDataMock();
            var bugsMock = dataLayerMock.Bugs;
            bugsMock.Add(new Bug() { Id = 1, Title = "Bug #1" });
            bugsMock.Add(new Bug() { Id = 2, Title = "Bug #2" });

            // Act -> edit bug data
            var bugsController = new BugsController(dataLayerMock);
            this.SetupControllerForTesting(bugsController, "bugs");
            EditBugBindingModel editBugData = null;
            var httpResponse = bugsController.EditBug(1, editBugData)
                .ExecuteAsync(new CancellationToken()).Result;

            // Assert -> HTTP status code 400 (BadRequest)
            Assert.AreEqual(HttpStatusCode.BadRequest, httpResponse.StatusCode);
        }
        public void EditBug_NonExistingBug_ShouldReturn404NotFound()
        {
            // Arrange -> create a few bugs
            var dataLayerMock = new BugTrackerDataMock();
            var bugsMock = dataLayerMock.Bugs;
            bugsMock.Add(new Bug() { Id = 1, Title = "Bug #1" });
            bugsMock.Add(new Bug() { Id = 2, Title = "Bug #2" });

            // Act -> edit bug data
            var bugsController = new BugsController(dataLayerMock);
            this.SetupControllerForTesting(bugsController, "bugs");
            var editBugData = new EditBugInputModel() { Title = "new title" };
            var httpResponse = bugsController.EditBug(1234, editBugData)
                .ExecuteAsync(new CancellationToken()).Result;

            // Assert -> HTTP status code 404 (Not Found)
            Assert.AreEqual(HttpStatusCode.NotFound, httpResponse.StatusCode);
        }
        public void EditBug_ExistingBug_ShouldReturn200OK_CorrectBugData()
        {
            // Arrange -> create a few bugs
            var dataLayerMock = new BugTrackerDataMock();
            var bugsMock = dataLayerMock.Bugs;
            bugsMock.Add(new Bug() { Id = 1, Title = "Bug #1" });
            bugsMock.Add(new Bug()
            {
                Id = 2,
                Title = "Bug #2 for edit ...",
                Description = "Description for edit ...",
                Status = BugStatus.Fixed
            });
            bugsMock.Add(new Bug() { Id = 3, Title = "Bug #3" });
            var newTitle = "new title";
            var newDescription = "new description";
            var newStatus = BugStatus.Closed;

            // Act -> edit bug data
            var bugsController = new BugsController(dataLayerMock);
            this.SetupControllerForTesting(bugsController, "bugs");
            var editBugData = new EditBugBindingModel()
            {
                Title = newTitle,
                Description = newDescription,
                Status = newStatus
            };
            var httpResponse = bugsController.EditBug(2, editBugData)
                .ExecuteAsync(new CancellationToken()).Result;

            // Assert -> HTTP status code 200 (OK) + bug data changed
            Assert.AreEqual(HttpStatusCode.OK, httpResponse.StatusCode);

            Assert.AreEqual(2, bugsMock.Find(2).Id);
            Assert.AreEqual(newTitle, bugsMock.Find(2).Title);
            Assert.AreEqual(newDescription, bugsMock.Find(2).Description);
            Assert.AreEqual(newStatus, bugsMock.Find(2).Status);
        }