public void TestCreateSetsHotelId() { // Arrange Review testReview = new Review(); // Act controllerUnderTest.Create(testReview, "ABC123"); // Assert Assert.AreEqual("ABC123", testReview.HotelID, "The controller's Create method is not setting the Hotel ID properly."); }
public void DB_Edit_test() { ReviewsController reviewController = new ReviewsController(db); ProductsController productController = new ProductsController(db2); Product testproduct = new Product("Chips", 2.00, "USA"); testproduct.ProductId = 1; Review testReview = new Review(); testReview.ReviewId = 1; testReview.Author = "Ellie"; testReview.ContentBody = "This is some content from Ellie"; testReview.Rating = 3; testReview.ProductId = 1; productController.Create(testproduct); reviewController.Create(testReview); testReview.Author = "Eli"; reviewController.Edit(testReview); var collection = (reviewController.Index() as ViewResult).ViewData.Model as List <Review>; Assert.AreEqual(testReview.Author, "Eli"); }
public void DB_EditEntry_Test() { ReviewsController controller = new ReviewsController(reviewDb); ProductsController controller2 = new ProductsController(db); Product testProduct = new Product(); testProduct.ProductId = 1; testProduct.Name = "Pepperoni"; testProduct.Cost = 12.75; testProduct.Country = "USA"; controller2.Create(testProduct); Review testReview = new Review(); testReview.Author = "Jesse"; testReview.Content_Body = "Wow"; testReview.Rating = 4; testReview.ProductId = 1; controller.Create(testReview); testReview.Author = "Kaili"; controller.Edit(testReview); var collection = (controller.Index() as ViewResult).ViewData.Model as List <Review>; Assert.AreEqual(testReview.Author, "Kaili"); }
public void DB_CreateEntryPOST_Test() { //Arrange var productController = new ProductsController(dbp); var testProduct = new Product() { Name = "Kitfo", Cost = 10, CountryOfOrigin = "Ethiopia", ProductImg = null }; productController.Create(testProduct); var productId = dbp.Products.ToList()[0].ProductId; var reviewController = new ReviewsController(db); var testReview = new Review() { Author = "Mike", ContentBody = "Awesome", Rating = "4", ProductId = productId }; //Act reviewController.Create(testReview, null); var collection = db.Reviews.ToList(); //Assert CollectionAssert.Contains(collection, testReview); }
public async Task CreateGet_Success() { // Arrange var repo = new FakeReviewRepository(TestData.Reviews()); var purchaseRepo = new FakePurchaseService(TestData.Purchases()); using (var controller = new ReviewsController(repo, purchaseRepo, new NullLogger <ReviewsController>())) { var id = 1; // Act var result = await controller.Create(id); // Assert Assert.IsNotNull(result); var review = result as ViewResult; Assert.IsNotNull(review); var purchase = review.ViewData["purchase"]; var actual = purchase as PurchaseDto; var tgt = TestData.Purchases().FirstOrDefault(p => p.Id == id); Assert.AreEqual(tgt.Id, actual.Id); Assert.AreEqual(tgt.AccountId, actual.AccountId); Assert.AreEqual(tgt.AddressId, actual.AddressId); Assert.AreEqual(tgt.OrderStatus, actual.OrderStatus); Assert.AreEqual(tgt.ProductId, actual.ProductId); Assert.AreEqual(tgt.Qty, actual.Qty); Assert.AreEqual(tgt.TimeStamp, actual.TimeStamp); } }
public async void TestCreate_InvalidReview_ShouldFail() { // Arrange ReviewsController controller = new ReviewsController(_context); InitializeReview(); review.GameId = 99; try { // Act var result = await controller.Create(review); // Assert Assert.IsType <ViewResult>(result); ViewResult viewResult = (ViewResult)result; Assert.NotNull(viewResult.ViewData.ModelState); Assert.NotEmpty(viewResult.ViewData.ModelState.Keys); foreach (string item in viewResult.ViewData.ModelState.Keys) { Assert.Equal("", item); } } catch (Exception ex) { Assert.Equal("System.NullReferenceException", ex.GetType().ToString()); } }
public void Mock_GetViewResultCreateGet_ActionResult() // Confirms route returns view { DbSetup(); ReviewsController controller = new ReviewsController(mock.Object); var result = controller.Create(); Assert.IsInstanceOfType(result, typeof(ViewResult)); }
public void Save_Changes_On_Valid_Model() { var controller = new ReviewsController(_mockMovieData.Object); controller.Create(1, new Review()); _mockMovieData.Verify(m => m.SaveChanges(), Times.Once()); }
public void Does_Not_Save_Changes_On_Invalid_Model() { var controller = new ReviewsController(_mockMovieData.Object); controller.ModelState.AddModelError("", "Error!"); controller.Create(1, new Review()); _mockMovieData.Verify(m => m.SaveChanges(), Times.Never()); }
public void TestReviewsCreate() { //Arrange FakeRestaurantRepository fakeRestaurantRepository = new FakeRestaurantRepository(); FakeReviewRepository fakeReviewRepository = new FakeReviewRepository(); ReviewsController controller = new ReviewsController(fakeRestaurantRepository, fakeReviewRepository); ReviewsCreateVM vm = new ReviewsCreateVM(fakeRestaurantRepository); string e2RestName = "McD"; //Act var result = controller.Create(vm) as ActionResult; var result2 = controller.Create(1) as ViewResult; var data2 = result2.Model as ReviewsCreateVM; //Assert Assert.IsNotNull(result); Assert.IsNotNull(result2); Assert.AreEqual(e2RestName, data2.Restaurants.First(x => x.ID == data2.Review.RestaurantID).Name); }
public void DB_CreateEntryGET_Test() { //Arrange var reviewController = new ReviewsController(db); //Act var indexViewResult = reviewController.Create(null) as ViewResult; //Assert Assert.IsInstanceOfType(indexViewResult, typeof(IActionResult)); }
public void Create() { // Arrange ReviewsController controller = new ReviewsController(); // Act ViewResult result = controller.Create() as ViewResult; // Assert Assert.IsNotNull(result); }
public void Controller_HttpPostCreate_Creates() { //Arrange DbSetup(); ReviewsController controller = new ReviewsController(mock.Object); //Act var result = controller.Create(); //Assert Assert.IsInstanceOfType(result, typeof(ViewResult)); }
public void Mock_GetViewResultCreatePost_ActionResult() // Confirms route returns view { DbSetup(); int productId = mockProduct.Object.Products.FirstOrDefault().ProductId; Review review = new Review { Rating = 2, Content = "some test content", ProductId = productId }; ReviewsController controller = new ReviewsController(mock.Object); var result = controller.Create(review); Assert.IsInstanceOfType(result, typeof(RedirectToActionResult)); }
public void TestMethod2() { //Arrange ReviewsController prodController = new ReviewsController(); // ToDo - mock DbContext and pass that in // Act var result = prodController.Create() as ViewResult; // Assert Assert.IsNotNull(result); // Assert.IsNotNull(result.Model); // add additional checks on the Model Assert.IsTrue(string.IsNullOrEmpty(result.ViewName) || result.ViewName == "Index"); }
public void CreateTest_Post_ResturnRedirectToActionResultWhenModelStateIsValid() { _reviewsServices.Setup(s => s.AddReview(new ReviewDTO() { ApplicationUserId = "324hj3h4j3h", Description = "Good", PlaceId = 18, Rating = 10 })) .Verifiable(); var result = _reviewsController.Create(new ReviewViewModel() { ApplicationUserId = "324hj3h4j3h", Description = "Good", PlaceId = 18, Rating = 10 }); Assert.IsType <RedirectToActionResult>(result); }
public void Mock_CreateReturnsView_ViewResult() { //arrange DbSetup(); ReviewsController controller = new ReviewsController(mock.Object); Review testReview = new Review { ReviewId = 1, Author = "Bob", ContentBody = "This product is great", Rating = 5 }; //act var resultView = controller.Create(testReview.ReviewId); //assert Assert.IsInstanceOfType(resultView, typeof(ViewResult)); }
public void DB_IndexListsReviews_Collection() { //arrange ReviewsController controller = new ReviewsController(db); ProductsController otherController = new ProductsController(pdb); Product testProduct = new Product("Sponge", "Sponges up liquids", (decimal)1.99); Review testReview1 = new Review("bob", "this is a great sponge", 5); Review testReview2 = new Review("frank", "this is a bad sponge", 1); //act otherController.Create(testProduct); testReview1.ProductId = testProduct.ProductId; testReview2.ProductId = testProduct.ProductId; controller.Create(testReview1); controller.Create(testReview2); var collection = (controller.Index() as ViewResult).ViewData.Model as List <Review>; List <Review> result = new List <Review> { testReview1, testReview2 }; //assert CollectionAssert.AreEqual(result, collection); Assert.IsInstanceOfType(collection, typeof(List <Review>)); }
public void testDb_Delete_RemovesFromDb() { ReviewsController controller = new ReviewsController(db); Review testReview = new Review { ReviewId = 2, Body = "A Review", Rating = 4, UserName = "******", ItemId = 1 }; controller.Create(testReview); controller.DeleteConfirmed(testReview.ReviewId); var collection = (controller.Index() as ViewResult).ViewData.Model as List <Review>; CollectionAssert.DoesNotContain(collection, testReview); }
public void DB_CreatesNewEntries_Collection() { // Arrange SetUpTheMockDb(); ReviewsController controller = new ReviewsController(db); Review testReview = new Review(); testReview.Author = "Gummi Bear"; // Act controller.Create(testReview); var collection = (controller.Index() as ViewResult).ViewData.Model as List <Review>; // Assert CollectionAssert.Contains(collection, testReview); }
public void Mock_PostViewResultCreate_ViewResult() { // Arrange Review testReview = new Review { ReviewId = 1, Title = "Love It!", Author = "Sara", Content_Body = "This is the best gummy bear I have ever had.", Rating = 5, ProductId = 1 }; DbSetup(); ReviewsController controller = new ReviewsController(reviewMock.Object); // Act var resultView = controller.Create(testReview) as RedirectToActionResult; // Assert Assert.IsInstanceOfType(resultView, typeof(RedirectToActionResult)); }
public void DB_CreatesNewReviews_Collection() { // Arrange ReviewsController controller = new ReviewsController(db); Review testReview = new Review(); testReview.Author = "TestDb Review"; testReview.Content = "Good"; testReview.Rating = 4; testReview.PropertyId = 8; // Act controller.Create(testReview); var collection = (controller.Index() as ViewResult).ViewData.Model as List <Review>; // Assert CollectionAssert.Contains(collection, testReview); }
public void TestDb_Create_AddsToDb() { DbSetUp(); ReviewsController controller = new ReviewsController(db); ItemsController itemController = new ItemsController(dbItem); Item testItem = new Item { ItemId = 7, Description = "Gummi Bears!", Name = "Gummi Bears", Cost = 1 }; Review testReview = new Review { ReviewId = 1, Body = "A Review", Rating = 4, UserName = "******", ItemId = 2 }; itemController.Create(testItem); controller.Create(testReview); var collection = (controller.Index() as ViewResult).ViewData.Model as List <Review>; CollectionAssert.Contains(collection, testReview); db.RemoveAll(); }
public async Task CreateGet_NoPurchase() { // Arrange var repo = new FakeReviewRepository(TestData.Reviews()); var purchaseRepo = new FakePurchaseService(TestData.Purchases()); using (var controller = new ReviewsController(repo, purchaseRepo, new NullLogger <ReviewsController>())) { var id = 360; // Act var result = await controller.Create(id); // Assert Assert.IsNotNull(result); var objResult = result as BadRequestObjectResult; Assert.IsNotNull(objResult); } }
public void DB_CreatesNewReviews_Collection() { //arrange ReviewsController controller = new ReviewsController(db); ProductsController otherController = new ProductsController(pdb); Product testProduct = new Product("Sponge", "Sponges up liquids", (decimal)1.99); Review testReview = new Review("bob", "this is a great sponge", 5); //act otherController.Create(testProduct); testReview.ProductId = testProduct.ProductId; controller.Create(testReview); var collection = (controller.Index() as ViewResult).ViewData.Model as List <Review>; //assert CollectionAssert.Contains(collection, testReview); }
public void Mock_PostViewResultCreate_ViewResult() { // Arrange Review testReview = new Review { ReviewId = 1, Author = "Gummi Bear" }; SetUpTheMockDb(); ReviewsController controller = new ReviewsController(mock.Object); // Act var resultView = controller.Create(testReview); // Assert Assert.IsInstanceOfType(resultView, typeof(RedirectToActionResult)); }
public void Mock_PostViewResultCreate_ViewResult() { // Arrange Review testReview = new Review { ReviewId = 4, Author = "Darwin" }; DbSetup(); ReviewsController controller = new ReviewsController(mock.Object); // Act var resultView = controller.Create(testReview) as ViewResult; // Assert Assert.IsInstanceOfType(resultView, typeof(ViewResult)); }
public void DB_CreatesNewEntries_Collection() { // Arrange ProductsController productController = new ProductsController(productDb); ReviewsController reviewController = new ReviewsController(reviewDb); Product testProduct = new Product { ProductId = 1, Name = "Giant Gummi", Description = "12 oz. gummi bear", Cost = 4.99m, ImageUrl = "https://i.ytimg.com/vi/1CbfG0epWHo/maxresdefault.jpg" }; Review testReview = new Review { ReviewId = 1, Title = "Love It!", Author = "Sara", Content_Body = "This is the best gummy bear I have ever had.", Rating = 5, ProductId = 1 }; // Act productController.Create(testProduct); reviewController.Create(testReview); var collection = (reviewController.Index() as ViewResult).ViewData.Model as List <Review>; // Assert CollectionAssert.Contains(collection, testReview); }
public async Task Succeed() { var reviewServiceMock = new Mock <IReviewService>(); var sut = new ReviewsController(reviewServiceMock.Object); var reviewViewModel = new ReviewViewModel() { Id = 1, OriginalDescription = "This is first review", BusinessUnitId = 1, Rating = 1 }; reviewServiceMock.Setup(x => x.CreateReviewAsync(reviewViewModel.OriginalDescription, reviewViewModel.BusinessUnitId, reviewViewModel.Rating)).ReturnsAsync(TestHelpersReviewController.TestReviewDTO01()); var actionResult = await sut.Create(reviewViewModel); Assert.IsInstanceOfType(actionResult, typeof(OkObjectResult)); }
public async Task ThrowsBadRequestWhenReviewWasNotCreatedNotFoundReviewId() { var reviewServiceMock = new Mock <IReviewService>(); var sut = new ReviewsController(reviewServiceMock.Object); var reviewViewModel = new ReviewViewModel() { Id = 3, OriginalDescription = null, BusinessUnitId = 1, Rating = 1 }; reviewServiceMock.Setup(x => x.CreateReviewAsync(reviewViewModel.OriginalDescription, reviewViewModel.BusinessUnitId, reviewViewModel.Rating)).ReturnsAsync(TestHelpersReviewController.TestReviewDTO01()); var actionResult = await sut.Create(reviewViewModel); Assert.IsInstanceOfType(actionResult, typeof(BadRequestObjectResult)); }