Ejemplo n.º 1
0
        public void TestGetColdArticles()
        {
            //Arrange
            var         service = new ArticleServices();
            ArticleType shirt   = (ArticleType)Enum.Parse(typeof(ArticleType), "Shirt");
            ArticleType pants   = (ArticleType)Enum.Parse(typeof(ArticleType), "Pants");

            //Act
            service.CreateArticle("red shirt", shirt, "warm");
            service.CreateArticle("blue shirt", shirt, "cold");
            service.CreateArticle("green pants", pants, "warm");
            articlesDictionary = service.GetArticles();

            List <string> articles = new List <string>();

            articles.Add("red shirt");
            articles.Add("blue shirt");
            articles.Add("green pants");
            //Assert
            Assert.AreEqual(service.getColdArticles(articles).ElementAt(0), articles.ElementAt(1));
        }
Ejemplo n.º 2
0
        public void TestArticleTypeCreation()
        {
            //Arrange
            var service = new ArticleServices();

            string[]    articleStuff = { "red shirt", "Shirt", "warm" };
            ArticleType type         = (ArticleType)Enum.Parse(typeof(ArticleType), articleStuff[1].ToString());

            //Act
            service.CreateArticle(articleStuff[0], type, articleStuff[2]);
            articlesDictionary = service.GetArticles();
            //Assert
            Assert.AreEqual(type, articlesDictionary.ElementAt(0).Value.Type);
        }
        public async Task Should_Create_New_Article()
        {
            // Arrange
            var nameIdentifierClaim = new Claim(ClaimTypes.NameIdentifier, "Username");

            _httpContextAccessor.Setup(x => x.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier))
            .Returns(nameIdentifierClaim)
            .Verifiable();

            _repository.Setup(x => x.AddAsync(It.IsAny <entity.Article>()))
            .ReturnsAsync(MockEntityArticleModels().First())
            .Verifiable();

            //Act
            var result = await _sut.CreateArticle(MockArticleModels().First());

            //Assert
            _httpContextAccessor.Verify();
            _repository.Verify(x => x.AddAsync(It.IsAny <entity.Article>()), Times.Once);
            Assert.IsNotNull(result);
            Assert.AreEqual(result.Author, "Author1");
        }