public void MergeFields_Strings_Valid()
        {
            var options = SetOptions.MergeFields("a.b", "c");

            Assert.Equal(new[] { new FieldPath("a", "b"), new FieldPath("c") }, options.FieldMask);
            Assert.True(options.Merge);
        }
        public void MergeFields_Strings_Empty()
        {
            var options = SetOptions.MergeFields(new string[0]);

            Assert.Empty(options.FieldMask);
            Assert.True(options.Merge);
        }
        public void MergeFields_FieldPaths_Empty()
        {
            var options = SetOptions.MergeFields(new FieldPath[0]);

            Assert.Empty(options.FieldMask);
            Assert.True(options.Merge);
        }
Пример #4
0
 public void SetData(object documentData, CompletionHandler handler, params string[] mergeFields)
 {
     _documentReference.Set(documentData.ToNativeFieldValues(), SetOptions.MergeFields(mergeFields)).AddOnCompleteListener(new OnCompleteHandlerListener((task) =>
     {
         handler?.Invoke(task.IsSuccessful ? null : ExceptionMapper.Map(task.Exception));
     }));
 }
Пример #5
0
 public void SetData <T>(T documentData, IEnumerable <string> mergeFields, CompletionHandler handler) where T : class
 {
     DocumentReference.Set(documentData.ToNativeFieldValues(), SetOptions.MergeFields(mergeFields.ToArray())).AddOnCompleteListener(new OnCompleteHandlerListener((task) =>
     {
         handler?.Invoke(task.IsSuccessful ? null : new CloudFirestoreException(task.Exception.Message));
     }));
 }
        public void MergeFields_FieldPaths_Valid()
        {
            var path1   = new FieldPath("a", "b");
            var path2   = new FieldPath("c");
            var options = SetOptions.MergeFields(path1, path2);

            Assert.Equal(new[] { path1, path2 }, options.FieldMask);
            Assert.True(options.Merge);
        }
        public void MergeFields_Immutable()
        {
            var path1     = new FieldPath("a", "b");
            var path2     = new FieldPath("c");
            var pathArray = new[] { path1, path2 };
            var options   = SetOptions.MergeFields(pathArray);

            pathArray[0] = new FieldPath("d");
            // Modifying the array doesn't modify the options
            Assert.Equal(new[] { path1, path2 }, options.FieldMask);
        }
Пример #8
0
 public void Set(SerializableTest wrapper)
 {
     SetTest test = wrapper.Test.Set;
     Check(test.IsError, test.Request, batch =>
     {
         DocumentReference doc = GetDocumentReference(test.DocRefPath);
         object documentData = DeserializeJson(test.JsonData);
         var setOptions = test.Option == null ? null :
             test.Option.All ? SetOptions.MergeAll :
             SetOptions.MergeFields(test.Option.Fields.Select(ConvertFieldPath).ToArray());
         batch.Set(doc, documentData, setOptions);
     });
 }
        /// <summary>
        ///     we don't want to overwrite anything besides the fields we have on the class. Since some initialized
        ///     properties may be null, we specify merge fields.
        /// </summary>
        /// <param name="project">
        ///     if there are any null property values that should NOT overwrite fields on the
        ///     documents; specify the non-null properties in the <paramref name="mergeFields" />mergeFields> param.
        /// </param>
        /// <param name="githubDatabaseId"></param>
        /// <param name="mergeFields"></param>
        /// <returns></returns>
        public async Task <Project> UploadProjectAsync(
            Project project,
            string githubDatabaseId,
            string[] mergeFields
            )
        {
            // Make document ref in collection
            var projectRef = _projectCollection.Document(githubDatabaseId);
            // write / update in Db
            var unused = await projectRef.SetAsync(project, SetOptions.MergeFields(mergeFields));

            // get result of write
            var snapshot = await projectRef.GetSnapshotAsync();

            // convert to model
            return(snapshot.ConvertTo <Project>());
        }
Пример #10
0
        public Task SetDataAsync <T>(T documentData, IEnumerable <string> mergeFields) where T : class
        {
            var tcs = new TaskCompletionSource <bool>();

            DocumentReference.Set(documentData.ToNativeFieldValues(), SetOptions.MergeFields(mergeFields.ToArray())).AddOnCompleteListener(new OnCompleteHandlerListener((task) =>
            {
                if (task.IsSuccessful)
                {
                    tcs.SetResult(true);
                }
                else
                {
                    tcs.SetException(new CloudFirestoreException(task.Exception.Message));
                }
            }));

            return(tcs.Task);
        }
Пример #11
0
        public Task SetDataAsync(object documentData, params string[] mergeFields)
        {
            var tcs = new TaskCompletionSource <bool>();

            _documentReference.Set(documentData.ToNativeFieldValues(), SetOptions.MergeFields(mergeFields)).AddOnCompleteListener(new OnCompleteHandlerListener((task) =>
            {
                if (task.IsSuccessful)
                {
                    tcs.SetResult(true);
                }
                else
                {
                    tcs.SetException(ExceptionMapper.Map(task.Exception));
                }
            }));

            return(tcs.Task);
        }
Пример #12
0
    public IEnumerator TestSetOptions() {
      DocumentReference doc = TestDocument();
      var initialData = new Dictionary<string, object> {
        { "field1", "value1" },
      };

      var set1 = new Dictionary<string, object> { { "field2", "value2" } };
      var setOptions1 = SetOptions.MergeAll;

      var set2 =
          new Dictionary<string, object> { { "field3", "value3" }, { "not-field4", "not-value4" } };
      var setOptions2 = SetOptions.MergeFields("field3");

      var set3 =
          new Dictionary<string, object> { { "field4", "value4" }, { "not-field5", "not-value5" } };
      var setOptions3 = SetOptions.MergeFields(new FieldPath("field4"));

      var expected = new Dictionary<string, object> {
        { "field1", "value1" },
        { "field2", "value2" },
        { "field3", "value3" },
        { "field4", "value4" },
      };

      yield return AwaitSuccess(doc.SetAsync(initialData));
      yield return AwaitSuccess(doc.SetAsync(set1, setOptions1));
      yield return AwaitSuccess(
          doc.Firestore.StartBatch().Set(doc, set2, setOptions2).CommitAsync());
      yield return AwaitSuccess(db.RunTransactionAsync(transaction => {
        transaction.Set(doc, set3, setOptions3);
        return Task.CompletedTask;
      }));

      var getTask = doc.GetSnapshotAsync();
      yield return AwaitSuccess(getTask);
      Assert.That(getTask.Result.ToDictionary(), Is.EquivalentTo(expected));
    }
Пример #13
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")
            });
        }
Пример #14
0
 public void MergeFields_FieldPaths_Invalid()
 {
     Assert.Throws <ArgumentNullException>(() => SetOptions.MergeFields((FieldPath[])null));
     Assert.Throws <ArgumentException>(() => SetOptions.MergeFields((FieldPath)null));
     Assert.Throws <ArgumentException>(() => SetOptions.MergeFields(null, new FieldPath("a")));
 }
 public void SetData(IDocumentReference document, object documentData, params string[] mergeFields)
 {
     _transaction.Set(document.ToNative(), documentData.ToNativeFieldValues(), SetOptions.MergeFields(mergeFields));
 }
Пример #16
0
 public void MergeFields_Strings_Invalid(params string[] fieldPaths)
 {
     Assert.Throws <ArgumentException>(() => SetOptions.MergeFields(fieldPaths));
 }
 public ITransaction Set <T>(IDocumentReference document, T documentData, params string[] mergeFields)
 {
     _transaction.Set(document.ToNative(), documentData.ToNativeFieldValues(), SetOptions.MergeFields(mergeFields));
     return(this);
 }
        public ITransaction Set <T>(IDocumentReference document, T documentData, params string[] mergeFields)
        {
            var wrapper = (DocumentReferenceWrapper)document;

            _transaction.Set((DocumentReference)wrapper, documentData.ToNativeFieldValues(), SetOptions.MergeFields(mergeFields));
            return(this);
        }
Пример #19
0
        public void SetData(IDocumentReference document, object documentData, params string[] mergeFields)
        {
            var wrapper = (DocumentReferenceWrapper)document;

            _writeBatch.Set((DocumentReference)wrapper, documentData.ToNativeFieldValues(), SetOptions.MergeFields(mergeFields));
        }
Пример #20
0
        public void SetData <T>(IDocumentReference document, T documentData, string[] mergeFields) where T : class
        {
            var wrapper = (DocumentReferenceWrapper)document;

            WriteBatch.Set(wrapper.DocumentReference, documentData.ToNativeFieldValues(), SetOptions.MergeFields(mergeFields));
        }
Пример #21
0
 public IWriteBatch Set <T>(IDocumentReference document, T documentData, params string[] mergeFields)
 {
     _writeBatch.Set(document.ToNative(), documentData.ToNativeFieldValues(), SetOptions.MergeFields(mergeFields));
     return(this);
 }