public void GetReviewsReturnNull() { // ARRANGE - generate empty List IQueryable <Review> dummyReviews = new List <Review> ().AsQueryable(); var _reviewSet = MockingHelper.Create(dummyReviews); _db.Setup(x => x.Reviews).Returns(_reviewSet.Object); // ACT var result = _controller.GetReviews(); // ASSERT Assert.AreEqual(0, result.Count()); }
public async void GetReviewsTest() { mockIRepo.Setup(x => x.GetReviewsAsync()).Verifiable(); var allReviews = await reviewsController.GetReviews(); allReviews.Should().NotBeNull(); }
public async Task GetReviews_ReturnsAllReviews() { // arrange var controller = new ReviewsController(_context); // act var result = await controller.GetReviews(); // assert var objectResult = Assert.IsType <OkObjectResult>(result); var reviews = Assert.IsAssignableFrom <IEnumerable <Review> >(objectResult.Value); Assert.Equal(3, reviews.Count()); }
public async Task GetReviews_Void_TaskActionResultContainsIEnumerableOfReview() { // Arrange List <Review> expectedData = GetFakeList(); InitializeInmemoryDatabase(out DbContextOptions <GameReviewsContext> options, GetFakeList()); // Act using (var context = new GameReviewsContext(options)) { ReviewsController reviewsController = new ReviewsController(context); IEnumerable <Review> reviews = (await reviewsController.GetReviews()).Value; // Assert Assert.Equal(expectedData.Count, reviews.Count()); for (int i = 0; i < expectedData.Count; ++i) { Assert.True(AreEqual(expectedData[i], reviews.ElementAt(i))); } } }
public void ValidGetReviewsShouldListAll() { var options = new DbContextOptionsBuilder <BookingsDbContext>() .UseInMemoryDatabase(databaseName: nameof(ValidGetReviewsShouldListAll)) .Options; using (var context = new BookingsDbContext(options)) { var controller = new ReviewsController(context); Review review1 = new Review { HotelId = 1, UserId = 1, Text = "Cool", Rating = 8 }; Review review2 = new Review { HotelId = 2, UserId = 2, Text = "Cool", Rating = 8 }; // Arrange controller.PostReview(review1); controller.PostReview(review2); // Act var result = controller.GetReviews(); // Assert Assert.IsNotNull(result); var okResult = result.Should().BeOfType <ActionResult <IEnumerable <Review> > >().Subject; okResult.Value.Count().Should().Be(2); } }
public async void GetReviews() { // Arrange var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase("SocialMediumForMusicians2").Options; var storeOptions = Options.Create(new OperationalStoreOptions()); using (var context = new ApplicationDbContext(options, storeOptions)) { var m1 = new Musician() { Id = "1", Email = "*****@*****.**", Name = "Aaa", Price = 10.03M, Types = new List <MusicianType>() { MusicianType.Jamming, MusicianType.Session, MusicianType.Teacher }, Instruments = new List <string>() { "Drums" } }; var m2 = new Musician() { Id = "2", Email = "*****@*****.**", Name = "Bbb", Price = 20.03M, Types = new List <MusicianType>() { MusicianType.Jamming }, Instruments = new List <string>() { "Guitar", "Bass Guitar", "Drums" } }; var m3 = new Musician() { Id = "3", Email = "*****@*****.**", Name = "Ccc", Price = 20.03M, Types = new List <MusicianType>() { MusicianType.Teacher }, Instruments = new List <string>() { "Drums" } }; var m4 = new Musician() { Id = "4", Email = "*****@*****.**", Name = "Ddd", Price = 40.03M }; context.AddRange(new List <Musician>() { m1, m2, m3, m4 }); var r1 = new Review() { Author = m4, Target = m1, Rate = 4, SentAt = new System.DateTime(2000, 12, 31, 15, 43, 23) }; var r2 = new Review() { Author = m4, Target = m1, Rate = 3, SentAt = new System.DateTime(2001, 12, 31, 15, 43, 23) }; var r3 = new Review() { Author = m4, Target = m2, Rate = 5, SentAt = new System.DateTime(2002, 12, 31, 15, 43, 23) }; var r4 = new Review() { Author = m1, Target = m2, Rate = 2, SentAt = new System.DateTime(2003, 12, 31, 15, 43, 23) }; var r5 = new Review() { Author = m2, Target = m1, Rate = 1, SentAt = new System.DateTime(2004, 12, 31, 15, 43, 23) }; context.AddRange(new List <Review>() { r1, r2, r3, r4, r5 }); context.SaveChanges(); } PaginationApiResult <ReviewsListDTO> result; PaginationApiResult <ReviewsListDTO> resultPagination; PaginationApiResult <ReviewsListDTO> resultAuthor; // Act using (var context = new ApplicationDbContext(options, storeOptions)) { var controller = new ReviewsController(context); result = (await controller.GetReviews(top: 3)).Value; resultPagination = (await controller.GetReviews(id: "1", pageIndex: 0, pageSize: 2)).Value; resultAuthor = (await controller.GetReviews(id: "1", authorId: "4")).Value; } // Assert Assert.Equal(3, result.Elements.Count); Assert.Equal(1, result.Elements[0].Rate); // ID & pagination Assert.Equal(2, resultPagination.Elements.Count); Assert.Equal(3, resultPagination.TotalCount); Assert.Equal(2, resultPagination.TotalPages); Assert.Equal(2, resultAuthor.Elements.Count); }