@@ -31,12 +31,6 @@ namespace firestore {
31
31
32
32
using ::testing::HasSubstr;
33
33
34
- // We will be using lambda in the test instead of defining a
35
- // TransactionFunction for each of the test case.
36
- //
37
- // We do have a TransactionFunction-version of the test
38
- // TestGetNonexistentDocumentThenCreate to test the non-lambda API.
39
-
40
34
class TransactionTest : public FirestoreIntegrationTest {
41
35
protected:
42
36
// We occasionally get transient error like "Could not reach Cloud Firestore
@@ -91,38 +85,25 @@ class TransactionTest : public FirestoreIntegrationTest {
91
85
}
92
86
};
93
87
94
- class TestTransactionFunction : public TransactionFunction {
95
- public:
96
- TestTransactionFunction (DocumentReference doc) : doc_(doc) {}
97
-
98
- Error Apply (Transaction& transaction, std::string& error_message) override {
99
- Error error = Error::kErrorUnknown ;
100
- DocumentSnapshot snapshot = transaction.Get (doc_, &error, &error_message);
101
- EXPECT_EQ (Error::kErrorOk , error);
102
- EXPECT_FALSE (snapshot.exists ());
103
- transaction.Set (doc_, MapFieldValue{{key_, FieldValue::String (value_)}});
104
- return error;
105
- }
106
-
107
- std::string key () { return key_; }
108
- std::string value () { return value_; }
109
-
110
- private:
111
- DocumentReference doc_;
112
- const std::string key_{" foo" };
113
- const std::string value_{" bar" };
114
- };
115
-
116
- TEST_F (TransactionTest, TestGetNonexistentDocumentThenCreatePortableVersion) {
88
+ TEST_F (TransactionTest, TestGetNonexistentDocumentThenCreate) {
117
89
DocumentReference doc = TestFirestore ()->Collection (" towns" ).Document ();
118
- TestTransactionFunction transaction{doc};
119
- Future<void > future = TestFirestore ()->RunTransaction (&transaction);
90
+ std::string key = " foo" ;
91
+ std::string value = " bar" ;
92
+ Future<void > future = TestFirestore ()->RunTransaction (
93
+ [&](Transaction& transaction, std::string& error_message) {
94
+ Error error = Error::kErrorUnknown ;
95
+ DocumentSnapshot snapshot =
96
+ transaction.Get (doc, &error, &error_message);
97
+ EXPECT_EQ (Error::kErrorOk , error);
98
+ EXPECT_FALSE (snapshot.exists ());
99
+ transaction.Set (doc, MapFieldValue{{key, FieldValue::String (value)}});
100
+ return error;
101
+ });
120
102
Await (future);
121
103
122
104
EXPECT_EQ (Error::kErrorOk , future.error ());
123
105
DocumentSnapshot snapshot = ReadDocument (doc);
124
- EXPECT_EQ (FieldValue::String (transaction.value ()),
125
- snapshot.Get (transaction.key ()));
106
+ EXPECT_EQ (FieldValue::String (value), snapshot.Get (key));
126
107
}
127
108
128
109
class TransactionStage {
0 commit comments