public async Task OperationCanceledException_is_not_wrapped_with_DbUpdateException(bool async)
        {
            var entry = CreateEntry(EntityState.Added, generateKeyValues: true);

            var command = CreateModificationCommand("T1", null, new ParameterNameGenerator().GenerateNext, true, null);

            command.AddEntry(entry, true);

            var originalException = new OperationCanceledException();

            var connection = CreateConnection(
                new FakeCommandExecutor(
                    executeReaderAsync: (c, b, ct) => throw originalException,
                    executeReader: (c, b) => throw originalException));

            var batch = new ModificationCommandBatchFake();

            batch.AddCommand(command);

            var actualException = async
                ? await Assert.ThrowsAsync <OperationCanceledException>(() => batch.ExecuteAsync(connection))
                : Assert.Throws <OperationCanceledException>(() => batch.Execute(connection));

            Assert.Same(originalException, actualException);
        }
Esempio n. 2
0
    public async Task Exception_thrown_if_rows_returned_for_command_without_store_generated_values_is_not_1(bool async)
    {
        var entry = CreateEntry(EntityState.Modified);

        var command = CreateModificationCommand("T1", null, new ParameterNameGenerator().GenerateNext, true, null);

        command.AddEntry(entry, true);

        var connection = CreateConnection(
            CreateFakeDataReader(
                new[] { "Col1" }, new List <object[]> {
            new object[] { 42 }
        }));

        var batch = new ModificationCommandBatchFake();

        batch.TryAddCommand(command);
        batch.Complete();

        var exception = async
            ? await Assert.ThrowsAsync <DbUpdateConcurrencyException>(() => batch.ExecuteAsync(connection))
            : Assert.Throws <DbUpdateConcurrencyException>(() => batch.Execute(connection));

        Assert.Equal(RelationalStrings.UpdateConcurrencyException(1, 42), exception.Message);
    }
        public async Task Exception_thrown_if_no_rows_returned_for_command_with_store_generated_values(bool async)
        {
            var entry = CreateEntry(EntityState.Added, generateKeyValues: true);

            entry.SetTemporaryValue(entry.EntityType.FindPrimaryKey().Properties[0], -1);

            var command = CreateModificationCommand("T1", null, new ParameterNameGenerator().GenerateNext, true, null);

            command.AddEntry(entry, true);

            var connection = CreateConnection(
                CreateFakeDataReader(new[] { "Col1" }, new List <object[]>()));

            var batch = new ModificationCommandBatchFake();

            batch.AddCommand(command);

            var exception = async
                ? await Assert.ThrowsAsync <DbUpdateConcurrencyException>(() => batch.ExecuteAsync(connection))
                : Assert.Throws <DbUpdateConcurrencyException>(() => batch.Execute(connection));

            Assert.Equal(RelationalStrings.UpdateConcurrencyException(1, 0), exception.Message);
        }