public void CreateReviewForGame_GET_Authenticated_ReturnsView() { Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake(); Mock<ControllerContext> contextStub = new Mock<ControllerContext>(); contextStub.SetupUserAuthenticated(true); var idGetter = TestHelpers.GetSetupIUserIdGetterFake(memberId); ReviewsController controller = new ReviewsController(dbStub.Object, idGetter.Object) { ControllerContext = contextStub.Object, }; var result = controller.CreateReviewForGame(game); Assert.That(result != null); Assert.That(result.Model, Is.InstanceOf<ReviewViewModel>()); }
public async void Deny_EmployeeDeniesReview_ReviewStatusSetDenied() { Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake(); Mock<DbSet<GameReview>> gameReviewsDbSetStub = TestHelpers.GetFakeAsyncDbSet(new List<GameReview> { pendinGameReview }.AsQueryable()); dbStub.Setup(db => db.GameReviews).Returns(gameReviewsDbSetStub.Object); gameReviewsDbSetStub.SetupForInclude(); ReviewsController controller = new ReviewsController(dbStub.Object, idGetter: null); await controller.Deny(memberGuid, gameProductGuid); Assert.That(pendinGameReview.ReviewStatus == ReviewStatus.Denied); }
public void Deny_EmployeeDeniesNullReview_Throws404() { Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake(); Mock<DbSet<GameReview>> gameReviewsDbSetStub = TestHelpers.GetFakeAsyncDbSet(new List<GameReview>().AsQueryable()); dbStub.Setup(db => db.GameReviews).Returns(gameReviewsDbSetStub.Object); ReviewsController controller = new ReviewsController(dbStub.Object, idGetter: null); Assert.That( async () => await controller.Deny(memberGuid, gameProductGuid), Throws.InstanceOf<HttpException>().And.Matches<HttpException>(e => e.GetHttpCode() == 404) ); }
public async void CreateReviewForGameProduct_ValidExisting_MarkAsChangedCalledOnce() { var existingReviews = new List<GameReview> { ratingOnlyReview }; var games = new List<Game> {game}; Mock<DbSet<Game>> gamesStub = TestHelpers.GetFakeAsyncDbSet(games.AsQueryable()); Mock<DbSet<GameReview>> gameReviewsStub = TestHelpers.GetFakeAsyncDbSet(existingReviews.AsQueryable()); gameReviewsStub.Setup(rdb => rdb.FindAsync(It.IsAny<Guid>(), It.IsAny<Guid>())).ReturnsAsync(fullReview); Mock<IVeilDataAccess> dbMock = TestHelpers.GetVeilDataAccessFake(); dbMock.Setup(db => db.GameReviews).Returns(gameReviewsStub.Object); dbMock.Setup(db => db.MarkAsModified(It.IsAny<GameReview>())).Verifiable(); dbMock.Setup(db => db.SaveChangesAsync()).ReturnsAsync(0).Verifiable(); dbMock.Setup(db => db.Games).Returns(gamesStub.Object); Mock<ControllerContext> contextStub = new Mock<ControllerContext>(); contextStub.SetupUser().InMemberRole(); var idGetter = TestHelpers.GetSetupIUserIdGetterFake(memberId); ReviewsController controller = new ReviewsController(dbMock.Object, idGetter.Object) { ControllerContext = contextStub.Object, }; ReviewViewModel model = new ReviewViewModel() { GameId = game.Id, GameSKUSelectList = null, Review = fullReview }; await controller.CreateReviewForGameProduct(model); Assert.That(() => dbMock.Verify(db => db.MarkAsModified(fullReview), Times.Once), Throws.Nothing); Assert.That(() => dbMock.Verify(db => db.SaveChangesAsync(), Times.Once), Throws.Nothing); }
public async void Pending_DisplaysPendingReviews_AllReviewsPending() { Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake(); Mock<DbSet<GameReview>> gameReviewsDbSetStub = TestHelpers.GetFakeAsyncDbSet(new List<GameReview> { pendinGameReview, approvedGameReview, deniedGameReview }.AsQueryable()); dbStub.Setup(db => db.GameReviews).Returns(gameReviewsDbSetStub.Object); gameReviewsDbSetStub.SetupForInclude(); ReviewsController controller = new ReviewsController(dbStub.Object, idGetter: null); var result = await controller.Pending() as ViewResult; Assert.That(result.Model != null); var model = (List<GameReview>)result.Model; Assert.That(model, Has.All.Matches<GameReview>(gr => gr.ReviewStatus == ReviewStatus.Pending)); }
public async void CreateReviewForGameProduct_POST_Invalid_SaveChangesNotCalled() { Mock<DbSet<GameReview>> gameReviewStub = TestHelpers.GetFakeAsyncDbSet(new List<GameReview>().AsQueryable()); gameReviewStub.Setup(rdb => rdb.FindAsync(It.IsAny<Guid>(), It.IsAny<Guid>())).ReturnsAsync(null); Mock<IVeilDataAccess> dbMock = TestHelpers.GetVeilDataAccessFake(); dbMock.Setup(db => db.GameReviews).Returns(gameReviewStub.Object); dbMock.Setup(db => db.SaveChangesAsync()).ReturnsAsync(0).Verifiable(); Mock<ControllerContext> contextStub = new Mock<ControllerContext>(); contextStub.SetupUser().InMemberRole(); var idGetter = TestHelpers.GetSetupIUserIdGetterFake(memberId); ReviewsController controller = new ReviewsController(dbMock.Object, idGetter.Object) { ControllerContext = contextStub.Object, }; controller.ModelState.AddModelError("GameId", "GameId is required"); ReviewViewModel model = new ReviewViewModel() { GameId = game.Id, GameSKUSelectList = null, Review = fullReview }; await controller.CreateReviewForGameProduct(model); Assert.That(() => dbMock.Verify(db => db.SaveChangesAsync(), Times.Never), Throws.Nothing); }
public async void CreateReviewForGameProduct_POST_UserNotInMemberRole_RedirectsBackToGameDetail() { Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake(); Mock<ControllerContext> contextStub = new Mock<ControllerContext>(); contextStub.SetupUser().InNoRoles(); var idGetter = TestHelpers.GetSetupIUserIdGetterFake(memberId); ReviewsController controller = new ReviewsController(dbStub.Object, idGetter.Object) { ControllerContext = contextStub.Object, }; ReviewViewModel model = new ReviewViewModel() { GameId = game.Id, GameSKUSelectList = null, Review = fullReview }; var result = await controller.CreateReviewForGameProduct(model) as RedirectToRouteResult; Assert.That(result != null); Assert.That(result.RouteValues["Action"], Is.EqualTo(nameof(GamesController.Details))); Assert.That(result.RouteValues["Controller"], Is.EqualTo("Games")); Assert.That(result.RouteValues["id"], Is.EqualTo(model.GameId)); }
public void CreateReviewForGame_GET_NotAuthenticated_ReturnsNull() { Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake(); Mock<ControllerContext> contextStub = new Mock<ControllerContext>(); contextStub.SetupUserAuthenticated(false); var idGetter = TestHelpers.GetSetupIUserIdGetterFake(memberId); ReviewsController controller = new ReviewsController(dbStub.Object, idGetter.Object) { ControllerContext = contextStub.Object, }; var result = controller.CreateReviewForGame(game); Assert.That(result, Is.Null); }