コード例 #1
0
        public void UpdateSinglePerson_ManyExists_OneIsUpdated()
        {
            var persons = new[]
            {
                new Person {
                    Name = "Daniel1", Age = 29
                },
                new Person {
                    Name = "Daniel2", Age = 29
                }
            };

            TestHelper.InsertDocuments(Constants.Collections.PersonsCollectionName, persons);

            using (var cn = TestHelper.CreateConnection())
            {
                var updateCommand = new UpdateDocumentsCommand(cn)
                {
                    FullCollectionName = Constants.Collections.PersonsFullCollectionName,
                    QuerySelector      = new { Name = "Daniel2" },
                    Document           = new { Name = "Daniel3" }
                };
                updateCommand.Execute();
            }

            Assert.AreEqual(1, TestHelper.GetDocumentCount(new { Name = "Daniel3" }, Constants.Collections.PersonsCollectionName));
        }
コード例 #2
0
 public DocumentsController(UploadDocumentsCommand uploadDocumentsDocumentsCommand,
                            GetDocumentsCommand getDocumentsCommand,
                            UpdateDocumentsCommand updateDocumentsCommand)
 {
     _uploadDocumentsDocumentsCommand = uploadDocumentsDocumentsCommand;
     _getDocumentsCommand             = getDocumentsCommand;
     _updateDocumentsCommand          = updateDocumentsCommand;
 }
コード例 #3
0
        public void UpdateMany(object selector, object document)
        {
            var cmd = new UpdateDocumentsCommand(Database.Session.Connection)
            {
                Mode = UpdateModes.MultiUpdate,
                FullCollectionName = FullCollectionName,
                QuerySelector      = selector,
                Document           = document
            };

            cmd.Execute();
        }
コード例 #4
0
        public void UpdateSinglePerson_EmptyDb_OneIsUpsert()
        {
            using (var cn = TestHelper.CreateConnection())
            {
                var updateCommand = new UpdateDocumentsCommand(cn)
                {
                    Mode = UpdateModes.Upsert,
                    FullCollectionName = Constants.Collections.PersonsFullCollectionName,
                    QuerySelector      = new { Name = "Joe" },
                    Document           = new { Name = "Joe" }
                };
                updateCommand.Execute();
            }

            Assert.AreEqual(1, TestHelper.GetDocumentCount(Constants.Collections.PersonsCollectionName));
        }
コード例 #5
0
        public void UpdateManyPersons_UsingDocumentWhereManyExists_NoneIsUpdated()
        {
            var persons = new[]
            {
                new { Name = "Daniel1", Age = 29 },
                new { Name = "Daniel2", Age = 29 }
            };

            TestHelper.InsertDocuments(Constants.Collections.PersonsCollectionName, persons);

            using (var cn = TestHelper.CreateConnection())
            {
                var updateCommand = new UpdateDocumentsCommand(cn)
                {
                    Mode = UpdateModes.MultiUpdate,
                    FullCollectionName = Constants.Collections.PersonsFullCollectionName,
                    QuerySelector      = @"{$where : ""this.Name.indexOf('Daniel') > -1""}",
                    Document           = new { Name = "The Daniel" }
                };
                updateCommand.Execute();
            }

            Assert.AreEqual(0, TestHelper.GetDocumentCount(new { Name = "The Daniel" }, Constants.Collections.PersonsCollectionName));
        }