public void Equality()
        {
            var query    = s_db.Collection("col1");
            var readTime = new Timestamp(10, 2);
            var doc1     = GetSampleSnapshot(s_db, "doc1");
            var doc2     = GetSampleSnapshot(s_db, "doc2");
            var doc3     = GetSampleSnapshot(s_db, "doc3");

            var docs    = new[] { doc1, doc2 };
            var control = QuerySnapshot.ForDocuments(query, docs, readTime);

            EqualityTester.AssertEqual(control,
                                       // Distinct but equal values for query and snapshots, but a different timestamp
                                       equal: new[] { QuerySnapshot.ForDocuments(s_db.Collection("col1"), new[] { GetSampleSnapshot(s_db, "doc1"), doc2 }, new Timestamp(12, 13)) },
                                       unequal: new[] {
                // Unequal query
                QuerySnapshot.ForDocuments(query.Offset(0), docs, readTime),
                // No doc2
                QuerySnapshot.ForDocuments(query, new[] { doc1 }, readTime),
                // Extra doc3
                QuerySnapshot.ForDocuments(query, new[] { doc1, doc2, doc3 }, readTime),
                // Order matters
                QuerySnapshot.ForDocuments(query, new[] { doc2, doc1 }, readTime),
            });

            // Note: no test for the changes being compared. It would be overkill at the moment.
        }
Beispiel #2
0
        public void Equality()
        {
            var query    = s_db.Collection("col1");
            var readTime = new Timestamp(10, 2);
            var doc1     = GetSampleSnapshot("doc1");
            var doc2     = GetSampleSnapshot("doc2");
            var doc3     = GetSampleSnapshot("doc3");

            var docs    = new[] { doc1, doc2 };
            var control = new QuerySnapshot(query, docs, readTime);

            EqualityTester.AssertEqual(control,
                                       // Distinct but equal values for query and snapshots, but a different timestamp
                                       equal: new[] { new QuerySnapshot(s_db.Collection("col1"), new[] { GetSampleSnapshot("doc1"), doc2 }, new Timestamp(12, 13)) },
                                       unequal: new[] {
                // Unequal query
                new QuerySnapshot(query.Offset(0), docs, readTime),
                // No doc2
                new QuerySnapshot(query, new[] { doc1 }, readTime),
                // Extra doc3
                new QuerySnapshot(query, new[] { doc1, doc2, doc3 }, readTime),
                // Order matters
                new QuerySnapshot(query, new[] { doc2, doc1 }, readTime),
            });
        }
        public void Equality()
        {
            var snapshot = GetSampleSnapshot("doc1");

            var control = new DocumentChange(snapshot, DocumentChange.Type.Modified, 3, 2);

            EqualityTester.AssertEqual(control,
                                       // Distinct but equal document snapshots
                                       equal: new[] { new DocumentChange(GetSampleSnapshot("doc1"), DocumentChange.Type.Modified, 3, 2) },
                                       unequal: new[] {
                // Different document
                new DocumentChange(GetSampleSnapshot("doc2"), DocumentChange.Type.Modified, 3, 2),
                // These indexes don't actually make sense for added, but it's simplest to change things independently
                new DocumentChange(snapshot, DocumentChange.Type.Added, 3, 2),
                new DocumentChange(snapshot, DocumentChange.Type.Modified, 4, 2),
                new DocumentChange(snapshot, DocumentChange.Type.Modified, 3, 1),
                new DocumentChange(snapshot, DocumentChange.Type.Modified, null, 2),
                new DocumentChange(snapshot, DocumentChange.Type.Modified, 3, null),
            });

            // Null matching checks
            EqualityTester.AssertEqual(new DocumentChange(snapshot, DocumentChange.Type.Added, null, 2),
                                       equal: new[] { new DocumentChange(snapshot, DocumentChange.Type.Added, null, 2) },
                                       unequal: new[] { new DocumentChange(snapshot, DocumentChange.Type.Added, 0, 2) });
            EqualityTester.AssertEqual(new DocumentChange(snapshot, DocumentChange.Type.Removed, 1, null),
                                       equal: new[] { new DocumentChange(snapshot, DocumentChange.Type.Removed, 1, null) },
                                       unequal: new[] { new DocumentChange(snapshot, DocumentChange.Type.Removed, 1, 1) });
        }
Beispiel #4
0
        public void Equality()
        {
            var client = new FakeFirestoreClient();
            var db1    = FirestoreDb.Create("proj", "db", client);
            var db2    = FirestoreDb.Create("proj", "db", client);
            var db3    = FirestoreDb.Create("proj", "otherdb", client);

            var control = db1.Collection("col1/doc1/col2");
            var equal   = new[]
            {
                db1.Collection("col1/doc1/col2"),
                db2.Collection("col1/doc1/col2"),
                db1.Collection("col1").Document("doc1").Collection("col2")
            };
            var unequal = new[]
            {
                db1.Collection("col1x/doc1/col2"),
                db1.Collection("col1/doc1x/col2"),
                db1.Collection("col1/doc1/col2x"),
                db3.Collection("col1/doc1/col2"),
                db1.Collection("col1"),
                db1.Collection("col2"),
            };

            EqualityTester.AssertEqual(control, equal, unequal);
        }
Beispiel #5
0
        public void Equality_Where()
        {
            var col   = s_db.Collection("col");
            var query = col.WhereEqualTo("field", 10);

            EqualityTester.AssertEqual(query,
                                       equal: new[] {
                col.WhereEqualTo("field", 10),                // Same value
                col.WhereEqualTo("field", 10L),               // Same value after serialization
                col.WhereEqualTo(new FieldPath("field"), 10), // FieldPath instead of Field
            },
                                       unequal: new[] {
                query.WhereEqualTo("field", 10),    // Repeated filter doesn't replace (at the moment, anyway)
                col.WhereEqualTo("otherfield", 10), // Different field
                col.WhereLessThan("field", 10),     // Different operator
                col.WhereEqualTo("field", 20),      // Different value
            }
                                       );

            query = col.WhereEqualTo("first", "foo").WhereEqualTo("second", "bar");
            EqualityTester.AssertEqual(query,
                                       equal: new[] {
                col.WhereEqualTo("first", "foo").WhereEqualTo("second", "bar")
            },
                                       unequal: new[] {
                // Ordering of filters matters
                col.WhereEqualTo("second", "bar").WhereEqualTo("first", "foo"),
                // It's not just a replacement
                col.WhereEqualTo("first", "foo")
            }
                                       );
        }
        public void Equality()
        {
            var control = GetSampleSnapshot();
            var equalDb = FirestoreDb.Create("proj", "db", new FakeFirestoreClient());

            // Equal (but distinct) everything
            var doc1   = control.Document.Clone();
            var equal1 = DocumentSnapshot.ForDocument(equalDb, doc1, control.ReadTime);

            var doc2 = control.Document.Clone();

            doc2.CreateTime = null;
            doc2.UpdateTime = null;
            // Different create/update times
            var equal2 = DocumentSnapshot.ForDocument(equalDb, doc2, control.ReadTime);

            // Different read time
            var equal3 = DocumentSnapshot.ForDocument(equalDb, doc2, new Timestamp(10, 3));

            // Different fields
            var doc4 = doc1.Clone();

            doc4.Fields["other"] = new Value {
                StringValue = "different"
            };
            var unequal1 = DocumentSnapshot.ForDocument(equalDb, doc4, control.ReadTime);

            // Different name
            var doc5 = doc1.Clone();

            doc5.Name += "x";
            var unequal2 = DocumentSnapshot.ForDocument(equalDb, doc5, control.ReadTime);

            EqualityTester.AssertEqual(control, new[] { equal1, equal2, equal3 }, new[] { unequal1, unequal2 });
        }
Beispiel #7
0
        public void Equality_Complex()
        {
            // It doesn't matter what order the query calls are made in, other than for ordering + start etc.
            var col   = s_db.Collection("col");
            var query = col
                        .OrderBy("foo")
                        .StartAfter(20)
                        .EndBefore(30)
                        .Select("foo")
                        .WhereGreaterThan("bar", 20)
                        .Limit(20)
                        .Offset(3);

            EqualityTester.AssertEqual(query,
                                       equal: new[] {
                col.WhereGreaterThan("bar", 20)
                .Select("foo")
                .Offset(3)
                .OrderBy("foo")
                .EndBefore(30)
                .Limit(20)
                .StartAfter(20)
            },
                                       unequal: new[] {
                // Just one change here - the EndBefore argument
                col.WhereGreaterThan("bar", 20)
                .Select("foo")
                .Offset(3)
                .OrderBy("foo")
                .EndBefore(40)
                .Limit(20)
                .StartAfter(20)
            }
                                       );
        }
Beispiel #8
0
 public void Equality_CollectionGroup()
 {
     EqualityTester.AssertEqual(s_db.CollectionGroup("col"),
                                equal: new[] { s_db.CollectionGroup("col") },
                                unequal: new[] { s_db.Collection("col") }
                                );
 }
        public void Equality()
        {
            // Note: timestamp choice can give false test failures, due to proto hash code computation.
            var timestamp1 = new Timestamp(10, 0);
            var timestamp2 = new Timestamp(10, 1);

            EqualityTester.AssertEqual(Precondition.None,
                                       equal: new[] { Precondition.None },
                                       unequal: new[] { Precondition.MustExist, Precondition.MustNotExist, Precondition.LastUpdated(timestamp1) }
                                       );

            EqualityTester.AssertEqual(Precondition.MustExist,
                                       equal: new[] { Precondition.MustExist },
                                       unequal: new[] { Precondition.MustNotExist, Precondition.LastUpdated(timestamp1) }
                                       );

            EqualityTester.AssertEqual(Precondition.MustNotExist,
                                       equal: new[] { Precondition.MustNotExist },
                                       unequal: new[] { Precondition.LastUpdated(timestamp1) }
                                       );

            EqualityTester.AssertEqual(Precondition.LastUpdated(timestamp1),
                                       equal: new[] { Precondition.LastUpdated(timestamp1) },
                                       unequal: new[] { Precondition.LastUpdated(timestamp2) }
                                       );
        }
Beispiel #10
0
        public void Equality()
        {
            var control = new FieldPath("a", "b");
            var equal   = new[] { new FieldPath("a", "b"), FieldPath.FromDotSeparatedString("a.b") };
            var unequal = new[] { new FieldPath("a", "c") };

            EqualityTester.AssertEqual(control, equal, unequal);
        }
Beispiel #11
0
        public void Equality()
        {
            var control = Blob.CopyFrom(new byte[] { 1, 2, 3, 4, 5 });
            var equal   = new[] { Blob.CopyFrom(new byte[] { 1, 2, 3, 4, 5 }) };
            var unequal = new[] { Blob.CopyFrom(new byte[] { 1, 2, 3, 4, 5, 6 }) };

            EqualityTester.AssertEqual(control, equal, unequal);
            EqualityTester.AssertEqualityOperators(control, equal, unequal);
        }
Beispiel #12
0
        public void Equality_Limit()
        {
            var col   = s_db.Collection("col");
            var query = col.Limit(10);

            EqualityTester.AssertEqual(query,
                                       equal: new[] { col.Limit(10), query.Limit(10) },
                                       unequal: new[] { col.Limit(2), query.Limit(2) });
        }
Beispiel #13
0
        public void Equality()
        {
            var control = new Timestamp(1, 2);
            var equal   = new[] { new Timestamp(1, 2) };
            var unequal = new[] { new Timestamp(2, 2), new Timestamp(1, 3) };

            EqualityTester.AssertEqual(control, equal, unequal);
            EqualityTester.AssertEqualityOperators(control, equal, unequal);
        }
Beispiel #14
0
        public void Equality_Offset()
        {
            var col   = s_db.Collection("col");
            var query = col.Offset(1);

            EqualityTester.AssertEqual(query,
                                       equal: new[] { col.Offset(1), query.Offset(1) },
                                       unequal: new[] { col.Offset(2), query.Offset(2) });
        }
Beispiel #15
0
        public void Equality_CollectionRefNotEqualToQuery()
        {
            var col1 = s_db.Collection("col1");
            var col2 = s_db.Collection("col2");

            // Collection and "a Query isn't equal to a CollectionReference"
            var query = col1.Offset(0);

            EqualityTester.AssertEqual(query, equal: new[] { col1.Offset(0), query.Offset(0) }, unequal: new[] { col1, col2.Offset(0) });
        }
        public void Equality_Missing()
        {
            var nonMissing = GetSampleSnapshot();
            var db         = nonMissing.Database;
            var doc        = nonMissing.Document;

            var control  = DocumentSnapshot.ForMissingDocument(db, doc.Name, new Timestamp(1, 2));
            var equal    = DocumentSnapshot.ForMissingDocument(db, doc.Name, new Timestamp(1, 3));
            var unequal1 = DocumentSnapshot.ForMissingDocument(db, doc.Name + "x", new Timestamp(1, 2));
            var unequal2 = DocumentSnapshot.ForDocument(db, doc, new Timestamp(1, 2));

            EqualityTester.AssertEqual(control, new[] { equal }, new[] { unequal1, unequal2 });
        }
        public void Equality()
        {
            var control = new GeoPoint(1.5, 2.5);
            // Equal
            var equal   = new[] { new GeoPoint(1.5, 2.5) };
            var unequal = new[]
            {
                new GeoPoint(2.5, 2.5), // Difference in latitude
                new GeoPoint(1.5, 3.5)  // Difference in longitude
            };

            EqualityTester.AssertEqual(control, equal, unequal);
            EqualityTester.AssertEqualityOperators(control, equal, unequal);
        }
Beispiel #18
0
        public void Equality_End()
        {
            var col   = s_db.Collection("col");
            var query = col.OrderBy("foo").EndAt(10);

            EqualityTester.AssertEqual(query,
                                       equal: new[] {
                col.OrderBy("foo").EndAt(10L)
            },
                                       unequal: new[] {
                col.OrderBy("foo"),
                col.OrderBy("foo").EndAt(20),
                col.OrderBy("foo").EndBefore(10)
            }
                                       );
        }
Beispiel #19
0
        public void Equality_Start()
        {
            var col   = s_db.Collection("col");
            var query = col.OrderBy("foo").StartAt(10);

            EqualityTester.AssertEqual(query,
                                       equal: new[] {
                col.OrderBy("foo").StartAt(10L),
            },
                                       unequal: new[] {
                col.OrderBy("foo"),
                col.OrderBy("foo").StartAt(20),
                col.OrderBy("foo").StartAfter(10)
            }
                                       );
        }
Beispiel #20
0
        public void Equality_OrderBy()
        {
            var col   = s_db.Collection("col");
            var query = col.OrderBy("foo").OrderByDescending("bar");

            EqualityTester.AssertEqual(query,
                                       equal: new[] {
                col.OrderBy("foo").OrderByDescending("bar")
            },
                                       unequal: new[] {
                query.OrderBy("foo"),
                col.OrderBy("foo"),
                col.OrderByDescending("foo").OrderByDescending("bar"),
                col.OrderBy("bar").OrderByDescending("foo"),
            }
                                       );
        }
Beispiel #21
0
        public void Equality_Select()
        {
            var col = s_db.Collection("col");
            // Each call to Select replaces previous ones
            var query = col.Select("a", "b");

            EqualityTester.AssertEqual(query,
                                       equal: new[] {
                col.Select("a", "b"),
                query.Select("a", "b"),
                col.Select("x").Select("a", "b"),
            },
                                       unequal: new[] {
                col.Select("b").Select("a"), // Order matters
                query.Select("a"),           // Projecting again adds another projection
            }
                                       );
        }
Beispiel #22
0
        public void Equality()
        {
            EqualityTester.AssertEqual(SetOptions.MergeAll,
                                       equal: new[] { SetOptions.MergeAll },
                                       unequal: new[] { SetOptions.Overwrite, SetOptions.MergeFields("a", "b") });

            EqualityTester.AssertEqual(SetOptions.Overwrite,
                                       equal: new[] { SetOptions.Overwrite },
                                       unequal: new[] { SetOptions.MergeFields("a", "b") });

            EqualityTester.AssertEqual(SetOptions.MergeFields("a", "b.c"),
                                       equal: new[] {
                SetOptions.MergeFields("a", "b.c"),
                SetOptions.MergeFields(new FieldPath("a"), new FieldPath("b", "c"))
            },
                                       unequal: new[] {
                SetOptions.MergeFields("a"),
                SetOptions.MergeFields("b.c"),
                SetOptions.MergeFields("a", "b.c", "d"),
                SetOptions.MergeFields("x"),
                // Currently, equality is order-sensitive. This is being reviewed.
                SetOptions.MergeFields("b.c", "a")
            });
        }
Beispiel #23
0
 public void Equality()
 {
     EqualityTester.AssertEqual(TransactionOptions.Create(10),
                                equal: new[] { TransactionOptions.Create(10) },
                                unequal: new[] { TransactionOptions.Create(20) });
 }
 public void Equality()
 {
     EqualityTester.AssertEqual(new FieldMask("a", "b"),
                                new[] { new FieldMask("a", "b", "b"), new FieldMask(new FieldPath("a"), new FieldPath("b")) },
                                new[] { new FieldMask("a"), new FieldMask("a", "c"), new FieldMask("a", "b", "c") });
 }