Esempio n. 1
0
        public void Put_UpdateNullTag_TagShouldNotBeUpdated()
        {
            // Arrange
            var          controller = new TagsController(tagService);
            TagViewModel tag        = null;

            // Act
            IHttpActionResult result = controller.Put(5, tag);

            // Assert
            Assert.IsInstanceOfType(result, typeof(BadRequestResult));
        }
Esempio n. 2
0
        public void Put_UpdateExisingTag_TagShouldBeUpdated()
        {
            // Arrange
            var          controller = new TagsController(tagService);
            TagViewModel tag        = new TagViewModel {
                Id = 1, Name = "Updated Tag 1"
            };

            // Act
            IHttpActionResult result = controller.Put(tag.Id, tag);

            // Assert
            Assert.IsInstanceOfType(result, typeof(OkResult));
        }
Esempio n. 3
0
        public async Task PutShouldReturnBadRequestResultWhenResultFalse()
        {
            // Arrange
            var model = new Tag();

            var fakeSql = Substitute.For <IDatabase>();

            fakeSql.UpdateAsync(model).Returns(Task.FromResult(false));

            var controller = new TagsController(fakeSql);

            // Act
            var result = await controller.Put(1, model);

            // Assert
            var viewResult = Assert.IsType <BadRequestResult>(result);

            Assert.NotNull(viewResult);
        }
Esempio n. 4
0
        public async Task PutShouldReturnOkResultWhenResultTrue()
        {
            // Arrange
            var model = new Tag();

            var fakeSql = Substitute.For <IDatabase>();

            fakeSql.UpdateAsync(model).Returns(Task.FromResult(true));

            var controller = new TagsController(fakeSql);

            // Act
            var result = await controller.Put(1, model);

            // Assert
            var viewResult = Assert.IsType <OkNegotiatedContentResult <Tag> >(result);

            Assert.NotNull(viewResult);
        }
Esempio n. 5
0
        public async Task PutShouldReturnReturnOkResultWithModelIdSetToId()
        {
            // Arrange
            var model = new Tag {
                Id = 1
            };

            var fakeSql = Substitute.For <IDatabase>();

            fakeSql.UpdateAsync(model).Returns(Task.FromResult(true));

            var controller = new TagsController(fakeSql);

            // Act
            var result = await controller.Put(2, model);

            // Assert
            var viewResult = Assert.IsType <OkNegotiatedContentResult <Tag> >(result);

            Assert.Equal(viewResult.Content.Id, 2);
        }
Esempio n. 6
0
        public async Task PutShouldReturnInvalidModelStateResultWhenInvalidModel()
        {
            // Arrange
            var model = new Tag();

            var fakeSql = Substitute.For <IDatabase>();

            fakeSql.CreateAsync(model).Returns(Task.FromResult(1));

            var controller = new TagsController(fakeSql)
            {
                Configuration = new HttpConfiguration()
            };

            controller.ModelState.AddModelError("FakeError", "This is a Fake Error!");

            // Act
            var result = await controller.Put(1, model);

            // Assert
            var viewResult = Assert.IsType <InvalidModelStateResult>(result);

            Assert.NotNull(viewResult);
        }
        public async Task PutShouldReturnReturnOkResultWithModelIdSetToId()
        {
            // Arrange
            var model = new Tag { Id = 1 };

            var fakeSql = Substitute.For<IDatabase>();
            fakeSql.UpdateAsync(model).Returns(Task.FromResult(true));

            var controller = new TagsController(fakeSql);

            // Act
            var result = await controller.Put(2, model);

            // Assert
            var viewResult = Assert.IsType<OkNegotiatedContentResult<Tag>>(result);
            Assert.Equal(viewResult.Content.Id, 2);
        }
        public async Task PutShouldReturnInvalidModelStateResultWhenInvalidModel()
        {
            // Arrange
            var model = new Tag();

            var fakeSql = Substitute.For<IDatabase>();
            fakeSql.CreateAsync(model).Returns(Task.FromResult(1));

            var controller = new TagsController(fakeSql)
            {
                Configuration = new HttpConfiguration()
            };
            controller.ModelState.AddModelError("FakeError", "This is a Fake Error!");

            // Act
            var result = await controller.Put(1, model);

            // Assert
            var viewResult = Assert.IsType<InvalidModelStateResult>(result);
            Assert.NotNull(viewResult);
        }
        public async Task PutShouldReturnBadRequestResultWhenResultFalse()
        {
            // Arrange
            var model = new Tag();

            var fakeSql = Substitute.For<IDatabase>();
            fakeSql.UpdateAsync(model).Returns(Task.FromResult(false));

            var controller = new TagsController(fakeSql);

            // Act
            var result = await controller.Put(1, model);

            // Assert
            var viewResult = Assert.IsType<BadRequestResult>(result);
            Assert.NotNull(viewResult);
        }
        public async Task PutShouldReturnOkResultWhenResultTrue()
        {
            // Arrange
            var model = new Tag();

            var fakeSql = Substitute.For<IDatabase>();
            fakeSql.UpdateAsync(model).Returns(Task.FromResult(true));

            var controller = new TagsController(fakeSql);

            // Act
            var result = await controller.Put(1, model);

            // Assert
            var viewResult = Assert.IsType<OkNegotiatedContentResult<Tag>>(result);
            Assert.NotNull(viewResult);
        }