@@ -31,12 +31,6 @@ namespace firestore {
3131
3232using ::testing::HasSubstr;
3333
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-
4034class TransactionTest : public FirestoreIntegrationTest {
4135 protected:
4236 // We occasionally get transient error like "Could not reach Cloud Firestore
@@ -91,38 +85,25 @@ class TransactionTest : public FirestoreIntegrationTest {
9185 }
9286};
9387
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) {
11789 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+ });
120102 Await (future);
121103
122104 EXPECT_EQ (Error::kErrorOk , future.error ());
123105 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));
126107}
127108
128109class TransactionStage {
0 commit comments