public void Put_MismatchBetweenUrlIdAndStagecoördinatorIdCausesBadRequest()
        {
            //Arange
            var stagecoördinator = new StagecoördinatorBuilder().WithId().Build();

            //Act
            var badRequestResult = _controller.Put(10, stagecoördinator) as BadRequestResult;

            //Assert
            Assert.That(badRequestResult, Is.Not.Null);
        }
        public void Put_InValidStagecoördinatorModelStateCausesBadRequest()
        {
            //Arrange
            var stagecoördinator = new StagecoördinatorBuilder().WithNumber().Build();

            _controller.ModelState.AddModelError("Name", "Name is required");

            //Act
            var badRequestResult = _controller.Put(stagecoördinator.Id, stagecoördinator) as BadRequestResult;

            //Assert
            Assert.That(badRequestResult, Is.Not.Null);
        }
        public void Get_ValidId_ReturnsStagecoördinatorIfItExists()
        {
            //Arrange
            var stagecoördinator = new StagecoördinatorBuilder().WithId().Build();

            _controller.StagecoördinatorRepositoryMock.Setup(repo => repo.Get(It.IsAny <int>())).Returns(stagecoördinator);

            //Act
            var okResult = _controller.Get(stagecoördinator.Id) as OkNegotiatedContentResult <Stagecoördinator>;

            //Assert
            Assert.That(okResult, Is.Not.Null);
            _controller.StagecoördinatorRepositoryMock.Verify(repo => repo.Get(stagecoördinator.Id), Times.Once);
            Assert.That(okResult.Content, Is.EqualTo(stagecoördinator));
        }
        public void Delete_ExistingStagecoördinatorIsDeletedFromRepository()
        {
            //Arrange
            var stagecoördinator = new StagecoördinatorBuilder().WithId().Build();

            _controller.StagecoördinatorRepositoryMock.Setup(repo => repo.Get(stagecoördinator.Id)).Returns(() => stagecoördinator);

            //Act
            var action = _controller.Delete(stagecoördinator.Id) as OkResult;

            //Assert
            Assert.That(action, Is.Not.Null);
            _controller.StagecoördinatorRepositoryMock.Verify(r => r.Get(stagecoördinator.Id), Times.Once);
            _controller.StagecoördinatorRepositoryMock.Verify(r => r.Delete(stagecoördinator.Id), Times.Once);
        }
        public void Put_ExistingStagecoördinatorIsSavedInRepository()
        {
            //Arrange
            var stagecoördinator = new StagecoördinatorBuilder().WithId().Build();

            _controller.StagecoördinatorRepositoryMock.Setup(repo => repo.Get(stagecoördinator.Id)).Returns(() => stagecoördinator);

            //Act
            var okResult = _controller.Put(stagecoördinator.Id, stagecoördinator) as OkResult;

            //Assert
            Assert.That(okResult, Is.Not.Null);
            _controller.StagecoördinatorRepositoryMock.Verify(repo => repo.Get(stagecoördinator.Id), Times.Once);
            _controller.StagecoördinatorRepositoryMock.Verify(repo => repo.Update(stagecoördinator), Times.Once);
        }
        public void GetHomeData_ValidId_ReturnsStageCoördinatorHomePageData()
        {
            //Arrange
            var stagecoördinator = new StagecoördinatorBuilder().WithId().Build();

            _controller.StagecoördinatorRepositoryMock.Setup(repo => repo.GetHomePageData(It.IsAny <int>())).Returns(stagecoördinator);

            //Act

            var returnedHomePageData = _controller.GetHomeData(stagecoördinator.Id) as OkNegotiatedContentResult <Stagecoördinator>;

            //Assert
            Assert.That(returnedHomePageData, Is.Not.Null);
            _controller.StagecoördinatorRepositoryMock.Verify(repo => repo.GetHomePageData(stagecoördinator.Id), Times.Once);
            Assert.That(returnedHomePageData.Content, Is.EqualTo(stagecoördinator));
        }
        public void Put_NonExistingStagecoördinatorReturnsNotFound()
        {
            //Aragnge
            _controller.StagecoördinatorRepositoryMock.Setup(s => s.Get(It.IsAny <int>())).Returns(() => null);

            var stagecoördinator = new StagecoördinatorBuilder().WithId().Build();

            //Act
            var notFoundResult = _controller.Put(stagecoördinator.Id, stagecoördinator) as NotFoundResult;

            //Assert
            Assert.That(notFoundResult, Is.Not.Null);

            _controller.StagecoördinatorRepositoryMock.Verify(repo => repo.Get(stagecoördinator.Id), Times.Once);
            _controller.StagecoördinatorRepositoryMock.Verify(repo => repo.Update(It.IsAny <Stagecoördinator>()), Times.Never);
        }
        public void Post_ValidStagecoördinatorIsSavedInRepository()
        {
            //Arange
            var stagecoördinator = new StagecoördinatorBuilder().Build();

            _controller.StagecoördinatorRepositoryMock.Setup(repo => repo.Post(It.IsAny <Stagecoördinator>())).Returns(() =>
            {
                stagecoördinator.Id = new Random().Next();
                return(stagecoördinator);
            });

            //Act
            var actionResult = _controller.Post(stagecoördinator) as CreatedAtRouteNegotiatedContentResult <Stagecoördinator>;

            //Assert
            Assert.That(actionResult, Is.Not.Null);
            _controller.StagecoördinatorRepositoryMock.Verify(repo => repo.Post(stagecoördinator), Times.Once);
            Assert.That(actionResult.Content, Is.EqualTo(stagecoördinator)); //---
            Assert.That(actionResult.Content.Id, Is.GreaterThan(0));
            Assert.That(actionResult.RouteName, Is.EqualTo("DefaultApi"));
            Assert.That(actionResult.RouteValues.Count, Is.EqualTo(2));
            Assert.That(actionResult.RouteValues["controller"], Is.EqualTo("Stagecoördinator"));
            Assert.That(actionResult.RouteValues["id"], Is.EqualTo(actionResult.Content.Id));
        }