예제 #1
0
        private async void Preview()
        {
            using (var context = InMemoryDb.CreateDbContext())
            {
                context.Initialize();

                await CreateStatisticalUnitsAsync(context);

                var service = new SampleFramesService(context, null);

                await service.Create(
                    new SampleFrameM
                {
                    Name      = "Sample frame name",
                    Predicate = CreateExpressionGroup(),
                    Fields    = new[] { FieldEnum.RegId, FieldEnum.Name }
                },
                    (await context.Users.FirstAsync()).Id);

                Assert.Equal(1, await context.SampleFrames.CountAsync());

                var existing = await context.SampleFrames.FirstOrDefaultAsync();

                var units = await context.StatisticalUnits.ToListAsync();

                var expected = new[]
                {
                    new { RegId = units[0].RegId.ToString(), units[0].Name },
                    new { RegId = units[1].RegId.ToString(), units[1].Name }
                };
                var actual = (await service.Preview(existing.Id, (await context.Users.FirstAsync()).Id, 2)).ToArray();

                Assert.Equal(expected.Length, actual.Length);
                Assert.Equal(expected[0].RegId, actual[0][FieldEnum.RegId]);
                Assert.Equal(expected[1].Name, actual[1][FieldEnum.Name]);
            }
        }
예제 #2
0
 public async Task <IActionResult> Preview(int id) =>
 Ok(await _sampleFramesService.Preview(id, User.GetUserId(), 10));