From d3160f6e6c18b364bc8aa764c7e7c60ddcffca20 Mon Sep 17 00:00:00 2001 From: Markus Richter <8398165+mqus@users.noreply.github.com> Date: Wed, 27 May 2020 23:50:31 +0200 Subject: [PATCH 1/2] add integration test for transaction rollback --- floor/test/integration/database_test.dart | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/floor/test/integration/database_test.dart b/floor/test/integration/database_test.dart index b7f017d2..b6a35adf 100644 --- a/floor/test/integration/database_test.dart +++ b/floor/test/integration/database_test.dart @@ -1,3 +1,5 @@ +import 'dart:io'; + import 'package:floor/floor.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:matcher/matcher.dart'; @@ -129,6 +131,24 @@ void main() { expect(actual, equals(newPersons)); }); + test('transaction rollback on failure', () async { + final persons = [Person(1, 'Simon'), Person(2, 'Frank')]; + await personDao.insertPersons(persons); + + final newPersons = [Person(3, 'Paul'), Person(3, 'Karl')]; + + //should fail and trigger rollback because ids are the same + try { + await personDao.replacePersons(newPersons); + }catch (sfe) { + // the type SqfliteFfiException is not in scope, so we have to do it this way + expect(sfe.runtimeType.toString() ,equals('SqfliteFfiException')); + } + + final actual = await personDao.findAllPersons(); + expect(actual, equals(persons)); + }); + test('Reactivity is retained when using transactions', () async { final persons = [Person(1, 'Simon'), Person(2, 'Frank')]; await personDao.insertPersons(persons); From 55d886af63f9bc6fd00e1281eeb8df37458cc72f Mon Sep 17 00:00:00 2001 From: Markus Richter <8398165+mqus@users.noreply.github.com> Date: Thu, 28 May 2020 00:04:41 +0200 Subject: [PATCH 2/2] fix formatting and lint issues --- floor/test/integration/database_test.dart | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/floor/test/integration/database_test.dart b/floor/test/integration/database_test.dart index b6a35adf..420a7a25 100644 --- a/floor/test/integration/database_test.dart +++ b/floor/test/integration/database_test.dart @@ -1,5 +1,3 @@ -import 'dart:io'; - import 'package:floor/floor.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:matcher/matcher.dart'; @@ -140,9 +138,9 @@ void main() { //should fail and trigger rollback because ids are the same try { await personDao.replacePersons(newPersons); - }catch (sfe) { + } catch (sfe) { // the type SqfliteFfiException is not in scope, so we have to do it this way - expect(sfe.runtimeType.toString() ,equals('SqfliteFfiException')); + expect(sfe.runtimeType.toString(), equals('SqfliteFfiException')); } final actual = await personDao.findAllPersons();