Ejemplo n.º 1
0
        public void About_WhenCalled_ReturnsView()
        {
            HomeController controller = new HomeController(null);

            var result = controller.About() as ViewResult;

            Assert.That(result != null);
        }
Ejemplo n.º 2
0
        public async void Index_WhenCalled_ReturnsViewResult()
        {
            Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake();
            Mock<DbSet<Game>> gamesDbSetStub = TestHelpers.GetFakeAsyncDbSet(new List<Game> {futureGame1, futureGame2, pastGame1, pastGame2, pastGame3}.AsQueryable());
            dbStub.Setup(db => db.Games).Returns(gamesDbSetStub.Object);

            Mock<ControllerContext> contextStub = new Mock<ControllerContext>();
            contextStub.SetupUser().InAllRoles();

            HomeController controller = new HomeController(dbStub.Object)
            {
                ControllerContext = contextStub.Object
            };

            var result = await controller.Index() as ViewResult;

            Assert.That(result != null);
            Assert.That(result.Model, Is.InstanceOf<HomePageViewModel>());

            var model = (HomePageViewModel)result.Model;

            Assert.That(model.ComingSoon.Select(g => g.GameSKUs), Has.All.Matches<List<GameProduct>>(gs => gs.Any(lgp => lgp.ReleaseDate > DateTime.Now)));
            Assert.That(model.NewReleases.Select(g => g.GameSKUs), Has.All.Matches<List<GameProduct>>(gs => gs.Any(lgp => lgp.ReleaseDate < DateTime.Now)));
        }
Ejemplo n.º 3
0
        public async void Index_Privileged_IncludesNotForSaleGame(string role)
        {
            futureGame1.GameAvailabilityStatus = AvailabilityStatus.NotForSale;
            futureGame2.GameAvailabilityStatus = AvailabilityStatus.PreOrder;
            pastGame1.GameAvailabilityStatus = AvailabilityStatus.NotForSale;
            pastGame2.GameAvailabilityStatus = AvailabilityStatus.Available;
            pastGame3.GameAvailabilityStatus = AvailabilityStatus.DiscontinuedByManufacturer;

            List<Game> games = new List<Game>
            {
                futureGame1, futureGame2, pastGame1, pastGame2, pastGame3
            };

            Mock<IVeilDataAccess> dbStub = TestHelpers.GetVeilDataAccessFake();
            Mock<DbSet<Game>> gameDbSetStub = TestHelpers.GetFakeAsyncDbSet(games.AsQueryable());
            dbStub.Setup(db => db.Games).Returns(gameDbSetStub.Object);

            Mock<ControllerContext> contextStub = new Mock<ControllerContext>();
            contextStub.SetupUser().IsInRole(role);

            HomeController controller = new HomeController(dbStub.Object)
            {
                ControllerContext = contextStub.Object
            };

            var result = await controller.Index() as ViewResult;

            Assert.That(result != null);
            Assert.That(result.Model, Is.InstanceOf<HomePageViewModel>());

            var model = (HomePageViewModel)result.Model;

            Assert.That(model.ComingSoon, Has.Count.EqualTo(2));
            Assert.That(model.ComingSoon, Has.Member(futureGame1));
            Assert.That(model.ComingSoon, Has.Member(futureGame2));

            Assert.That(model.NewReleases, Has.Count.EqualTo(3));
            Assert.That(model.NewReleases, Has.Member(pastGame1));
            Assert.That(model.NewReleases, Has.Member(pastGame2));
            Assert.That(model.NewReleases, Has.Member(pastGame3));
        }