Example #1
0
        public async Task Should_delete_single_item()
        {
            var elements = new List <TestEntityWithCompositePk>
            {
                new TestEntityWithCompositePk {
                    UserId = 1, Column2 = "value-2"
                }
            };

            await using var connection = new NpgsqlConnection(_configuration.ConnectionString);
            await _testService.InsertAsync(connection, elements, CancellationToken.None);

            await _testService.DeleteAsync(connection, elements, CancellationToken.None);

            var countOfRows = await _testUtils.HowManyRowsInTableAsync(_entityProfile);

            Assert.AreEqual(0, countOfRows);
        }
Example #2
0
        public async Task SimpleDelete_should_update_autogenerated_fields()
        {
            var elements = new List <TestEntity>
            {
                new TestEntity {
                    RecordId = "rec-01", SensorId = "sens-01", Value = 127
                },
                new TestEntity {
                    RecordId = "rec-02", SensorId = "sens-01", Value = 128
                }
            };

            await using var connection = new NpgsqlConnection(_configuration.ConnectionString);
            await _testService.InsertAsync(connection, elements, CancellationToken.None);

            await _testService.DeleteAsync(connection, elements, CancellationToken.None);

            var countOfRows = await _testUtils.HowManyRowsWithIdsAsync(_entityProfile, new[] { elements[0].Id, elements[1].Id });

            Assert.AreEqual(0, countOfRows);
        }
Example #3
0
        public async Task SimpleDelete_should_delete_elements_with_multiple_pk()
        {
            var bulkServiceOptions = new BulkServiceOptions();
            var profile            = new EntityProfile(typeof(TestEntity));

            profile.HasProperty <TestEntity, int>(x => x.Id)
            .ThatIsPrivateKey()
            .ThatIsAutoGenerated();
            profile.HasProperty <TestEntity, string>(x => x.RecordId)
            .ThatIsPrivateKey();
            profile.HasProperty <TestEntity, int>(x => x.Value);
            profile.ToTable("simple_test_entity", "unit_tests");
            bulkServiceOptions.AddEntityProfile <TestEntity>(profile);

            var insertCommandBuilder = new InsertSqlCommandBuilder(NullLoggerFactory.Instance);
            var updateCommandBuilder = new Mock <IUpdateSqlCommandBuilder>().Object;
            var deleteCommandBuilder = new SimpleDeleteSqlCommandBuilder(NullLoggerFactory.Instance);
            var upsertCommandBuilder = new Mock <IUpsertSqlCommandBuilder>().Object;

            _testService = new NpgsqlCommandsBulkService(
                bulkServiceOptions,
                NullLoggerFactory.Instance,
                insertCommandBuilder,
                updateCommandBuilder,
                deleteCommandBuilder,
                upsertCommandBuilder);

            var elements = new List <TestEntity>
            {
                new TestEntity {
                    RecordId = "rec-01", SensorId = "sens-01", Value = 127
                },
                new TestEntity {
                    RecordId = "rec-02", SensorId = "sens-01", Value = 128
                },
                new TestEntity {
                    RecordId = "rec-01", SensorId = "sens-02", Value = 227
                },
            };

            await using var connection = new NpgsqlConnection(_configuration.ConnectionString);
            await _testService.InsertAsync(connection, elements, CancellationToken.None);

            await _testService.DeleteAsync(connection, elements, CancellationToken.None);

            var countOfRows = await _testUtils.HowManyRowsWithIdsAsync(_entityProfile, new[] { elements[0].Id, elements[1].Id, elements[2].Id });

            Assert.AreEqual(0, countOfRows);
        }
Example #4
0
        public async Task Should_delete_elements_with_multiple_pk()
        {
            var bulkServiceOptions = new BulkServiceOptions();
            var profile            = new EntityProfile(typeof(TestEntity));

            profile.HasProperty <TestEntity, int>(x => x.Id)
            .ThatIsPrivateKey()
            .ThatIsAutoGenerated();
            profile.HasProperty <TestEntity, string>(x => x.RecordId)
            .ThatIsPrivateKey();
            profile.HasProperty <TestEntity, int>(x => x.Value);
            profile.ToTable("simple_test_entity", "unit_tests");
            bulkServiceOptions.AddEntityProfile <TestEntity>(profile);

            var insertCommandBuilder = new InsertSqlCommandBuilder(NullLoggerFactory.Instance);
            var updateCommandBuilder = new Mock <IUpdateSqlCommandBuilder>().Object;
            var deleteCommandBuilder = new WhereInDeleteSqlCommandBuilder(NullLogger <WhereInDeleteSqlCommandBuilder> .Instance);
            var upsertCommandBuilder = new Mock <IUpsertSqlCommandBuilder>().Object;

            _testService = new NpgsqlCommandsBulkService(
                bulkServiceOptions,
                NullLoggerFactory.Instance,
                insertCommandBuilder,
                updateCommandBuilder,
                deleteCommandBuilder,
                upsertCommandBuilder);

            var elements = new List <TestEntity>
            {
                new TestEntity {
                    RecordId = "rec-01", SensorId = "sens-01", Value = 127
                },
                new TestEntity {
                    RecordId = "rec-02", SensorId = "sens-01", Value = 128
                },
                new TestEntity {
                    RecordId = "rec-01", SensorId = "sens-02", Value = 227
                },
            };

            await using var connection = new NpgsqlConnection(_configuration.ConnectionString);
            var ex = Assert.ThrowsAsync <SqlBulkExecutionException <TestEntity> >(() => _testService.DeleteAsync(connection, elements, CancellationToken.None));

            Assert.IsTrue(ex.InnerException is ArgumentException);
        }