public async Task PostContent_Valid_Returns201CreatedAsync()
        {
            var filters = new Models.ContentOptionFilter
            {
                ContentId = 1,
            };
            var saveContent = new SaveContent()
            {
                PageId = 1,
                BookId = 1,
                Value  = "x",
            };
            var content = new Models.Content()
            {
                ContentId = 1
            };

            this.ContentRepositoryMock
            .Setup(x => x.AddAsync(It.IsAny <Models.Content>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(content);

            var response = await this.client.PostAsJsonAsync("content", saveContent).ConfigureAwait(false);

            Assert.Equal(HttpStatusCode.Created, response.StatusCode);
            Assert.Equal(ContentType.RestfulJson, response.Content.Headers.ContentType?.MediaType);
            var contentViewModel = await response.Content.ReadAsAsync <Content>(this.formatters).ConfigureAwait(false);

            var uriString = AddQueryString("/content", filters);

            Assert.Equal(new Uri($"http://localhost{uriString}"), response.Headers.Location);
        }
        public async Task PutContent_Valid_Returns200OkAsync()
        {
            var filters = new Models.ContentOptionFilter
            {
                ContentId = 1,
            };
            var saveContent = new SaveContent()
            {
                PageId = 1,
                BookId = 1,
                Value  = "x",
            };
            var content = new List <Models.Content> {
                new Models.Content()
                {
                    ContentId = 1
                }
            };

            this.ContentRepositoryMock
            .Setup(x => x.GetAsync(It.IsAny <Models.ContentOptionFilter>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(content);
            this.ContentRepositoryMock.Setup(x => x.UpdateAsync(content.First(), It.IsAny <CancellationToken>())).ReturnsAsync(content.First());

            var response = await this.client.PutAsJsonAsync("content/1", saveContent).ConfigureAwait(false);

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            Assert.Equal(ContentType.RestfulJson, response.Content.Headers.ContentType?.MediaType);
            var contentViewModel = await response.Content.ReadAsAsync <Content>(this.formatters).ConfigureAwait(false);

            Assert.Equal(contentViewModel.ContentId, content.First().ContentId);
        }
Beispiel #3
0
 public SaveManager()
 {
     if (Application.isPlaying)
     {
         GameObject GD = GameObject.Find("GameData");
         gameData = GD.GetComponent <GameData>();
         save     = new SaveContent();
     }
     instance = this;
 }
        /// <summary>
        /// Execute async.
        /// </summary>
        /// <param name="saveContent">The save content.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>An action result.</returns>
        public async Task <IActionResult> ExecuteAsync(SaveContent saveContent, CancellationToken cancellationToken)
        {
            var content = this.saveContentToContentMapper.Map(saveContent);

            content = await this.contentRepository.AddAsync(content, cancellationToken).ConfigureAwait(false);

            var contentViewModel = this.contentToContentMapper.Map(content);

            var filters = new Models.ContentOptionFilter {
                ContentId = contentViewModel.ContentId
            };

            return(new CreatedAtRouteResult(
                       ContentControllerRoute.GetContent,
                       filters,
                       contentViewModel));
        }
Beispiel #5
0
        protected override int Execute()
        {
            ILogger logger = GetLogger();
            CTable  t      = XmlToCTable();

            INoSqlContext ctx = GetNoSqlContextWithAuthen("FirebaseNoSqlContext");

            FactoryBusinessOperation.SetNoSqlContext(ctx);

            SaveContent opr = (SaveContent)FactoryBusinessOperation.CreateBusinessOperationObject("SaveContent");

            try
            {
                ArrayList types = t.GetChildArray("Contents");
                foreach (CTable pt in types)
                {
                    MContent mc = new MContent();
                    mc.Name          = pt.GetFieldValue("Name");
                    mc.Type          = pt.GetFieldValue("Type");
                    mc.LastMaintDate = DateTime.Now;
                    ArrayList values = pt.GetChildArray("Values");

                    foreach (CTable value in values)
                    {
                        mc.Values = new Dictionary <string, string>();
                        foreach (CField field in value.GetTableFields())
                        {
                            mc.Values[field.GetName()] = field.GetValue();
                        }
                        LogUtils.LogInformation(logger, "Adding content : [{0}][{1}]", mc.Type, mc.Name);
                    }

                    opr.Apply(mc);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Error : {0}", e);
            }

            return(0);
        }
Beispiel #6
0
        /// <summary>
        /// Execute async.
        /// </summary>
        /// <param name="contentId">The content id.</param>
        /// <param name="saveContent">The save content.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>A action result.</returns>
        public async Task <IActionResult> ExecuteAsync(long contentId, SaveContent saveContent, CancellationToken cancellationToken)
        {
            var filters = new Models.ContentOptionFilter {
                ContentId = contentId
            };
            var content = await this.contentRepository.GetAsync(filters, cancellationToken).ConfigureAwait(false);

            if (content is null || !content.Any())
            {
                return(new NotFoundResult());
            }

            var item = content.First();

            this.saveContentToContentMapper.Map(saveContent, item);
            item = await this.contentRepository.UpdateAsync(item, cancellationToken).ConfigureAwait(false);

            var contentViewModel = this.contentToContentMapper.Map(item);

            return(new OkObjectResult(contentViewModel));
        }
        public async Task PutContent_ContentNotFound_Returns404NotFoundAsync()
        {
            var filters = new Models.ContentOptionFilter
            {
                ContentId = 999,
            };
            var saveContent = new SaveContent()
            {
                PageId = 1,
                BookId = 1,
                Value  = "x",
            };
            var content = new List <Models.Content>();

            this.ContentRepositoryMock.Setup(x => x.GetAsync(It.IsAny <Models.ContentOptionFilter>(), It.IsAny <CancellationToken>())).ReturnsAsync(content);

            var response = await this.client.PutAsJsonAsync("content/999", saveContent).ConfigureAwait(false);

            Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
            var problemDetails = await response.Content.ReadAsAsync <ProblemDetails>(this.formatters).ConfigureAwait(false);

            Assert.Equal(StatusCodes.Status404NotFound, problemDetails.Status);
        }
        // 无头浏览器测试,封装版
        private void btn_chromiumTest_Encapsulated_Click(object sender, EventArgs e)
        {
            this.Invoke(new Action(() =>
            {
                this.btn_chromiumTest_Encapsulated.Enabled = false;
            }));

            Task.Run(async() =>
            {
                LaunchOptions launchOptions = await ChromiumBrowser.ChromiumLaunchOptions(true, true);
                using (Browser browser = await Puppeteer.LaunchAsync(launchOptions))
                {
                    using (Page page = await ChromiumBrowser.NewPageAndInitAsync(browser))
                    {
                        // 导航到 url 页
                        await page.GoToAsync(_testUrl);

                        string fileName = DateTime.Now.ToString("yyyy-MM-dd_HH.mm.ss");
                        // 保存截图 1
                        await ChromiumBrowser.SavePageScreenshotAsync(page, true, $"{SaveContent.SaveContentDirectory}{fileName}-1.png");
                        // 保存截图 2
                        await ChromiumBrowser.SavePageScreenshotAsync(page, null, $"{SaveContent.SaveContentDirectory}{fileName}-2.png");

                        // 获取并保存页面的 Html 内容
                        string htmlContent = await page.GetContentAsync();
                        SaveContent.SaveContentByCreate(htmlContent, $"{SaveContent.SaveContentDirectory}{fileName}.html");
                    }
                }
            }).ContinueWith(t =>
            {
                this.Invoke(new Action(() =>
                {
                    this.btn_chromiumTest_Encapsulated.Enabled = true;
                }));
            });
        }
 public Task <IActionResult> PutAsync(
     [FromServices] PutContentCommand command,
     long contentId,
     [FromBody] SaveContent content,
     CancellationToken cancellationToken) => command.ExecuteAsync(contentId, content, cancellationToken);