Beispiel #1
0
        public async Task RemovesNpgSqlComposite()
        {
            var toDelete = NpgSqlCompositeIds.Take(5).ToList();

            using (var db = new postgresContext())
            {
                var entities = await db.Efcoretestchild
                               .Join(toDelete)
                               .ToListAsync();

                Assert.NotEmpty(entities);
            }

            using (var db = new postgresContext())
            {
                var result = await db.Efcoretestchild
                             .Where(e => e.Name.Contains(nameof(BulkRemoveTests)))
                             .BulkRemoveAsync(toDelete);

                Assert.Equal(5, result);
            }

            using (var db = new postgresContext())
            {
                var entities = await db.Efcoretestchild
                               .Join(toDelete)
                               .ToListAsync();

                Assert.Empty(entities);
            }
        }
Beispiel #2
0
        public async Task JoinsByCompositeNpgSql()
        {
            var expectedIds = NpgSqlCompositeIds.Take(5).ToList();

            List <object[]> actualIds;

            using (var db = new postgresContext())
            {
                actualIds = await db.Efcoretestchild
                            .Join(expectedIds)
                            .Select(e => new object[] { e.Id, e.Efcoretestid })
                            .ToListAsync();
            }

            Assert.Equal(expectedIds.Count, actualIds.Count);

            foreach (var expected in expectedIds)
            {
                Assert.Contains(expected, actualIds);
            }
        }
        public async Task UpdatesNpgSqlComposite()
        {
            var toUpdate = NpgSqlCompositeIds.Take(2)
                           .ToDictionary(key => key, value => DateTime.UtcNow.AddDays(3));

            using (var db = new postgresContext())
            {
                var result = await db.Efcoretestchild.BulkUpdateAsync(toUpdate.Select(x => x.Key), id => new Efcoretestchild
                {
                    Modifieddate = toUpdate[id]
                });

                Assert.Equal(toUpdate.Count, result);
            }

            using (var db = new postgresContext())
            {
                var updated = await db.Efcoretestchild
                              .Join(toUpdate.Select(y => y.Key))
                              .ToListAsync();

                Assert.Equal(toUpdate.Count, updated.Count);

                foreach (var u in updated)
                {
                    var keyExists = toUpdate.Keys.Any(k => Enumerable.SequenceEqual(new object[] { u.Id, u.Efcoretestid }, k));

                    Assert.True(keyExists);

                    var expected = toUpdate.First(x => Enumerable.SequenceEqual(new object[] { u.Id, u.Efcoretestid }, x.Key)).Value;
                    var actual   = u.Modifieddate;

                    Assert.Equal(expected.ToString("d"), actual.ToString("d"));
                }
            }
        }