Exemplo n.º 1
0
        public async Task FlowDeleteById()
        {
            var factory = new OrmLiteConnectionFactory(":memory:", SqliteDialect.Provider);

            var db = await factory.OpenDbConnectionAsync();

            db.CreateTable <Person>();
            db.Save(new Person()
            {
                Name = "Mario"
            });

            var flow = new FlowBuilder()
                       .Add(
                DataFlowElementBuilder.New()
                .SetConnection(db)
                .Delete <Person>()
                .DeleteById(i => i)
                .Build()
                ).Build();

            await flow.RunAsync(1);

            var persons = await db.SelectAsync <Person>();

            persons.Should().BeEmpty();
        }
Exemplo n.º 2
0
        public async Task ExecuteQueryTaskOnEmptyResultReturnError()
        {
            var factory = new OrmLiteConnectionFactory(":memory:", SqliteDialect.Provider);

            var db = await factory.OpenDbConnectionAsync();

            db.CreateTable <Person>();

            var pipeline = new FlowBuilder()
                           .Add(
                DataFlowElementBuilder.New()
                .SetConnection(db)
                .Read <Person>()
                .Query(args => args.Expression.Where(p => p.Id == (int)args.PipeArgs))
                .OnEmptyOrNullRaiseError()
                .List()
                .Build()
                ).Build();

            var result = await pipeline.RunAsync(2);

            result.Should()
            .BeOfType <FlowErrorResult>()
            .Which.ErrorObject.Should().Be("no results found");
        }
Exemplo n.º 3
0
        public async Task ExecuteCustomDbStep(int id)
        {
            var factory = new OrmLiteConnectionFactory(":memory:", SqliteDialect.Provider);

            var db = await factory.OpenDbConnectionAsync();

            db.CreateTable <Person>();
            db.Save(new Person
            {
                Name = "Mario"
            });

            db.Save(new Person
            {
                Name = "Princess"
            });

            db.Save(new Person
            {
                Name = "Luigi"
            });

            var pipeline = new FlowBuilder()
                           .Add(
                DataFlowElementBuilder.New()
                .SetConnection(db)
                .Custom()
                .CanExecuteContinue()
                .OnExecute(async args => await args.Db.SingleAsync <Person>(p => p.Id == (int)args.args))
                .Build()
                ).Build();

            var result = await pipeline.RunAsync(id);

            result.Should()
            .BeOfType <FlowSuccessResult>()
            .Which.Result
            .Should()
            .BeOfType <Person>()
            .Which.Id
            .Should()
            .Be(id);
        }
Exemplo n.º 4
0
        public async Task ExecuteQueryTaskReturnOneResult()
        {
            var factory = new OrmLiteConnectionFactory(":memory:", SqliteDialect.Provider);

            var db = await factory.OpenDbConnectionAsync();

            db.CreateTable <Person>();
            db.Save(new Person()
            {
                Name = "Mario"
            });

            db.Save(new Person()
            {
                Name = "Princess"
            });

            db.Save(new Person()
            {
                Name = "Luigi"
            });

            var pipeline = new FlowBuilder()
                           .Add(
                DataFlowElementBuilder.New()
                .SetConnection(db)
                .Read <Person>()
                .Query(args => args.Expression.Where(p => p.Id == (int)args.PipeArgs))
                .List()
                .Build()
                ).Build();

            var result = await pipeline.RunAsync(2);

            result.Should()
            .BeOfType <FlowSuccessResult>();
            result.Result.Should()
            .BeOfType <List <Person> >()
            .Which.Single()
            .Id.Should().Be(2);
        }
Exemplo n.º 5
0
        public async Task FlowDeleteByExpression()
        {
            var factory = new OrmLiteConnectionFactory(":memory:", SqliteDialect.Provider);

            var db = await factory.OpenDbConnectionAsync();

            db.CreateTable <Person>();
            await db.SaveAsync(new Person()
            {
                Name = "Mario"
            });

            await db.SaveAsync(new Person()
            {
                Name = "Luigi"
            });

            await db.SaveAsync(new Person()
            {
                Name = "Highlander"
            });

            var flow = new FlowBuilder()
                       .Add(
                DataFlowElementBuilder.New()
                .SetConnection(db)
                .Delete <Person>()
                .DeleteBy(ints => person => ((int[])ints).Contains(person.Id))
                .Build()
                ).Build();

            await flow.RunAsync(new[] { 1, 2 });

            var persons = await db.SelectAsync <Person>();

            persons
            .Single()
            .Id
            .Should()
            .Be(3);
        }