@@ -164,7 +164,7 @@ protected override void Start() {
164
164
Func < Task > [ ] testFilter = {
165
165
// THIS LIST MUST BE EMPTY WHEN CHECKED INTO SOURCE CONTROL!
166
166
} ;
167
-
167
+
168
168
// Unity "helpfully" adds stack traces whenever you call Debug.Log. Unfortunately, these stack
169
169
// traces are basically useless, since the good parts are always truncated. (See comments on
170
170
// LogInBatches.) So just disable them.
@@ -191,6 +191,14 @@ protected override void Start() {
191
191
192
192
UIEnabled = false ;
193
193
base . Start ( ) ;
194
+
195
+ /*
196
+ * THIS MUST BE COMMENTED OUT WHEN CHECKED INTO SOURCE CONTROL!
197
+ *
198
+ * To run tests against Firestore emulator locally, set `USE_FIRESTORE_EMULATOR` to "true".
199
+ * To switch back to run against prod, set it back to null.
200
+ */
201
+ // Environment.SetEnvironmentVariable("USE_FIRESTORE_EMULATOR", "true");
194
202
}
195
203
196
204
// Passes along the update call to automated test runner.
@@ -747,7 +755,7 @@ Task TestMultiInstanceSnapshotsInSyncListeners() {
747
755
var app1 = db1 . App ;
748
756
749
757
var app2 = FirebaseApp . Create ( app1 . Options , "MultiInstanceSnapshotsInSyncTest" ) ;
750
- var db2 = FirebaseFirestore . GetInstance ( app2 ) ;
758
+ var db2 = TestFirestore ( app2 ) ;
751
759
var db2Doc = db2 . Collection ( db1Doc . Parent . Id ) . Document ( db1Doc . Id ) ;
752
760
753
761
var db1SyncAccumulator = new EventAccumulator < string > ( MainThreadId , FailTest ) ;
@@ -793,7 +801,7 @@ Task TestMultiInstanceDocumentReferenceListeners() {
793
801
var app1 = db1 . App ;
794
802
795
803
var app2 = FirebaseApp . Create ( app1 . Options , "MultiInstanceDocumentReferenceListenersTest" ) ;
796
- var db2 = FirebaseFirestore . GetInstance ( app2 ) ;
804
+ var db2 = TestFirestore ( app2 ) ;
797
805
var db2Doc = db2 . Collection ( db1Doc . Parent . Id ) . Document ( db1Doc . Id ) ;
798
806
799
807
var db1DocAccumulator = new EventAccumulator < DocumentSnapshot > ( MainThreadId , FailTest ) ;
@@ -827,7 +835,7 @@ Task TestMultiInstanceQueryListeners() {
827
835
var app1 = db1 . App ;
828
836
829
837
var app2 = FirebaseApp . Create ( app1 . Options , "MultiInstanceQueryListenersTest" ) ;
830
- var db2 = FirebaseFirestore . GetInstance ( app2 ) ;
838
+ var db2 = TestFirestore ( app2 ) ;
831
839
var db2Coll = db2 . Collection ( db1Coll . Id ) ;
832
840
833
841
var db1CollAccumulator = new EventAccumulator < QuerySnapshot > ( MainThreadId , FailTest ) ;
@@ -1308,7 +1316,7 @@ Task TestTransactionDispose() {
1308
1316
// Verify that the Transaction is disposed when the Firestore instance terminated.
1309
1317
{
1310
1318
FirebaseApp customApp = FirebaseApp . Create ( db . App . Options , "transaction-terminate" ) ;
1311
- FirebaseFirestore customDb = FirebaseFirestore . GetInstance ( customApp ) ;
1319
+ FirebaseFirestore customDb = TestFirestore ( customApp ) ;
1312
1320
DocumentReference doc = customDb . Document ( TestDocument ( ) . Path ) ;
1313
1321
var barrier = new BarrierCompat ( 2 ) ;
1314
1322
Transaction capturedTransaction = null ;
@@ -1343,7 +1351,7 @@ Task TestTransactionDispose() {
1343
1351
// Verify that the Transaction is disposed when the Firestore instance is disposed.
1344
1352
{
1345
1353
FirebaseApp customApp = FirebaseApp . Create ( db . App . Options , "transaction-dispose1" ) ;
1346
- FirebaseFirestore customDb = FirebaseFirestore . GetInstance ( customApp ) ;
1354
+ FirebaseFirestore customDb = TestFirestore ( customApp ) ;
1347
1355
DocumentReference doc = customDb . Document ( TestDocument ( ) . Path ) ;
1348
1356
var barrier = new BarrierCompat ( 2 ) ;
1349
1357
Transaction capturedTransaction = null ;
@@ -1375,7 +1383,7 @@ Task TestTransactionDispose() {
1375
1383
// directly from the transaction callback.
1376
1384
{
1377
1385
FirebaseApp customApp = FirebaseApp . Create ( db . App . Options , "transaction-dispose2" ) ;
1378
- FirebaseFirestore customDb = FirebaseFirestore . GetInstance ( customApp ) ;
1386
+ FirebaseFirestore customDb = TestFirestore ( customApp ) ;
1379
1387
DocumentReference doc = customDb . Document ( TestDocument ( ) . Path ) ;
1380
1388
var barrier = new BarrierCompat ( 2 ) ;
1381
1389
Transaction capturedTransaction = null ;
@@ -1402,7 +1410,7 @@ Task TestTransactionDispose() {
1402
1410
// from the task returned from the transaction callback.
1403
1411
{
1404
1412
FirebaseApp customApp = FirebaseApp . Create ( db . App . Options , "transaction-dispose3" ) ;
1405
- FirebaseFirestore customDb = FirebaseFirestore . GetInstance ( customApp ) ;
1413
+ FirebaseFirestore customDb = TestFirestore ( customApp ) ;
1406
1414
DocumentReference doc = customDb . Document ( TestDocument ( ) . Path ) ;
1407
1415
var barrier = new BarrierCompat ( 2 ) ;
1408
1416
Transaction capturedTransaction = null ;
@@ -1440,7 +1448,7 @@ Task TestTransactionsInParallel() {
1440
1448
}
1441
1449
FirebaseFirestore [ ] firestores = new FirebaseFirestore [ apps . Length ] ;
1442
1450
for ( int i = 0 ; i < firestores . Length ; i ++ ) {
1443
- firestores [ i ] = FirebaseFirestore . GetInstance ( apps [ i ] ) ;
1451
+ firestores [ i ] = TestFirestore ( apps [ i ] ) ;
1444
1452
}
1445
1453
1446
1454
int numTransactionsPerFirestore = 3 ;
@@ -2453,8 +2461,8 @@ Task TestInQueries() {
2453
2461
2454
2462
Task TestDefaultInstanceStable ( ) {
2455
2463
return Async ( ( ) => {
2456
- FirebaseFirestore db1 = FirebaseFirestore . DefaultInstance ;
2457
- FirebaseFirestore db2 = FirebaseFirestore . DefaultInstance ;
2464
+ FirebaseFirestore db1 = db ;
2465
+ FirebaseFirestore db2 = db ;
2458
2466
AssertEq ( "FirebaseFirestore.DefaultInstance's not stable" , db1 , db2 ) ;
2459
2467
} ) ;
2460
2468
}
@@ -2653,7 +2661,7 @@ Task TestTerminate() {
2653
2661
! docListenerInvoked ) ;
2654
2662
2655
2663
// Create a new functional instance.
2656
- var db2 = FirebaseFirestore . GetInstance ( app ) ;
2664
+ var db2 = TestFirestore ( app ) ;
2657
2665
Assert ( "Should create a new instance." , db1 != db2 ) ;
2658
2666
AssertTaskSucceeds ( db2 . DisableNetworkAsync ( ) ) ;
2659
2667
AssertTaskSucceeds ( db2 . EnableNetworkAsync ( ) ) ;
@@ -2679,7 +2687,7 @@ Task TestClearPersistence() {
2679
2687
// Create a document to use to verify the behavior of ClearPersistenceAsync().
2680
2688
{
2681
2689
var app = FirebaseApp . Create ( defaultOptions , "TestClearPersistenceApp" ) ;
2682
- var db = FirebaseFirestore . GetInstance ( app ) ;
2690
+ var db = TestFirestore ( app ) ;
2683
2691
var docContents = new Dictionary < string , object > { { "foo" , 42 } } ;
2684
2692
2685
2693
var doc = db . Collection ( "TestCollection" ) . Document ( ) ;
@@ -2839,12 +2847,12 @@ Task TestObjectMappingSmokeTest() {
2839
2847
// Verify Firestore instances are singletons.
2840
2848
Task TestFirestoreSingleton ( ) {
2841
2849
return Async ( ( ) => {
2842
- FirebaseFirestore db2 = FirebaseFirestore . DefaultInstance ;
2850
+ FirebaseFirestore db2 = db ;
2843
2851
Assert ( "FirebaseFirestore.DefaultInstance returns a singleton" , db == db2 ) ;
2844
2852
Assert ( "Query.Firestore returns the same instance" ,
2845
- db == db . Collection ( "a" ) . WhereEqualTo ( "x" , 1 ) . Firestore ) ;
2853
+ db == db . Collection ( "a" ) . WhereEqualTo ( "x" , 1 ) . Firestore ) ;
2846
2854
Assert ( "DocumentReference.Firestore returns the same instance" ,
2847
- db == db . Document ( "a/b" ) . Firestore ) ;
2855
+ db == db . Document ( "a/b" ) . Firestore ) ;
2848
2856
} ) ;
2849
2857
}
2850
2858
@@ -2853,7 +2861,7 @@ Task TestFirestoreSettings() {
2853
2861
// Verify that ToString() returns a meaningful value.
2854
2862
{
2855
2863
FirebaseApp customApp = FirebaseApp . Create ( db . App . Options , "settings-tostring-test" ) ;
2856
- FirebaseFirestore customDb = FirebaseFirestore . GetInstance ( customApp ) ;
2864
+ FirebaseFirestore customDb = TestFirestore ( customApp ) ;
2857
2865
customDb . Settings . Host = "a.b.c" ;
2858
2866
customDb . Settings . SslEnabled = true ;
2859
2867
customDb . Settings . PersistenceEnabled = false ;
@@ -2869,9 +2877,15 @@ Task TestFirestoreSettings() {
2869
2877
// Verify the default FirebaseFirestoreSettings values.
2870
2878
{
2871
2879
FirebaseApp customApp = FirebaseApp . Create ( db . App . Options , "settings-defaults-test" ) ;
2872
- FirebaseFirestore customDb = FirebaseFirestore . GetInstance ( customApp ) ;
2873
- AssertEq ( customDb . Settings . Host , "firestore.googleapis.com" ) ;
2874
- AssertEq ( customDb . Settings . SslEnabled , true ) ;
2880
+ FirebaseFirestore customDb = TestFirestore ( customApp ) ;
2881
+ // While using Firestore Emulator, the host and SslEnabled fields are different from prod.
2882
+ if ( IsUsingFirestoreEmulator ( ) ) {
2883
+ AssertStringContainsNoCase ( customDb . Settings . ToString ( ) , "Host=localhost:" ) ;
2884
+ AssertEq ( customDb . Settings . SslEnabled , false ) ;
2885
+ } else {
2886
+ AssertEq ( customDb . Settings . Host , "firestore.googleapis.com" ) ;
2887
+ AssertEq ( customDb . Settings . SslEnabled , true ) ;
2888
+ }
2875
2889
AssertEq ( customDb . Settings . PersistenceEnabled , true ) ;
2876
2890
AssertEq ( customDb . Settings . CacheSizeBytes , 100 * 1024 * 1024 ) ;
2877
2891
customApp . Dispose ( ) ;
@@ -2880,7 +2894,7 @@ Task TestFirestoreSettings() {
2880
2894
// Verify that the FirebaseFirestoreSettings written are read back.
2881
2895
{
2882
2896
FirebaseApp customApp = FirebaseApp . Create ( db . App . Options , "settings-readwrite-test" ) ;
2883
- FirebaseFirestore customDb = FirebaseFirestore . GetInstance ( customApp ) ;
2897
+ FirebaseFirestore customDb = TestFirestore ( customApp ) ;
2884
2898
2885
2899
customDb . Settings . Host = "a.b.c" ;
2886
2900
AssertEq < string > ( customDb . Settings . Host , "a.b.c" ) ;
@@ -2908,7 +2922,7 @@ Task TestFirestoreSettings() {
2908
2922
// Verify the FirebaseFirestoreSettings behavior after the FirebaseFirestore is disposed.
2909
2923
{
2910
2924
FirebaseApp customApp = FirebaseApp . Create ( db . App . Options , "settings-dispose-test" ) ;
2911
- FirebaseFirestore customDb = FirebaseFirestore . GetInstance ( customApp ) ;
2925
+ FirebaseFirestore customDb = TestFirestore ( customApp ) ;
2912
2926
FirebaseFirestoreSettings settings = customDb . Settings ;
2913
2927
2914
2928
var oldHost = settings . Host ;
@@ -2937,7 +2951,7 @@ Task TestFirestoreSettings() {
2937
2951
// Verify the FirebaseFirestoreSettings behavior after the FirebaseFirestore is used.
2938
2952
{
2939
2953
FirebaseApp customApp = FirebaseApp . Create ( db . App . Options , "settings-toolate-test" ) ;
2940
- FirebaseFirestore customDb = FirebaseFirestore . GetInstance ( customApp ) ;
2954
+ FirebaseFirestore customDb = TestFirestore ( customApp ) ;
2941
2955
var oldHost = customDb . Settings . Host ;
2942
2956
var oldSslEnabled = customDb . Settings . SslEnabled ;
2943
2957
var oldPersistenceEnabled = customDb . Settings . PersistenceEnabled ;
@@ -2964,13 +2978,13 @@ Task TestFirestoreSettings() {
2964
2978
2965
2979
customApp . Dispose ( ) ;
2966
2980
}
2967
-
2981
+
2968
2982
// Verify that FirebaseFirestoreSettings.PersistenceEnabled is respected.
2969
2983
{
2970
2984
FirebaseApp customApp = FirebaseApp . Create ( db . App . Options , "settings-persistence-test" ) ;
2971
2985
string docPath ;
2972
2986
{
2973
- FirebaseFirestore customDb = FirebaseFirestore . GetInstance ( customApp ) ;
2987
+ FirebaseFirestore customDb = TestFirestore ( customApp ) ;
2974
2988
customDb . Settings . PersistenceEnabled = true ;
2975
2989
DocumentReference doc = customDb . Collection ( "settings-persistence-test" ) . Document ( ) ;
2976
2990
docPath = doc . Path ;
@@ -2979,7 +2993,7 @@ Task TestFirestoreSettings() {
2979
2993
AssertTaskSucceeds ( customDb . TerminateAsync ( ) ) ;
2980
2994
}
2981
2995
{
2982
- FirebaseFirestore customDb = FirebaseFirestore . GetInstance ( customApp ) ;
2996
+ FirebaseFirestore customDb = TestFirestore ( customApp ) ;
2983
2997
customDb . Settings . PersistenceEnabled = false ;
2984
2998
DocumentReference doc = customDb . Document ( docPath ) ;
2985
2999
AssertTaskSucceeds ( doc . SetAsync ( TestData ( 1 ) ) ) ;
@@ -3288,7 +3302,7 @@ Task TestInternalExceptions() {
3288
3302
3289
3303
// Invalid argument.
3290
3304
try {
3291
- var db1 = FirebaseFirestore . DefaultInstance ;
3305
+ var db1 = db ;
3292
3306
var db2 = NonDefaultFirestore ( "InvalidArgument" ) ;
3293
3307
3294
3308
var batch = db1 . StartBatch ( ) ;
@@ -3304,28 +3318,32 @@ Task TestInternalExceptions() {
3304
3318
exception , exception is ArgumentException ) ;
3305
3319
}
3306
3320
3307
- // Illegal state.
3308
- exception = null ;
3309
- try {
3310
- var db = NonDefaultFirestore ( "IllegalState" ) ;
3311
- db . Settings . SslEnabled = false ;
3312
- // Make sure the Firestore client is initialized.
3313
- db . Collection ( "foo" ) . Document ( "bar" ) ;
3321
+ // While running against Firestore emulator, the 'sslEnabled' is already set to "false". No exception
3322
+ // will be thrown.
3323
+ if ( ! IsUsingFirestoreEmulator ( ) ) {
3324
+ // Illegal state.
3325
+ exception = null ;
3326
+ try {
3327
+ var db = NonDefaultFirestore ( "IllegalState" ) ;
3328
+ db . Settings . SslEnabled = false ;
3329
+ // Make sure the Firestore client is initialized.
3330
+ db . Collection ( "foo" ) . Document ( "bar" ) ;
3314
3331
3315
- } catch ( Exception e ) {
3316
- exception = e ;
3332
+ } catch ( Exception e ) {
3333
+ exception = e ;
3317
3334
3318
- } finally {
3319
- Assert ( "Expected an exception to be thrown" , exception != null ) ;
3320
- Assert ( "Expected an InvalidOperationException, but received " +
3321
- exception , exception is InvalidOperationException ) ;
3335
+ } finally {
3336
+ Assert ( "Expected an exception to be thrown" , exception != null ) ;
3337
+ Assert ( "Expected an InvalidOperationException, but received " +
3338
+ exception , exception is InvalidOperationException ) ;
3339
+ }
3322
3340
}
3323
3341
3324
3342
// Exception in an async method.
3325
3343
exception = null ;
3326
3344
3327
3345
{
3328
- var db1 = FirebaseFirestore . DefaultInstance ;
3346
+ var db1 = db ;
3329
3347
var db2 = NonDefaultFirestore ( "InternalAssertion" ) ;
3330
3348
3331
3349
DocumentReference doc1 = db1 . Collection ( "foo" ) . Document ( "bar" ) ;
@@ -3451,10 +3469,10 @@ Task TestLoadBundlesFromOtherProjects_ShouldFail() {
3451
3469
3452
3470
Task LoadedBundleDocumentsAlreadyPulledFromBackend_ShouldNotOverwrite ( ) {
3453
3471
return Async ( ( ) => {
3454
- var db = FirebaseFirestore . GetInstance ( FirebaseApp . DefaultInstance ) ;
3472
+ var db = TestFirestore ( FirebaseApp . DefaultInstance ) ;
3455
3473
Await ( db . TerminateAsync ( ) ) ;
3456
3474
Await ( db . ClearPersistenceAsync ( ) ) ;
3457
- db = FirebaseFirestore . GetInstance ( FirebaseApp . DefaultInstance ) ;
3475
+ db = TestFirestore ( FirebaseApp . DefaultInstance ) ;
3458
3476
3459
3477
var collection = db . Collection ( "coll-1" ) ;
3460
3478
Await ( collection . Document ( "a" ) . SetAsync ( new Dictionary < string , object > {
@@ -3784,7 +3802,7 @@ Task TestFirestoreDispose() {
3784
3802
// Verify that disposing the `FirebaseApp` in turn disposes the `FirebaseFirestore` object.
3785
3803
{
3786
3804
FirebaseApp customApp = FirebaseApp . Create ( db . App . Options , "dispose-app-to-firestore" ) ;
3787
- FirebaseFirestore customDb = FirebaseFirestore . GetInstance ( customApp ) ;
3805
+ FirebaseFirestore customDb = TestFirestore ( customApp ) ;
3788
3806
customApp . Dispose ( ) ;
3789
3807
Assert ( "App property should be null" , customDb . App == null ) ;
3790
3808
}
@@ -3798,7 +3816,7 @@ Task TestFirestoreDispose() {
3798
3816
Task < string > sampleTypedTask = taskCompletionSource . Task ;
3799
3817
3800
3818
FirebaseApp customApp = FirebaseApp . Create ( db . App . Options , "dispose-exceptions" ) ;
3801
- FirebaseFirestore customDb = FirebaseFirestore . GetInstance ( customApp ) ;
3819
+ FirebaseFirestore customDb = TestFirestore ( customApp ) ;
3802
3820
var doc = customDb . Document ( "ColA/DocA/ColB/DocB" ) ;
3803
3821
var doc2 = customDb . Document ( "ColA/DocA/ColB/DocC" ) ;
3804
3822
var collection = doc . Parent ;
@@ -4045,7 +4063,7 @@ private FirebaseFirestore NonDefaultFirestore(string appName) {
4045
4063
// Setting a ProjectId is required (b/158838266).
4046
4064
appOptions . ProjectId = appName ;
4047
4065
var app = FirebaseApp . Create ( appOptions , appName ) ;
4048
- return FirebaseFirestore . GetInstance ( app ) ;
4066
+ return TestFirestore ( app ) ;
4049
4067
}
4050
4068
4051
4069
/// Wraps IEnumerator in an exception handling Task.
0 commit comments