Beispiel #1
0
        public async Task Add_NewArticleCheckLog_ReturnsTrue()
        {
            using var connection = new SqliteConnection(_sqliteConnexionString);
            connection.Open();
            using var context = GetContext(connection);
            var logSpy            = new LogSpy(false);
            var articleController = new ArticlesController(new ArticleServices(new ArticleRepository(context), logSpy));

            var actionResultArticle = await articleController.Add(new Article()
            {
                Text = _text
            });

            Assert.True(logSpy.LogCalled);
        }
Beispiel #2
0
        public async Task Add_NewArticleCheckResultWithMock_ReturnsArticle()
        {
            using var connection = new SqliteConnection(_sqliteConnexionString);
            connection.Open();
            using var context = GetContext(connection);
            var articleController = new ArticlesController(new ArticleServices(new ArticleRepository(context), LogMockFactory.GetLogMock()));

            var actionResultArticle = await articleController.Add(new Article()
            {
                Text = _text
            });

            Assert.IsType <CreatedAtActionResult>(actionResultArticle.Result);
            Assert.IsType <Article>((actionResultArticle.Result as CreatedAtActionResult).Value);
        }
        public void Add_WithValidArticle_ShouldCallService()
        {
            // Arrange
            var  model          = new ArticleCreationBindingModel();
            bool serviceCalled  = false;
            var  mockRepository = new Mock <IAdminArticlesService>();

            mockRepository.Setup(repo => repo.AddArticleAsync(model))
            .Callback(() => serviceCalled = true);

            var userRepository = new Mock <IAdminUsersService>();

            userRepository.Setup(repo => repo.GetAuthorsAsync())
            .Callback(() => serviceCalled = true);

            var controller = new ArticlesController(userRepository.Object, mockRepository.Object);

            // Act
            var result = controller.Add(model);

            // Assert
            Assert.IsTrue(serviceCalled);
        }
Beispiel #4
0
        public void ArticlesAdd_ShouldReturnItsDefaultView()
        {
            var result = _controller.Add() as ViewResult;

            Assert.IsTrue(string.IsNullOrEmpty(result.ViewName));
        }