Ejemplo n.º 1
0
        public async Task OnPageAsync_MentorIsNull()
        {
            #region Arrange

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

            var expectedUsers = ApplicationDbContext.GetSeedMentor();

            var expectedUser = expectedUsers.FirstOrDefault();
            expectedUser.Mentor = null;

            var username = expectedUser.UserName;

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

            var pageModel = new AddressModel(mockDb.Object);
            pageModel.Username      = username;
            pageModel.AddressMentor = ApplicationDbContext.GetSeedAddresses()
                                      .FirstOrDefault();

            #endregion

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

            #endregion

            #region Assert
            Assert.IsType <NotFoundObjectResult>(result);
            #endregion
        }