public void PostCostAllocationReturnsBadRequestWhenModelIsInvalid()
        {
            var invalidModel = new CostAllocationModel();

            _sut.ModelState.AddModelError("name", "name is required");

            var result = _sut.PostEntity(invalidModel) as BadRequestResult;

            Assert.That(result, Is.Not.Null);

            _costAllocationRepositoryMock.Verify(m => m.Add(It.IsAny <CostAllocation>()), Times.Never);
        }
        public void UpdateCostAllocationReturnsBadRequestWhenIdFromModelDoesNotMatchIdFromQueryParameter()
        {
            var invalidModel = new CostAllocationModel
            {
                Id = 1
            };

            var result = _sut.UpdateEntity(invalidModel, invalidModel.Id + 1) as BadRequestObjectResult;

            Assert.That(result, Is.Not.Null);

            _costAllocationRepositoryMock.Verify(m => m.Update(It.IsAny <int>(), It.IsAny <CostAllocation>()),
                                                 Times.Never);
        }
        public void UpdateCostAllocationReturnsNotFoundWhenCostAllocationIsNotFound()
        {
            var invalidModel = new CostAllocationModel
            {
                Id = 1
            };

            _costAllocationRepositoryMock.Setup(m => m.Update(It.IsAny <int>(), It.IsAny <CostAllocation>()))
            .Returns(false);

            var result = _sut.UpdateEntity(invalidModel, invalidModel.Id) as NotFoundObjectResult;

            Assert.That(result, Is.Not.Null);

            _costAllocationRepositoryMock.Verify(m => m.Update(It.IsAny <int>(), It.IsAny <CostAllocation>()),
                                                 Times.Once);
        }
        public void PostCostAllocationReturnsOkWhenModelIsValid()
        {
            var validModel = new CostAllocationModel
            {
                Name = "name"
            };

            _mapperMock.Setup(m => m.Map <CostAllocationReturnModel>(It.IsAny <CostAllocation>()))
            .Returns(new CostAllocationReturnModel());
            _mapperMock.Setup(m => m.Map <CostAllocation>(It.IsAny <CostAllocationModel>()))
            .Returns(new CostAllocation());
            var result = _sut.PostEntity(validModel) as OkObjectResult;

            Assert.That(result, Is.Not.Null);
            Assert.That((CostAllocationReturnModel)result.Value, Is.Not.Null);

            _costAllocationRepositoryMock.Verify(m => m.Add(It.IsAny <CostAllocation>()), Times.Once);
        }
        public void UpdateCostAllocationReturnsOkWhenEverythingIsCorrect()
        {
            var validModel = new CostAllocationModel
            {
                Id   = 1,
                Name = ""
            };

            _costAllocationRepositoryMock.Setup(m => m.Update(It.IsAny <int>(), It.IsAny <CostAllocation>()))
            .Returns(true);

            var result = _sut.UpdateEntity(validModel, validModel.Id) as OkResult;

            Assert.That(result, Is.Not.Null);

            _costAllocationRepositoryMock.Verify(m => m.Update(It.IsAny <int>(), It.IsAny <CostAllocation>()),
                                                 Times.Once);
        }