Example #1
0
        public async Task GetCrawlerMeta_ShouldWorkCorrectly()
        {
            // arrange
            using var httpTest = new HttpTest();

            httpTest.RespondWithJson(new
            {
                error = false,
                data  = new
                {
                    uva = new
                    {
                        title       = "UVA",
                        description = "u description",
                        url         = "http",
                    },
                    vjudge = new
                    {
                        title         = "VJudge",
                        description   = "v description",
                        url           = "https",
                        virtual_judge = true,
                    },
                },
            });

            // act
            var result = await _crawlerApiBackendClient.GetCrawlerMeta();

            // assert
            httpTest.ShouldHaveCalled("http://crawler-api-backend/api/crawlers/")
            .WithVerb(HttpMethod.Get)
            .Times(1);

            result.Should().BeEquivalentTo(new[]
            {
                new CrawlerMetaItem
                {
                    CrawlerName        = "uva",
                    CrawlerTitle       = "UVA",
                    CrawlerDescription = "u description",
                    Url            = "http",
                    IsVirtualJudge = false,
                },
                new CrawlerMetaItem
                {
                    CrawlerName        = "vjudge",
                    CrawlerTitle       = "VJudge",
                    CrawlerDescription = "v description",
                    Url            = "https",
                    IsVirtualJudge = true,
                },
            });
        }
Example #2
0
        /// <inheritdoc cref="IQueryHistoryAppService.SaveOrReplaceQueryHistory"/>
        public async Task <SaveOrReplaceQueryHistoryOutput> SaveOrReplaceQueryHistory(
            SaveOrReplaceQueryHistoryInput input)
        {
            // 添加新记录
            var acHistory = ObjectMapper.Map <QueryHistory>(input);

            // AutoMapper will change empty array to null. The code below is used to restore them
            foreach (var(entity, dto) in acHistory.QueryWorkerHistories.Zip(input.QueryWorkerHistories))
            {
                if (dto.SolvedList == null)
                {
                    entity.SolvedList = null;
                }

                if (dto.SubmissionsByCrawlerName == null)
                {
                    entity.SubmissionsByCrawlerName = null;
                }
            }

            Debug.Assert(AbpSession.UserId != null, "AbpSession.UserId != null");
            acHistory.UserId           = AbpSession.UserId.Value;
            acHistory.CreationTime     = _clockProvider.Now;
            acHistory.IsReliableSource = false;

            var crawlerMeta = await _crawlerApiBackendClient.GetCrawlerMeta();

            var querySummary = _summaryGenerator.Generate(
                crawlerMeta,
                acHistory.QueryWorkerHistories.AsReadOnly());

            await RemoveLatestHistoryTheSameDayOf(acHistory.CreationTime);

            var historyId = await _acHistoryRepository.InsertAndGetIdAsync(acHistory);

            querySummary.QueryHistoryId = historyId;
            await _querySummaryRepository.InsertAsync(querySummary);

            return(new SaveOrReplaceQueryHistoryOutput
            {
                QueryHistoryId = historyId,
            });
        }