Beispiel #1
0
        public void CreateAndFetchObjects()
        {
            IEnumerable <BasicObject> paramObjs = Faker.RandomCollection(() => new BasicObject());

            BasicTestDb db = new BasicTestDb();

            // Create DB objects
            db.InsertAll(paramObjs);

            // Fetch created objects without Id
            IEnumerable <BasicObject> fetchedObjs =
                db.Table <BasicObject>()
                .SelectColumns(new[] { nameof(BasicObject.Idx), nameof(BasicObject.Value) });

            paramObjs.ShouldAllBeEquivalentTo(
                fetchedObjs, config => config.Excluding(ctx => ctx.SelectedMemberPath.EndsWith(".Id")));

            fetchedObjs.Should().OnlyContain(bo => bo.Id == 0);


            // Fetch created objects with Id
            fetchedObjs = db.Table <BasicObject>();

            fetchedObjs.Should().OnlyContain(bo => bo.Id != 0 && bo.Id <= paramObjs.Count());
        }
Beispiel #2
0
        public async void AsyncOperations()
        {
            const int Count = 500;

            BasicTestDb         db    = new BasicTestDb();
            List <Task <bool> > tasks = new List <Task <bool> >();

            await
            Task.Run(
                () => db.InsertAll(Faker.RandomCollection(() => new BasicObject(), Count, Count)))
            .ConfigureAwait(true);

            for (int i = 0; i < 20; i++)
            {
                tasks.Add(
                    Task.Run(
                        () =>
                {
                    using (db.Lock())
                        return(db.Table <BasicObject>().ToList().Count == Count);
                }));
            }

            await Task.WhenAll(tasks.ToArray()).ConfigureAwait(true);

            tasks.Should().OnlyContain(f => f.Result);
        }
Beispiel #3
0
        public void SelectExpr()
        {
            const int Count = 500;

            BasicTestDb db = new BasicTestDb();

            var paramObjs = Faker.RandomCollection(() => new BasicObject(), Count, Count);

            // Create DB objects
            db.InsertAll(paramObjs);

            IEnumerable <BasicObject> fetchedObjs;

            // Fetch created objects
            using (db.Lock())
                fetchedObjs =
                    db.Table <BasicObject>()
                    .Where(bo => paramObjs.Select(po => po.Idx).Contains(bo.Idx))
                    .ToList();

            fetchedObjs.Count().Should().Be(paramObjs.Count());
        }