FSTMockDatastore.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Copyright 2017 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import <Foundation/Foundation.h>
  17. #import "Firestore/Source/Remote/FSTDatastore.h"
  18. #include "Firestore/core/src/firebase/firestore/model/snapshot_version.h"
  19. #include "Firestore/core/src/firebase/firestore/model/types.h"
  20. NS_ASSUME_NONNULL_BEGIN
  21. @interface FSTMockDatastore : FSTDatastore
  22. /**
  23. * A count of the total number of requests sent to the watch stream since the beginning of the test
  24. * case.
  25. */
  26. @property(nonatomic) int watchStreamRequestCount;
  27. /**
  28. * A count of the total number of requests sent to the write stream since the beginning of the test
  29. * case.
  30. */
  31. @property(nonatomic) int writeStreamRequestCount;
  32. #pragma mark - Watch Stream manipulation.
  33. /** Injects a WatchChange as though it had come from the backend. */
  34. - (void)writeWatchChange:(FSTWatchChange *)change
  35. snapshotVersion:(const firebase::firestore::model::SnapshotVersion &)snap;
  36. /** Injects a stream failure as though it had come from the backend. */
  37. - (void)failWatchStreamWithError:(NSError *)error;
  38. /** Returns the set of active targets on the watch stream. */
  39. - (NSDictionary<FSTBoxedTargetID *, FSTQueryData *> *)activeTargets;
  40. /** Helper method to expose watch stream state to verify in tests. */
  41. - (BOOL)isWatchStreamOpen;
  42. #pragma mark - Write Stream manipulation.
  43. /**
  44. * Returns the next write that was "sent to the backend", failing if there are no queued sent
  45. */
  46. - (NSArray<FSTMutation *> *)nextSentWrite;
  47. /** Returns the number of writes that have been sent to the backend but not waited on yet. */
  48. - (int)writesSent;
  49. /** Injects a write ack as though it had come from the backend in response to a write. */
  50. - (void)ackWriteWithVersion:(const firebase::firestore::model::SnapshotVersion &)commitVersion
  51. mutationResults:(NSArray<FSTMutationResult *> *)results;
  52. /** Injects a stream failure as though it had come from the backend. */
  53. - (void)failWriteWithError:(NSError *_Nullable)error;
  54. @end
  55. NS_ASSUME_NONNULL_END