public void AddPersonToWorld_Returns400_WhenNoPersonIsGiven()
        {
            var controller =
                new PeopleController(new Mock <IPeopleRepository>().Object, new Mock <IMessageBuilder>().Object);

            IActionResult result     = controller.AddPersonToWorld(null);
            var           badRequest = result as BadRequestObjectResult;

            Assert.Equal(400, badRequest.StatusCode);
        }
        public void AddPersonToWorld_DoesNotCall_AddPersonToRepository_WhenNameExists()
        {
            var testPerson = new Person("Anton");
            var mockRepo   = new Mock <IPeopleRepository>();

            mockRepo.Setup(repo => repo.CheckIfNameExistsInRepository(testPerson.Name)).Returns(true);
            mockRepo.Setup(repo => repo.AddPersonToRepository(testPerson));
            var controller = new PeopleController(mockRepo.Object, new Mock <IMessageBuilder>().Object);

            controller.AddPersonToWorld(testPerson);

            mockRepo.Verify(repo => repo.AddPersonToRepository(testPerson), Times.Never);
        }
        public void AddPersonToWorld_Returns400_WhenNameExistsInRepository()
        {
            var testPerson = new Person("Anton");
            var mockRepo   = new Mock <IPeopleRepository>();

            mockRepo.Setup(repo => repo.CheckIfNameExistsInRepository(testPerson.Name)).Returns(true);
            var controller = new PeopleController(mockRepo.Object, new Mock <IMessageBuilder>().Object);

            IActionResult result     = controller.AddPersonToWorld(testPerson);
            var           badRequest = result as BadRequestObjectResult;

            Assert.Equal(400, badRequest.StatusCode);
        }
        public void AddPersonToWorld_Returns201_WhenNameDoesNotExistInRepository()
        {
            var testPerson = new Person("Anton");
            var mockRepo   = new Mock <IPeopleRepository>();

            mockRepo.Setup(repo => repo.CheckIfNameExistsInRepository(testPerson.Name)).Returns(false);
            mockRepo.Setup(repo => repo.AddPersonToRepository(testPerson));
            var controller = new PeopleController(mockRepo.Object, new Mock <IMessageBuilder>().Object);

            IActionResult result      = controller.AddPersonToWorld(testPerson);
            var           goodRequest = result as CreatedAtActionResult;

            Assert.Equal(201, goodRequest.StatusCode);
        }