コード例 #1
0
        public void ConvenienceMembers()
        {
            var db       = FirestoreDb.Create("proj", "db", new FakeFirestoreClient());
            var query    = db.Collection("col1");
            var readTime = new Timestamp(10, 2);
            var doc1     = DocumentSnapshot.ForMissingDocument(db, "projects/proj/databases/db/documents/col1/doc1", readTime);
            var proto    = new Document
            {
                CreateTime = CreateProtoTimestamp(1, 10),
                UpdateTime = CreateProtoTimestamp(2, 20),
                Name       = "projects/proj/databases/db/documents/col1/doc2"
            };
            var doc2 = DocumentSnapshot.ForDocument(db, proto, readTime);
            var docs = new[] { doc1, doc2 };

            var querySnapshot = new QuerySnapshot(query, docs, readTime);

            Assert.Equal(2, querySnapshot.Count);
            // Indexer
            Assert.Same(doc1, querySnapshot[0]);
            Assert.Same(doc2, querySnapshot[1]);
            Assert.Throws <ArgumentOutOfRangeException>(() => querySnapshot[-1]);
            Assert.Throws <ArgumentOutOfRangeException>(() => querySnapshot[2]);
            // Use IEnumerable<DocumentSnapshot>
            Assert.Equal(docs, querySnapshot);
            // OfType forces the use of non-generic IEnumerable
            Assert.Equal(docs, querySnapshot.OfType <DocumentSnapshot>());
        }
コード例 #2
0
        public void MissingDocumentTimestamps()
        {
            var target   = new AllTimestampOptionsModel();
            var db       = FirestoreDb.Create("project", "database", new FakeFirestoreClient());
            var readTime = new Timestamp(1, 100);
            var snapshot = DocumentSnapshot.ForMissingDocument(db, db.Document("col1/doc1").Path, readTime);

            AttributedTimestampAssigner.MaybeAssignTimestamps(target, snapshot);

            Assert.Equal(default, target.CreateDateTime);
        public void MissingDocumentSnapshotsAreRejected()
        {
            var query    = s_db.Collection("col");
            var comparer = query.CreateDocumentSnapshotComparer();
            var doc      = CreateSnapshot("doc", 1, 1);
            var missing  = DocumentSnapshot.ForMissingDocument(s_db, s_db.Document("col/doc2").Path, new Timestamp(10, 2));

            Assert.Throws <ArgumentException>(() => comparer.Compare(doc, missing));
            Assert.Throws <ArgumentException>(() => comparer.Compare(missing, doc));
        }
コード例 #4
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 });
        }
コード例 #5
0
        public void ConvertTo_Missing()
        {
            var sample   = GetSampleSnapshot();
            var document = DocumentSnapshot.ForMissingDocument(sample.Database, sample.Document.Name, new Timestamp(1, 2));

            // Deserializing ends up with the default value of the value type. That's slightly annoying, but
            // users can always use the Exists property instead.
            Assert.Equal(0, document.ConvertTo <int>());

            var custom = document.ConvertTo <SerializationTestData.CustomValueType>();

            Assert.Null(custom.Name);
            Assert.Equal(0, custom.Value);
        }
コード例 #6
0
        public void MissingDocument()
        {
            var db       = FirestoreDb.Create("proj", "db", new FakeFirestoreClient());
            var readTime = new Timestamp(10, 2);
            var document = DocumentSnapshot.ForMissingDocument(db, "projects/proj/databases/db/documents/col1/doc1/col2/doc2", readTime);

            Assert.Equal(db.Document("col1/doc1/col2/doc2"), document.Reference);
            Assert.Equal("doc2", document.Id);
            Assert.Same(db, document.Database);
            Assert.Null(document.Document);
            Assert.Null(document.CreateTime);
            Assert.Null(document.UpdateTime);
            Assert.Equal(readTime, document.ReadTime);
            Assert.False(document.Exists);
            Assert.Null(document.ToDictionary());
            Assert.Null(document.ConvertTo <SampleData>());
            Assert.Throws <InvalidOperationException>(() => document.GetValue <string>("name"));
            Assert.Throws <InvalidOperationException>(() => document.GetValue <string>(new FieldPath("name")));
            Assert.False(document.TryGetValue("name", out string name1));
            Assert.False(document.TryGetValue(new FieldPath("name"), out string name2));
        }