コード例 #1
0
        public async Task Can_Create_Article_With_Existing_Author()
        {
            // arrange
            var context = GetService <AppDbContext>();
            var author  = AuthorFactory.Get();
            var article = ArticleFactory.Get();

            context.Authors.Add(author);
            await context.SaveChangesAsync();


            //const string authorLocalId = "author-1";

            var content = new
            {
                operations = new object[] {
                    new {
                        op   = "add",
                        data = new {
                            type       = "articles",
                            attributes = new {
                                name = article.Name
                            },
                            relationships = new {
                                author = new {
                                    data = new {
                                        type = "authors",
                                        id   = author.Id
                                    }
                                }
                            }
                        }
                    }
                }
            };

            // act
            var(response, data) = await PatchAsync <OperationsDocument>("api/bulk", content);

            // assert
            Assert.NotNull(response);
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            Assert.Single(data.Operations);


            var lastAuthor = await context.Authors
                             .Include(a => a.Articles)
                             .SingleAsync(a => a.Id == author.Id);

            var articleOperationResult = data.Operations[0];

            // author validation: sanity checks
            Assert.NotNull(lastAuthor);
            Assert.Equal(author.Name, lastAuthor.Name);

            //// article validation
            Assert.Single(lastAuthor.Articles);
            Assert.Equal(article.Name, lastAuthor.Articles[0].Name);
            Assert.Equal(articleOperationResult.DataObject.Id, lastAuthor.Articles[0].StringId);
        }
コード例 #2
0
        public void OrderLine_IsValid_Returns_True_When_Valid()
        {
            //Arrange
            var customer = CustomerFactory.CreateValidEntity();

            customer.Id = Guid.NewGuid();
            var order = OrderFactory.CreateValidEntity(customer);

            order.Id = Guid.NewGuid();
            var product = ProductFactory.CreateValidEntity();

            product.Id = Guid.NewGuid();
            var article = ArticleFactory.CreateValidEntity(product);

            article.Id = Guid.NewGuid();
            var orderLine = OrderLineFactory.CreateValidEntity(order, article);

            orderLine.Id = Guid.NewGuid();

            //Act
            var result = orderLine.IsValid();

            //Assert
            Assert.IsTrue(result);
        }
コード例 #3
0
        public void Add_Returns_1_When_Adding_Valid_Order()
        {
            var databaseName = Guid.NewGuid().ToString();

            using (var context = DbContextFactory.CreateInstance(databaseName))
            {
                //Arrange
                var productRepository   = new ProductRepository(context);
                var articleRepository   = new ArticleRepository(context);
                var customerRepository  = new CustomerRepository(context);
                var orderRepository     = new OrderRepository(context);
                var orderLineRepository = new OrderLineRepository(context);

                //Act
                var product = ProductFactory.CreateValidEntity();
                productRepository.Add(product);
                var article = ArticleFactory.CreateValidEntity(product);
                articleRepository.Add(article);
                var customer = CustomerFactory.CreateValidEntity();
                customerRepository.Add(customer);
                var order = OrderFactory.CreateValidEntity(customer);
                orderRepository.Add(order);
                var orderLine = OrderLineFactory.CreateValidEntity(order, article);
                orderLineRepository.Add(orderLine);

                var result = context.SaveChanges();

                //Assert
                Assert.AreEqual(5, result); //Because we added five entities
            }
        }
コード例 #4
0
        public void Get_Returns_Order_When_Found()
        {
            var databaseName = Guid.NewGuid().ToString();

            using (var context = DbContextFactory.CreateInstance(databaseName))
            {
                //Arrange
                var productRepository   = new ProductRepository(context);
                var articleRepository   = new ArticleRepository(context);
                var customerRepository  = new CustomerRepository(context);
                var orderRepository     = new OrderRepository(context);
                var orderLineRepository = new OrderLineRepository(context);

                var product = ProductFactory.CreateValidEntity();
                productRepository.Add(product);
                var article = ArticleFactory.CreateValidEntity(product);
                articleRepository.Add(article);
                var customer = CustomerFactory.CreateValidEntity();
                customerRepository.Add(customer);
                var order = OrderFactory.CreateValidEntity(customer);
                orderRepository.Add(order);
                var orderLineToAdd = OrderLineFactory.CreateValidEntity(order, article);
                orderLineRepository.Add(orderLineToAdd);

                context.SaveChanges();

                //Act
                var orderLine = orderLineRepository.Get(orderLineToAdd.Id);

                //Assert
                Assert.IsNotNull(orderLine);
            }
        }
コード例 #5
0
        public void GetAll_Returns_10_Products()
        {
            var databaseName = Guid.NewGuid().ToString();

            using (var context = DbContextFactory.CreateInstance(databaseName))
            {
                //Arrange
                var productRepository = new ProductRepository(context);
                var articleRepository = new ArticleRepository(context);
                for (int i = 0; i < 10; i++)
                {
                    var product = ProductFactory.CreateValidEntity();
                    productRepository.Add(product);
                    var articleToAdd = ArticleFactory.CreateValidEntity(product);
                    articleRepository.Add(articleToAdd);
                }
                context.SaveChanges();

                //Act
                var articles = articleRepository.GetAll();

                //Assert
                Assert.AreEqual(10, articles.Count());
            }
        }
コード例 #6
0
        public void Remove_Deletes_Product()
        {
            var  databaseName = Guid.NewGuid().ToString();
            Guid articleId;

            using (var context = DbContextFactory.CreateInstance(databaseName))
            {
                //Arrange
                var product      = ProductFactory.CreateValidEntity();
                var articleToAdd = ArticleFactory.CreateValidEntity(product);
                context.Articles.Add(articleToAdd);
                articleId = articleToAdd.Id;
                context.SaveChanges();
            }

            //Act
            using (var context = DbContextFactory.CreateInstance(databaseName))
            {
                var articleRepository = new ArticleRepository(context);
                articleRepository.Remove(articleId);
                context.SaveChanges();
            }

            //Assert
            using (var context = DbContextFactory.CreateInstance(databaseName))
            {
                var articleRepository = new ArticleRepository(context);
                var article           = articleRepository.Get(articleId);
                Assert.IsNull(article);
            }
        }
コード例 #7
0
ファイル: ArticleAPI.cs プロジェクト: Malipaard/Rockstar-S2
        public IActionResult Update(Article article)
        {
            IArticleDAL dal = ArticleFactory.GetArticleDAL();

            dal.Update(article);
            return(Accepted());
        }
コード例 #8
0
ファイル: ArticleAPI.cs プロジェクト: Malipaard/Rockstar-S2
        public IActionResult Delete(int id)
        {
            IArticleDAL dal = ArticleFactory.GetArticleDAL();

            dal.DeleteArticle(id);
            return(Accepted());
        }
コード例 #9
0
        public ActionResult Create([Bind(Exclude = "Category.Name")] ArticleViewModel model)
        {
            try
            {
                ModelState.Remove("Category.Name");
                if (ModelState.IsValid)
                {
                    var article = ArticleFactory.CreateArticleFromViewModel(model, KBVaultHelperFunctions.UserAsKbUser(User).Id);
                    var id      = ArticleRepository.Add(article, model.Tags);
                    if (article.IsDraft == 0)
                    {
                        KbVaultLuceneHelper.AddArticleToIndex(article);
                    }

                    ShowOperationMessage(UIResources.ArticleCreatePageCreateSuccessMessage);
                    return(RedirectToAction("Edit", "Article", new { id = article.Id }));
                }

                return(View(model));
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                ModelState.AddModelError("Exception", ex.Message);
                return(View(model));
            }
        }
コード例 #10
0
ファイル: ArticleAPI.cs プロジェクト: Malipaard/Rockstar-S2
        public IEnumerable <Article> GetAll()
        {
            IArticleDAL    dal      = ArticleFactory.GetArticleDAL();
            List <Article> articles = dal.GetAll();

            return(articles);
        }
コード例 #11
0
ファイル: ArticleAPI.cs プロジェクト: Malipaard/Rockstar-S2
        public int GetArticleID(string author)
        {
            IArticleDAL dal = ArticleFactory.GetArticleDAL();
            var         id  = dal.GetArticleId(author);

            return(id);
        }
コード例 #12
0
        public void Remove_Deletes_Article_With_OrderLines()
        {
            //Arrange
            var customer     = CustomerFactory.CreateValidEntity();
            var productToAdd = ProductFactory.CreateValidEntity();
            var article      = ArticleFactory.CreateValidEntity(productToAdd);
            var order        = OrderFactory.CreateValidEntity(customer);
            var orderLine    = OrderLineFactory.CreateValidEntity(order, article);

            article.OrderLines.Add(orderLine);
            productToAdd.Articles.Add(article);

            //Setup ArticleRepository
            var articleRepositoryMock = new Mock <IArticleRepository>();

            articleRepositoryMock.Setup(ir => ir.Get(It.IsAny <Guid>(), It.IsAny <ArticleIncludes>())).Returns(article);
            articleRepositoryMock.Setup(rir => rir.Remove(It.IsAny <Guid>()));

            //Setup UnitOfWork
            var unitOfWorkMock = new Mock <IUnitOfWork>();

            unitOfWorkMock.Setup(uow => uow.Articles).Returns(articleRepositoryMock.Object);
            unitOfWorkMock.Setup(uow => uow.Complete()).Returns(1);

            var articleService = new ArticleService(unitOfWorkMock.Object);

            //Act
            var result = articleService.Remove(productToAdd.Id);

            //Assert
            Assert.IsTrue(result);
        }
コード例 #13
0
        public async Task Can_Get_Article_Author()
        {
            // arrange
            var context = GetService <AppDbContext>();
            var author  = AuthorFactory.Get();
            var article = ArticleFactory.Get();

            article.Author = author;
            context.Articles.Add(article);
            context.SaveChanges();

            var content = new
            {
                operations = new[] {
                    new Dictionary <string, object> {
                        { "op", "get" },
                        { "ref", new { type = "articles", id = article.StringId, relationship = nameof(article.Author) } }
                    }
                }
            };

            // act
            var(response, data) = await PatchAsync <OperationsDocument>("api/bulk", content);

            // assert
            Assert.NotNull(response);
            Assert.NotNull(data);
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            Assert.Single(data.Operations);
            var resourceObject = data.Operations.Single().DataObject;

            Assert.Equal(author.Id.ToString(), resourceObject.Id);
            Assert.Equal("authors", resourceObject.Type);
        }
コード例 #14
0
        public void Remove_Deletes_Product_With_Articles()
        {
            //Arrange
            var productToAdd = ProductFactory.CreateValidEntity();
            var article      = ArticleFactory.CreateValidEntity(productToAdd);

            productToAdd.Articles.Add(article);


            //Setup ProductRepository
            var productRepositoryMock = new Mock <IProductRepository>();

            productRepositoryMock.Setup(ir => ir.Get(It.IsAny <Guid>(), It.IsAny <ProductIncludes>())).Returns(productToAdd);
            productRepositoryMock.Setup(ir => ir.Remove(It.IsAny <Guid>()));

            //Setup ArticleRepository
            var articleRepositoryMock = new Mock <IArticleRepository>();

            articleRepositoryMock.Setup(rir => rir.Remove(It.IsAny <Guid>()));

            //Setup UnitOfWork
            var unitOfWorkMock = new Mock <IUnitOfWork>();

            unitOfWorkMock.Setup(uow => uow.Products).Returns(productRepositoryMock.Object);
            unitOfWorkMock.Setup(uow => uow.Articles).Returns(articleRepositoryMock.Object);
            unitOfWorkMock.Setup(uow => uow.Complete()).Returns(1);

            var productService = new ProductService(unitOfWorkMock.Object);

            //Act
            var result = productService.Remove(productToAdd.Id);

            //Assert
            Assert.IsTrue(result);
        }
コード例 #15
0
        public void GetAvailableProductResults_Returns_Available_Product()
        {
            var context    = DbContextFactory.CreateInstance("GetAvailableProductResults_Returns_Available_Product");
            var unitOfWork = UnitOfWorkFactory.CreateInstance(context);

            //Arrange
            var customer = CustomerFactory.CreateValidEntity();

            customer.Id = Guid.NewGuid();
            unitOfWork.Customers.Add(customer);
            var product = ProductFactory.CreateValidEntity();

            product.Id = Guid.NewGuid();
            unitOfWork.Products.Add(product);
            var article = ArticleFactory.CreateValidEntity(product);

            article.Id = Guid.NewGuid();
            unitOfWork.Articles.Add(article);
            var article2 = ArticleFactory.CreateValidEntity(product);

            article2.Id = Guid.NewGuid();
            unitOfWork.Articles.Add(article2);
            unitOfWork.Complete();

            var productService = new ProductService(unitOfWork);

            //Act
            var result = productService.All();

            Assert.AreEqual(1, result.Count);
        }
コード例 #16
0
 public ArticleRepository(IStubToUrlConverter urlGenerator, IHttpClient httpClient, ArticleFactory articleFactory, IApplicationConfiguration config)
 {
     _urlGenerator         = urlGenerator;
     _httpClient           = httpClient;
     _articleFactory       = articleFactory;
     _config               = config;
     authenticationHeaders = new Dictionary <string, string> {
         { "Authorization", _config.GetContentApiAuthenticationKey() }, { "X-ClientId", _config.GetWebAppClientId() }
     };
 }
コード例 #17
0
        public void Article_IsValid_Returns_False_When_Invalid()
        {
            //Arrange
            var article = ArticleFactory.CreateInvalidEntity();

            //Act
            var result = article.IsValid();

            //Assert
            Assert.IsFalse(result);
        }
コード例 #18
0
        public ArticleFactoryTests()
        {
            _webPageDownloader = Substitute.For <IWebPageDownloader>();
            _webPageDownloader.Download(Arg.Any <string>()).Returns("<html></html>");

            var keywordDictionary = Substitute.For <IKeywordDictionary>();

            keywordDictionary.IsValidKeyword(Arg.Any <string>()).Returns(true);

            _articleFactory = new ArticleFactory(new HtmlParser(), _webPageDownloader, new KeywordsParser(keywordDictionary));
        }
コード例 #19
0
    public ArticleCate()
    {
        //初始化ASP.NET内置对象
        Response    = System.Web.HttpContext.Current.Response;
        Request     = System.Web.HttpContext.Current.Request;
        Server      = System.Web.HttpContext.Current.Server;
        Session     = System.Web.HttpContext.Current.Session;
        Application = System.Web.HttpContext.Current.Application;

        tools = ToolsFactory.CreateTools();
        MyBLL = ArticleFactory.CreateArticleCate();
    }
コード例 #20
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);
        }
コード例 #21
0
ファイル: ArticleAPI.cs プロジェクト: Malipaard/Rockstar-S2
 public Article Get(int id)
 {
     try {
         IArticleDAL dal     = ArticleFactory.GetArticleDAL();
         var         article = dal.GetArticle(id);
         return(article);
     }
     catch
     {
         return(null);
     }
 }
コード例 #22
0
 public ActionResult Edit(int id)
 {
     try
     {
         return(View("Create", ArticleFactory.CreateArticleViewModel(ArticleRepository.Get(id))));
     }
     catch (Exception ex)
     {
         Log.Error(ex);
         return(RedirectToAction("Index", "Error"));
     }
 }
コード例 #23
0
 public SynchronizeMediaFeedsCommandHandler(
     IRepository repository,
     IFeedReader feedReader,
     ArticleFactory articleFactory,
     ISynchronizationFinder synchronizationFinder,
     ILogger logger)
 {
     _repository            = repository;
     _feedReader            = feedReader;
     _articleFactory        = articleFactory;
     _synchronizationFinder = synchronizationFinder;
     _logger = logger;
 }
コード例 #24
0
ファイル: ArticleAPI.cs プロジェクト: Malipaard/Rockstar-S2
 public ArticleCard GetCard(int id)
 {
     try
     {
         IArticleDAL dal  = ArticleFactory.GetArticleDAL();
         var         card = dal.GetCard(id);
         return(card);
     }
     catch
     {
         return(null);
     }
 }
コード例 #25
0
ファイル: ArticleAPI.cs プロジェクト: Malipaard/Rockstar-S2
 public List <ArticleCard> GetAllCards()
 {
     try
     {
         IArticleDAL dal   = ArticleFactory.GetArticleDAL();
         var         cards = dal.GetAllCards();
         return(cards);
     }
     catch
     {
         return(null);
     }
 }
コード例 #26
0
    public Article()
    {
        //初始化ASP.NET内置对象
        Response    = System.Web.HttpContext.Current.Response;
        Request     = System.Web.HttpContext.Current.Request;
        Server      = System.Web.HttpContext.Current.Server;
        Session     = System.Web.HttpContext.Current.Session;
        Application = System.Web.HttpContext.Current.Application;

        tools       = ToolsFactory.CreateTools();
        MyBLL       = ArticleFactory.CreateArticle();
        MyArt_Label = Article_LabelFactory.CreateArticle_Label();
        MyLabel     = Product_Article_LabelFactory.CreateProduct_Article_Label();

        articleCate = new ArticleCate();
    }
コード例 #27
0
        public void Article_IsValid_Returns_True_When_Valid()
        {
            //Arrange
            var product = ProductFactory.CreateValidEntity();

            product.Id = Guid.NewGuid();
            var article = ArticleFactory.CreateValidEntity(product);

            article.Id = Guid.NewGuid();

            //Act
            var result = article.IsValid();

            //Assert
            Assert.IsTrue(result);
        }
コード例 #28
0
        [Fact] public async void TestSuccesfullAddArticles()
        {
            var articleContext   = new ArticlesContext(options);
            var controller       = new ArticlesController(articleContext);
            var articleFactory   = new ArticleFactory();
            var publisherFactory = new PublisherFactory();
            var pub = publisherFactory.GetDataObject(0, 0).Publisher;
            await articleContext.Publishers.AddAsync(pub);

            await controller.AddArticles(articleFactory.GenerateArticle(pub.Id));

            var articles = await controller.GetArticles();

            Assert.True(await articleContext.Publishers.CountAsync() == 1);
            Assert.True(articles.Value.Count == 1);
        }
コード例 #29
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);
        }
コード例 #30
0
        public void GetAvailableProductResults_Returns_No_Available_Product_When_All_Rented()
        {
            var context    = DbContextFactory.CreateInstance("GetAvailableProductResults_Returns_No_Available_Product_When_All_Rented");
            var unitOfWork = UnitOfWorkFactory.CreateInstance(context);

            //Arrange
            var customer = CustomerFactory.CreateValidEntity();

            customer.Id = Guid.NewGuid();
            unitOfWork.Customers.Add(customer);
            var product = ProductFactory.CreateValidEntity();

            product.Id = Guid.NewGuid();
            unitOfWork.Products.Add(product);
            var article = ArticleFactory.CreateValidEntity(product);

            article.Id = Guid.NewGuid();
            unitOfWork.Articles.Add(article);
            var article2 = ArticleFactory.CreateValidEntity(product);

            article2.Id = Guid.NewGuid();
            unitOfWork.Articles.Add(article2);
            var order = OrderFactory.CreateValidEntity(customer);

            order.Id = Guid.NewGuid();
            unitOfWork.Orders.Add(order);
            var orderLine = OrderLineFactory.CreateValidEntity(order, article);

            orderLine.Id         = Guid.NewGuid();
            orderLine.ReturnedAt = null;
            unitOfWork.OrderLines.Add(orderLine);
            var orderLine2 = OrderLineFactory.CreateValidEntity(order, article2);

            orderLine2.Id         = Guid.NewGuid();
            orderLine2.ReturnedAt = null;
            unitOfWork.OrderLines.Add(orderLine2);
            unitOfWork.Complete();

            var productService = new ProductService(unitOfWork);

            //Act
            var result = productService.GetAvailableProductResults();

            Assert.AreEqual(0, result.Count);
        }