Esempio n. 1
0
        public async Task OnPostDeleteAsync_ReturnsARedirectToPageWhenUserDoesntExist(int userId)
        {
            // Arrange
            var optionsBuilder = new DbContextOptionsBuilder <ClippyContext>()
                                 .UseInMemoryDatabase("InMemoryDb");
            var mockContext = new Mock <ClippyContext>(optionsBuilder.Options);
            var mockLogger  = new Mock <ILogger <DetailsModel> >();

            mockContext.Setup(
                db => db.GetUserAsync(userId)).Returns(Task.FromResult((User)null));
                var httpContext = new DefaultHttpContext();
            var     tempData    = new TempDataDictionary(httpContext, Mock.Of <ITempDataProvider>());
            var     pageModel   = new DetailsModel(mockContext.Object, mockLogger.Object)
            {
                TempData = tempData    
            };

            pageModel.UnitTesting = true;

            // Act
            var result = await pageModel.OnPostDeleteAsync(userId);

            // Assert
            Assert.IsType <RedirectToPageResult>(result);
        }
Esempio n. 2
0
        public async Task OnPostDeleteAsync_ReturnsARedirectToPageResult(int bookmarkId)
        {
            // Arrange
            var optionsBuilder = new DbContextOptionsBuilder <ClippyContext>()
                                 .UseInMemoryDatabase("InMemoryDb");
            var mockContext      = new Mock <ClippyContext>(optionsBuilder.Options);
            var expectedBookmark = DatabaseInitializer.GetSeedingBookmarks().Single(b => b.Id == bookmarkId);

            mockContext.Setup(
                db => db.GetBookmarkAsync(bookmarkId)).Returns(Task.FromResult(expectedBookmark));
                var httpContext = new DefaultHttpContext();
            var     tempData    = new TempDataDictionary(httpContext, Mock.Of <ITempDataProvider>());
            var     pageModel   = new DetailsModel(mockContext.Object)
            {
                TempData = tempData    
            };

            // Act
            var result = await pageModel.OnPostDeleteAsync(bookmarkId);

            // Assert
            Assert.IsType <RedirectToPageResult>(result);
        }