コード例 #1
0
        public void Post_Create_A_Tag()
        {
            var tag      = new Tag();
            int reviewId = 42;

            underTest.Post(tag, reviewId);

            tagsRepo.Received().Create(tag);
        }
コード例 #2
0
        public void Post_And_Saves()
        {
            var tag       = new Tag();
            var tagRepo   = Substitute.For <ITagRepository>();
            var underTest = new TagsController(tagRepo);

            underTest.Post(tag, 42);

            tagRepo.Received().Create(tag);
        }
コード例 #3
0
        public void Post_AddNullTag_TagShouldNotBeAdded()
        {
            // Arrange
            var          controller = new TagsController(tagService);
            TagViewModel tag        = null;

            // Act
            IHttpActionResult result = controller.Post(tag);

            // Assert
            Assert.IsInstanceOfType(result, typeof(BadRequestResult));
        }
コード例 #4
0
        public void Post_AddNewTag_TagShouldBeAdded()
        {
            // Arrange
            var          controller = new TagsController(tagService);
            TagViewModel tag        = new TagViewModel {
                Id = 5, Name = "Tag 5"
            };

            // Act
            IHttpActionResult result = controller.Post(tag);

            // Assert
            Assert.IsInstanceOfType(result, typeof(OkResult));
        }
コード例 #5
0
        public async Task PostShouldReturnBadRequestResultWhenResultLessThanOne()
        {
            // Arrange
            var model = new Tag();

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

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

            var controller = new TagsController(fakeSql);

            // Act
            var result = await controller.Post(model);

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

            Assert.NotNull(viewResult);
        }
コード例 #6
0
        public async Task PostShouldReturnOkResultWhenResultGreaterThanOne()
        {
            // Arrange
            var model = new Tag();

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

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

            var controller = new TagsController(fakeSql);

            // Act
            var result = await controller.Post(model);

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

            Assert.NotNull(viewResult);
        }
コード例 #7
0
        public async Task PostShouldReturnInvalidModelStateResultWhenInvalidModel()
        {
            // 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.Post(model);

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

            Assert.NotNull(viewResult);
        }
コード例 #8
0
        public async Task PostShouldReturnBadRequestResultWhenResultLessThanOne()
        {
            // Arrange
            var model = new Tag();

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

            var controller = new TagsController(fakeSql);

            // Act
            var result = await controller.Post(model);

            // Assert
            var viewResult = Assert.IsType<BadRequestResult>(result);
            Assert.NotNull(viewResult);
        }
コード例 #9
0
        public async Task PostShouldReturnOkResultWhenResultGreaterThanOne()
        {
            // Arrange
            var model = new Tag();

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

            var controller = new TagsController(fakeSql);

            // Act
            var result = await controller.Post(model);

            // Assert
            var viewResult = Assert.IsType<OkNegotiatedContentResult<Tag>>(result);
            Assert.NotNull(viewResult);
        }
コード例 #10
0
        public async Task PostShouldReturnInvalidModelStateResultWhenInvalidModel()
        {
            // 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.Post(model);

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