コード例 #1
0
        public async Task Given_context_with_data_When_executing_query_with_filter_Then_it_returns_filtered_data()
        {
            var options = new DbContextOptionsBuilder <FunctionUsageContext>()
                          .UseInMemoryDatabase(nameof(Given_context_with_data_When_executing_query_with_filter_Then_it_returns_filtered_data)).Options;

            var context = new FunctionUsageContext(options);
            var query   = new FunctionsTotalUsageQuery(context);

            var functions = new[]
            {
                new FunctionTotalUsage {
                    FunctionName = "testFunc", InvocationsCount = 1
                },
                new FunctionTotalUsage {
                    FunctionName = "myFunc", InvocationsCount = 2
                }
            };

            context.FunctionsTotalUsage.AddRange(functions);
            await context.SaveChangesAsync();

            var res = await query.Execute("my");

            Assert.Equal(new [] { functions[1] }, res);
        }
コード例 #2
0
        public async Task Given_context_with_data_When_executing_query_with_filter_Then_it_returns_filtered_data()
        {
            var options = new DbContextOptionsBuilder <FunctionUsageContext>()
                          .UseInMemoryDatabase(nameof(FunctionUsageQueryTests) +
                                               nameof(
                                                   Given_context_with_data_When_executing_query_with_filter_Then_it_returns_filtered_data
                                                   )).Options;

            var context     = new FunctionUsageContext(options);
            var query       = new FunctionsUsageQuery(context);
            var periodStart = DateTimeOffset.Now;

            var functions = new[]
            {
                new FunctionUsage
                {
                    FunctionName     = "testFunc",
                    InvocationsCount = 1,
                    CalculatorName   = "calcA",
                    Period           = TimeSpan.FromMinutes(1),
                    PeriodStart      = periodStart,
                    PeriodEnd        = periodStart + TimeSpan.FromMinutes(1)
                },
                new FunctionUsage
                {
                    FunctionName     = "myFunc",
                    InvocationsCount = 2,
                    CalculatorName   = "calcB",
                    Period           = TimeSpan.FromHours(1),
                    PeriodStart      = periodStart,
                    PeriodEnd        = periodStart + TimeSpan.FromHours(1)
                },
                new FunctionUsage
                {
                    FunctionName     = "myFunc",
                    InvocationsCount = 2,
                    CalculatorName   = "calcB",
                    Period           = TimeSpan.FromHours(1),
                    PeriodStart      = periodStart - TimeSpan.FromHours(1),
                    PeriodEnd        = periodStart
                },
            };

            context.FunctionsUsage.AddRange(functions);
            await context.SaveChangesAsync();

            var res = await query.Execute("calcB", DateTimeOffset.Now - TimeSpan.FromHours(2), DateTimeOffset.Now);

            Assert.Equal(functions[2], res.Single());
        }
コード例 #3
0
        public async Task Given_context_with_data_When_executing_projection_query_Then_it_should_return_data()
        {
            var options = new DbContextOptionsBuilder <FunctionUsageContext>()
                          .UseInMemoryDatabase(nameof(Given_context_with_data_When_executing_projection_query_Then_it_should_return_data)).Options;

            var context = new FunctionUsageContext(options);
            var query   = new FindProjectionQuery(context);

            var projection = new Projection
            {
                Event = "testEvent", Name = "testName", Projector = "projector", Sequence = 10
            };

            context.Projections.Add(projection);
            await context.SaveChangesAsync();

            var res = query.Execute(projection.Name, projection.Projector, projection.Event);

            Assert.Equal(projection, res);
        }