コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }