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); }
public async Task Given_empty_context_When_executing_query_Then_it_should_return_nothing() { var options = new DbContextOptionsBuilder <FunctionUsageContext>() .UseInMemoryDatabase(nameof(Given_empty_context_When_executing_query_Then_it_should_return_nothing)).Options; var context = new FunctionUsageContext(options); var query = new FunctionsTotalUsageQuery(context); var res = await query.Execute(""); Assert.Empty(res); }
public async Task Given_existing_projection_When_projecting_Then_projection_is_updated_And_it_has_data() { var dependencies = Init(nameof(Given_existing_projection_When_projecting_Then_projection_is_updated_And_it_has_data)); var context = dependencies.CreateFunctionUsageContext(); var eventName = "testEvent"; context.Projections.Add(new Projection { Event = eventName, Name = KnownProjectionsNames.TotalFunctionUsage, Sequence = 11, Projector = nameof(FunctionsTotalUsageProjector) }); context.FunctionsTotalUsage.Add(new FunctionTotalUsage { FunctionName = "testFunction", InvocationsCount = 2 }); var actor = Sys.ActorOf(Props.Create <FunctionsTotalUsageProjector>(eventName)); actor.Tell(ProjectorActorProtocol.Start.Instance); ExpectMsg <ProjectorActorProtocol.Next>(); var usage = new SequencedFunctionTotalUsage { FunctionName = "testFunction", InvocationsCount = 10, Sequence = 200 }; actor.Tell(usage); ExpectMsg <ProjectorActorProtocol.Next>(); var query = dependencies.CreateFindProjectionQuery(); var projection = query.Execute(KnownProjectionsNames.TotalFunctionUsage, nameof(FunctionsTotalUsageProjector), eventName); //we have an existing projection Assert.Equal(usage.Sequence, projection.Sequence); //and it contains data var usageQuery = new FunctionsTotalUsageQuery(dependencies.CreateFunctionUsageContext()); var functionUsage = await usageQuery.Execute("test"); functionUsage.Should().BeEquivalentTo(new FunctionTotalUsage { InvocationsCount = usage.InvocationsCount, FunctionName = usage.FunctionName }); }