@@ -91,38 +91,26 @@ class TransactionTest : public FirestoreIntegrationTest {
91
91
}
92
92
};
93
93
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
94
TEST_F (TransactionTest, TestGetNonexistentDocumentThenCreatePortableVersion) {
117
95
DocumentReference doc = TestFirestore ()->Collection (" towns" ).Document ();
118
- TestTransactionFunction transaction{doc};
119
- Future<void > future = TestFirestore ()->RunTransaction (&transaction);
96
+ std::string key = " foo" ;
97
+ std::string value = " bar" ;
98
+ Future<void > future = TestFirestore ()->RunTransaction (
99
+ [this , doc, key, value](Transaction& transaction,
100
+ std::string& error_message) {
101
+ Error error = Error::kErrorUnknown ;
102
+ DocumentSnapshot snapshot =
103
+ transaction.Get (doc, &error, &error_message);
104
+ EXPECT_EQ (Error::kErrorOk , error);
105
+ EXPECT_FALSE (snapshot.exists ());
106
+ transaction.Set (doc, MapFieldValue{{key, FieldValue::String (value)}});
107
+ return error;
108
+ });
120
109
Await (future);
121
110
122
111
EXPECT_EQ (Error::kErrorOk , future.error ());
123
112
DocumentSnapshot snapshot = ReadDocument (doc);
124
- EXPECT_EQ (FieldValue::String (transaction.value ()),
125
- snapshot.Get (transaction.key ()));
113
+ EXPECT_EQ (FieldValue::String (value), snapshot.Get (key));
126
114
}
127
115
128
116
class TransactionStage {
0 commit comments