Esempio n. 1
0
        public async Task OnPageAsync()
        {
            #region Arrange

            var optionsBuilder = new DbContextOptionsBuilder <ApplicationDbContext>()
                                 .UseInMemoryDatabase("InMemoryDb");
            var mockDb = new Mock <ApplicationDbContext>(optionsBuilder.Options);

            var expectedUsers = ApplicationDbContext.GetSeedMentor();
            var expectedUser  = expectedUsers.FirstOrDefault();
            var username      = expectedUser.UserName;

            mockDb.Setup(db => db.GetMentorAsync(username))
            .Returns(Task.FromResult(expectedUser));

            var strategicDomains = ApplicationDbContext.GetSeedStrategicDomains();

            var pageModel = new StrategicDomainModel(mockDb.Object);
            pageModel.Username        = username;
            pageModel.StrategicDomain = strategicDomains.FirstOrDefault();

            #endregion

            #region Act
            var result = await pageModel.OnPostAsync();

            #endregion

            #region Assert
            Assert.IsType <RedirectToPageResult>(result);
            #endregion
        }
Esempio n. 2
0
        public void OnGet()
        {
            #region Arrange
            var optionsBuilder = new DbContextOptionsBuilder <ApplicationDbContext>()
                                 .UseInMemoryDatabase("InMemoryDb");
            var mockDb = new ApplicationDbContext(optionsBuilder.Options);

            var pageModel = new StrategicDomainModel(mockDb);
            #endregion

            #region Act
            var page = pageModel.OnGet();
            #endregion

            #region Assert
            Assert.Equal(
                typeof(PageResult),
                page.GetType());
            #endregion
        }
Esempio n. 3
0
        public async Task OnPageAsync_InvalidModelState()
        {
            #region Arrange

            var optionsBuilder = new DbContextOptionsBuilder <ApplicationDbContext>()
                                 .UseInMemoryDatabase("InMemoryDb");
            var mockDb = new Mock <ApplicationDbContext>(optionsBuilder.Options);

            var expectedUsers = ApplicationDbContext.GetSeedMentor();
            var expectedUser  = expectedUsers.FirstOrDefault();
            var username      = expectedUser.UserName;

            mockDb.Setup(db => db.GetMentorAsync(username))
            .Returns(Task.FromResult(expectedUser));

            var strategicDomain = ApplicationDbContext.GetSeedStrategicDomains();

            var pageModel = new StrategicDomainModel(mockDb.Object)
            {
                Username        = username,
                StrategicDomain = strategicDomain.FirstOrDefault()
            };
            pageModel.ModelState.AddModelError("This is an test error", "Error Message!");

            #endregion

            #region Act
            var result = await pageModel.OnPostAsync();

            #endregion

            #region Assert
            Assert.IsType <RedirectResult>(result);

            var pageResult = result as RedirectResult;
            var url        = pageResult.Url;
            Assert.Contains(
                "Error", url);
            #endregion
        }