public void AddValidBugShouldBeAddedToRepository()
        {
            // Arrange
            var bugLoggerFakeData = new BugLoggerFakeUoW();
            var bug = new CreateBugModel()
            {
                Description = "bug-1",
                LogDate = DateTime.Now
            };

            var bugsController = new BugsController(bugLoggerFakeData);
            this.SetupController(bugsController);

            // Act
            bugsController.Create(bug);

            // Assert
            Assert.AreEqual(bugLoggerFakeData.Bugs.All().Count(), 1);

            var bugInDatabase = bugLoggerFakeData.Bugs.All().First();
            Assert.AreEqual(bug.Description, bugInDatabase.Description);
            Assert.AreEqual(BugStatus.Pending, bugInDatabase.Status);
            Assert.IsNotNull(bugInDatabase.LogDate);
            Assert.IsTrue(bugLoggerFakeData.IsSaveChangedCalled);
        }
Exemplo n.º 2
0
        public HttpResponseMessage Create(CreateBugModel bugModel)
        {
            if (!this.ModelState.IsValid)
            {
                return this.Request.CreateResponse(HttpStatusCode.BadRequest);
            }

            if (string.IsNullOrEmpty(bugModel.Description))
            {
                return this.Request.CreateResponse(HttpStatusCode.BadRequest, "Description cannot be null or empty");
            }

            if (bugModel.LogDate == DateTime.MinValue || bugModel.LogDate == DateTime.MaxValue)
            {
                return this.Request.CreateResponse(HttpStatusCode.BadRequest, "Invalid LogDate: " + bugModel.LogDate);
            }

            var bug = new Bug()
            {
                Description = bugModel.Description,
                LogDate = bugModel.LogDate,
                Status = BugStatus.Pending
            };

            this.BugLoggerData.Bugs.Add(bug);
            this.BugLoggerData.SaveChanges();

            var response = this.Request.CreateResponse(HttpStatusCode.Created, bug);
            return response;
        }
        public void PostNewBugWithoutLogDateShouldReturn400()
        {
            var bugLoggerData = this.MockUnitOfWorkForActionAll();
            var bug = new CreateBugModel()
            {
                Description = "bug-1",
            };

            var server = new InMemoryHttpServer<Bug>(InMemoryServerUrl, bugLoggerData);
            var response = server.CreatePostRequest("/api/Bugs/Create", bug);

            Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
        }
        public void AddBugWithEmptyDescriptionShouldNotBeAddedToRepository()
        {
            // Arrange
            var bugLoggerFakeData = new BugLoggerFakeUoW();
            var bug = new CreateBugModel()
            {
                Description = string.Empty,
                LogDate = DateTime.Now
            };

            var bugsController = new BugsController(bugLoggerFakeData);
            this.SetupController(bugsController);

            // Act
            bugsController.Create(bug);

            // Assert
            Assert.AreEqual(bugLoggerFakeData.Bugs.All().Count(), 0);
        }
Exemplo n.º 5
0
        public void AddValidBugShouldBeAddedToRepository_Mocking()
        {
            // Arrange
            var bug = new CreateBugModel()
            {
                Description = "bug-1"
            };
            var bugs = new List<Bug>();
            var bugLoggerFakeData = this.MockUnitOfWorkForActionAll(bugs);
            var bugsController = new BugsController(bugLoggerFakeData);
            this.SetupController(bugsController);

            // Act
            bugsController.Create(bug);

            // Assert
            Assert.AreEqual(bugLoggerFakeData.Bugs.All().Count(), 1);

            var bugInDatabase = bugLoggerFakeData.Bugs.All().First();
            Assert.AreEqual(bug.Description, bugInDatabase.Description);
            Assert.AreEqual(BugStatus.Pending, bugInDatabase.Status);
            Assert.IsNotNull(bugInDatabase.LogDate);
        }
        public void AddBugWithoutBothDescriptionAndLogDateShouldNotBeAddedToRepository()
        {
            // Arrange
            var bugLoggerFakeData = new BugLoggerFakeUoW();
            var bug = new CreateBugModel();

            var bugsController = new BugsController(bugLoggerFakeData);
            this.SetupController(bugsController);

            // Act
            bugsController.Create(bug);

            // Assert
            Assert.AreEqual(bugLoggerFakeData.Bugs.All().Count(), 0);
        }