public void UpdateOpp() { var t = new Table(); t.Add(new Record(1, 2, 3)); t.Add(new Record("a", "b", 4)); var reader = new TestReader(new Tuple <int, char>(1, 'A'), "xyz"); var op = new UpdateOperation(t, reader); op.Execute(); Assert.AreEqual("xyz", t[1, 'A'].Str); reader = new TestReader(new Tuple <int, char>(2, 'B'), 100); op = new UpdateOperation(t, reader); op.Execute(); Assert.AreEqual(100, t[2, 'B'].Num); }
public override UpdateResult UpdateOne(FilterDefinition <TDocument> filter, UpdateDefinition <TDocument> update, UpdateOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { var documentsToUpdate = Filter(filter); var documentToUpdate = documentsToUpdate.FirstOrDefault(); if (documentToUpdate != null) { var updateDefenition = update.Render(BsonSerializer.LookupSerializer <TDocument>(), new BsonSerializerRegistry()); var operation = new UpdateOperation <TDocument>(documentToUpdate, updateDefenition, options); var updatedItem = operation.Execute().First(); _documents.Remove(documentToUpdate); _documents.Add(updatedItem); BsonValue objectId = null; try { objectId = documentToUpdate.GetElement("_id").Value; } catch { } return(new FakeUpdateResult(documentsToUpdate.Count(), objectId, 1)); } return(new FakeUpdateResult(0)); }
public void Update <T>(T entity) where T : class { UpdateOperation <T> operation = new UpdateOperation <T>(this); operation.Execute(entity); }