public void Post_Create_A_Tag() { var tag = new Tag(); int reviewId = 42; underTest.Post(tag, reviewId); tagsRepo.Received().Create(tag); }
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); }
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)); }
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)); }
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); }
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); }
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); }
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); }
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); }
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); }