public static async Task <Article> CreateNewAsync(Article article = null)
        {
            Console.WriteLine("Creating new article");
            var     now = DateTime.Now;
            dynamic obj = article ?? new Article("object");

            if (article == null)
            {
                obj.intfield      = 1;
                obj.decimalfield  = 10.0m;
                obj.datefield     = "2012-12-20";
                obj.datetimefield = now.ToString("o");
                obj.stringfield   = "string value";
                obj.textfield     = "text value";
                obj.boolfield     = false;
                obj.geofield      = "11.5,12.5";
                obj.listfield     = "a";
                obj.SetAttribute("attr1", "value1");
                obj.SetAttribute("attr2", "value2");
            }

            CreateArticleResponse response = null;

            response = await(new CreateArticleRequest()
            {
                Article     = obj,
                Environment = Environment.Sandbox
            }).ExecuteAsync();
            ApiHelper.EnsureValidResponse(response);
            Assert.IsNotNull(response.Article);
            Console.WriteLine("Created article id {0}", response.Article.Id);
            return(response.Article);
        }
Ejemplo n.º 2
0
        public ActionResult <CreateArticleService> Post(ArticleRequest request)
        {
            CreateArticleService  _service = new CreateArticleService(_unitOfWork);
            CreateArticleResponse response = _service.Execute(request);

            return(Ok(response));
        }
        public async Task DeleteArticleAsyncTest()
        {
            // Create article
            var     now = DateTime.Now;
            dynamic obj = new Article("object");

            obj.intfield      = 1;
            obj.decimalfield  = 10.0m;
            obj.datefield     = "2012-12-20";
            obj.datetimefield = now.ToString("o");
            obj.stringfield   = "string value";
            obj.textfield     = "text value";
            obj.boolfield     = false;
            obj.geofield      = "11.5,12.5";
            obj.listfield     = "a";
            obj.SetAttribute("attr1", "value1");
            obj.SetAttribute("attr2", "value2");

            CreateArticleResponse response = null;

            response = await(new CreateArticleRequest()
            {
                Article = obj
            }).ExecuteAsync();
            Assert.IsNotNull(response);
            Assert.IsNotNull(response.Status);
            Assert.IsTrue(response.Status.IsSuccessful);
            Assert.IsNotNull(response.Article);
            Console.WriteLine("Created article id {0}", response.Article.Id);
            Console.WriteLine("Time taken: {0} seconds", response.TimeTaken);

            // Delete the article
            var deleteArticleResponse = await(new DeleteArticleRequest()
            {
                Id   = response.Article.Id,
                Type = response.Article.Type
            }).ExecuteAsync();

            Assert.IsNotNull(deleteArticleResponse, "Delete articler response is null.");
            Assert.IsTrue(deleteArticleResponse.Status.IsSuccessful == true,
                          deleteArticleResponse.Status.Message ?? "Delete article operation failed.");

            // Try get the deleted article
            var getArticleResponse = await(
                new GetArticleRequest()
            {
                Id   = response.Article.Id,
                Type = response.Article.Type
            }).ExecuteAsync();

            Assert.IsNotNull(getArticleResponse, "Get article response is null.");
            Assert.IsNull(getArticleResponse.Article, "Should not be able to get a deleted article.");
            Assert.IsTrue(getArticleResponse.Status.Code == "404", "Error code expected was not 404.");
        }
        public async Task FindAllArticleAsyncFixture()
        {
            // Create atleast one article
            var     now = DateTime.Now;
            dynamic obj = new Article("object");

            obj.intfield      = 66666;
            obj.decimalfield  = 98765.0m;
            obj.datefield     = "2012-12-20";
            obj.datetimefield = now.ToString("o");
            obj.stringfield   = "Frank";
            obj.textfield     = "Frand Sinatra was an amazing singer.";
            obj.boolfield     = false;
            obj.geofield      = "11.5,12.5";
            obj.listfield     = "a";


            CreateArticleResponse response = null;

            response = await(new CreateArticleRequest()
            {
                Article = obj
            }).ExecuteAsync();

            ApiHelper.EnsureValidResponse(response);

            // Find all articles
            var findRequest = new FindAllArticleRequest()
            {
                Type = "object"
            };
            var findResponse = await findRequest.ExecuteAsync();

            ApiHelper.EnsureValidResponse(findResponse);
            findResponse.Articles.ForEach(x => Console.WriteLine("Found article id {0}.", x.Id));
            Assert.IsNotNull(findResponse.PagingInfo);
            Assert.IsTrue(findResponse.PagingInfo.PageNumber == 1);
            Assert.IsTrue(findResponse.PagingInfo.TotalRecords > 0);
            Console.WriteLine("Paging info => pageNumber: {0}, pageSize: {1}, totalRecords: {2}",
                              findResponse.PagingInfo.PageNumber,
                              findResponse.PagingInfo.PageSize,
                              findResponse.PagingInfo.TotalRecords);
        }
        public async Task CreateArticleAsyncTest()
        {
            // Create article
            var     now = DateTime.Now;
            dynamic obj = ObjectHelper.NewInstance();

            CreateArticleResponse response = null;


            response = await(new CreateArticleRequest()
            {
                Article     = obj,
                Environment = TestConfiguration.Environment
            }).ExecuteAsync();

            Assert.IsNotNull(response);
            Assert.IsNotNull(response.Status);
            Assert.IsTrue(response.Status.IsSuccessful);
            Assert.IsNotNull(response.Article);
            Console.WriteLine("Created article id {0}", response.Article.Id);
            Console.WriteLine("Time taken {0} seconds", response.TimeTaken);
        }
Ejemplo n.º 6
0
        public async Task CreateArticleCommandTestAsync(string title,
                                                        string titleImagePath, string identityUserId, int categoryId, bool isPublic, CreateArticleResponse result)
        {
            CreateArticleCommand request = new CreateArticleCommand
            {
                Title          = title,
                TitleImagePath = titleImagePath,
                IdentityUserId = identityUserId,
                CategoryId     = categoryId,
                IsPublic       = isPublic,
            };
            CreateArticleCommandHandler handler = new CreateArticleCommandHandler(_createFixture.Context);
            var expectedResult = await handler.Handle(request, new CancellationToken());

            Assert.Equal(expectedResult.IsSuccessful, result.IsSuccessful);
            if (expectedResult.IsSuccessful)
            {
                Article article = await _createFixture.Context.Articles
                                  .Include(a => a.TitleImage)
                                  .Include(a => a.Creator)
                                  .Where(a => a.Id == expectedResult.ArticleId).SingleOrDefaultAsync();

                Assert.NotNull(article);
                Assert.Equal(article.Title, title);
                Assert.Equal(article.TitleImage.Path, titleImagePath);
                Assert.Equal(article.Creator.IdentityUserId, identityUserId);
                Assert.Equal(article.CategoryId, categoryId);
                Assert.Equal(article.IsPublic, isPublic);
            }
            Assert.Equal(expectedResult.Message, result.Message);
        }