Beispiel #1
0
        public async Task Can_Post_Article()
        {
            // arrange
            var article = ArticleFactory.Create(1).Single();
            var json    = Serialize(article);

            // act
            var result = await Client.PostAsync("/api/articles", json);

            // assert
            Assert.Equal(HttpStatusCode.Created, result.StatusCode);
        }
Beispiel #2
0
        public async Task GetAllAsync_Returns_All_Articles()
        {
            // arrange
            var expectedArticleCount = _faker.Random.Int(5, 15);
            var expectedArticles     = ArticleFactory.Create(expectedArticleCount);

            DbContext.Articles.AddRange(expectedArticles);
            await DbContext.SaveChangesAsync();

            var service = GetService();

            // act
            var actualArticles = await service.GetAllAsync();

            // assert
            Assert.Equal(expectedArticleCount, actualArticles.Count);
        }
        public async Task GetArticlesAsync_Returns_Articles()
        {
            // arrange
            var expectedArticleCount = _faker.Random.Int(5, 15);
            var expectedArticles     = ArticleFactory.Create(expectedArticleCount);

            foreach (var article in expectedArticles)
            {
                await Connection.InsertAsync <Article>(article);
            }

            var repo = new ArticleRepository(Connection);

            // act
            var articles = await repo.GetArticlesAsync();

            // assert
            Assert.Equal(expectedArticleCount, articles.Count);
        }
Beispiel #4
0
        public void ShouldCreateAnArticle()
        {
            // Arrange
            var request = new AddArticleRequest
            {
                Content     = Content,
                Description = Description,
                Title       = Title
            };

            // Act
            var article = _factory.Create(request, UserId);

            // Assert
            Assert.Equal(request.Content, article.Content);
            Assert.Equal(request.Title, article.Title);
            Assert.Equal(request.Description, article.Description);
            Assert.Equal(UserId, article.AuthorId);
            Assert.True(article.EverPublished);
        }
Beispiel #5
0
        public async Task Can_Get_Article()
        {
            // arrange
            var article = ArticleFactory.Create(1).Single();

            DbContext.Articles.Add(article);
            await DbContext.SaveChangesAsync();

            // act
            var result = await Client.GetAsync("/api/articles");

            // assert
            Assert.Equal(HttpStatusCode.OK, result.StatusCode);

            var articles = await DeserializeAsync <List <Article> >(result);

            Assert.Equal(1, articles.Count);
            Assert.Equal(article.Id, articles.Single().Id);
            Assert.Equal(article.Title, articles.Single().Title);
        }
        public void CreateProductTest()
        {
            // Arrange

            IArticlesService articlesService = new MockArticlesService();

            // Acts

            bool isProduct = true;

            Article article = ArticleFactory.Create(isProduct);

            //if (isProduct)
            //{
            //    article = new Product();
            //}
            //else
            //{
            //    article = new Service();
            //}

            articlesService.Add(article);
        }
        public void CreateTest()
        {
            var article = ArticleFactory.Create("Product");

            Assert.IsNotNull(article);
        }