public void AddWithSameKeyReplaces() { var r1 = new Record { Id = "11", Name = "A" }; var r2 = new Record { Id = "11", Name = "B" }; mapper.Expect(m => m.ToDocument(Arg<Record>.Is.Same(r2), Arg<Document>.Is.NotNull)); session.Add(r1, r2); var pendingAdditions = session.ConvertPendingAdditions(); Verify(); Assert.That(pendingAdditions.Count(), Is.EqualTo(1)); }
public void Commit_Delete() { var q1 = new TermQuery(new Term("field1", "value1")); var q2 = new TermQuery(new Term("field1", "value2")); var r1 = new Record { Id = "12" }; var key = new DocumentKey(new Dictionary<IFieldMappingInfo, object> {{ new FakeFieldMappingInfo { FieldName = "Id"}, 12}}); session.Delete(r1); session.Delete(q1, q2); writer.Expect(w => w.DeleteDocuments(new[] {q1, q2, key.ToQuery(context.Analyzer, context.Version)})); writer.Expect(w => w.Commit()); session.Commit(); Assert.That(session.Deletions, Is.Empty, "Commit should clear pending deletions."); Verify(); }
public void Commit_Add_DeletesKey() { var key = new DocumentKey(new Dictionary<IFieldMappingInfo, object> { { new FakeFieldMappingInfo { FieldName = "Id" }, 1 } }); var record = new Record {Id = "1"}; session.Add(record); mapper.Expect(m => m.ToDocument(Arg<Record>.Is.Same(record), Arg<Document>.Is.NotNull)); writer.Expect(w => w.DeleteDocuments(new[] {key.ToQuery(context.Analyzer, context.Version)})); writer.Expect(w => w.AddDocument(Arg<Document>.Is.NotNull)); writer.Expect(w => w.Commit()); session.Commit(); Verify(); Assert.That(session.ConvertPendingAdditions, Is.Empty, "Commit should clear pending deletions."); }
public void Query_Attaches() { var records = new Record[0].AsQueryable(); var provider = MockRepository.GenerateStrictMock<IQueryProvider>(); var queryable = MockRepository.GenerateStrictMock<IQueryable<Record>>(); queryable.Expect(q => q.Provider).Return(provider); queryable.Expect(q => q.Expression).Return(Expression.Constant(records)); provider.Expect(p => p.CreateQuery<Record>(Arg<Expression>.Is.NotNull)).Return(records); session = new LuceneSession<Record>(mapper, context, queryable); session.Query(); queryable.VerifyAllExpectations(); provider.VerifyAllExpectations(); }
public void PendingChanges_DirtyDocuments() { var record = new Record(); var copy = new Record(); mapper.Expect(m => m.Equals(record, copy)).Return(false); mapper.Expect(m => m.ToDocument(Arg<Record>.Is.Same(record), Arg<Document>.Is.NotNull)); session.DocumentTracker.TrackDocument(record, copy); record.Id = "1"; session.StageModifiedDocuments(); Assert.That(session.PendingChanges, Is.True, "Should detect modified document."); }
public void Delete_SetsPendingChangesFlag() { var r1 = new Record { Id = "12" }; session.Delete(r1); Assert.That(session.PendingChanges, Is.True, "PendingChanges"); }
public void Delete_ThrowsOnEmptyKey() { mapper.BackToRecord(BackToRecordOptions.Expectations); mapper.Expect(m => m.ToKey(Arg<Record>.Is.NotNull)).Return(new DocumentKey()); var r1 = new Record { Id = "12" }; TestDelegate call = () => session.Delete(r1); Assert.That(call, Throws.InvalidOperationException); }
public void Delete() { var r1 = new Record { Id = "12" }; session.Delete(r1); Assert.That(session.Deletions.Single().ToString(), Is.EqualTo("+Id:12")); }
public void Delete_RemovesFromPendingAdditions() { var r1 = new Record { Id = "12" }; session.Add(r1); session.Delete(r1); Assert.That(session.Additions, Is.Empty); Assert.That(session.Deletions.Single().ToString(), Is.EqualTo("+Id:12")); }
public void Commit_Add_ConvertsDocumentAndKeyLate() { var record = new Record(); var key = new DocumentKey(new Dictionary<IFieldMappingInfo, object> { { new FakeFieldMappingInfo { FieldName = "Id" }, "biully" } }); var deleteQuery = key.ToQuery(context.Analyzer, Version.LUCENE_29); mapper.Expect(m => m.ToDocument(Arg<Record>.Is.Same(record), Arg<Document>.Is.NotNull)); writer.Expect(w => w.DeleteDocuments(new[] { deleteQuery })); writer.Expect(w => w.AddDocument(Arg<Document>.Is.NotNull));//Matches(doc => doc.GetValues("Name")[0] == "a name"))); writer.Expect(w => w.Commit()); session.Add(record); record.Id = "biully"; record.Name = "a name"; session.Commit(); Verify(); Assert.That(session.ConvertPendingAdditions, Is.Empty, "Commit should clear pending deletions."); }
public void DeleteAllClearsPendingAdditions() { var r1 = new Record(); session.Add(r1); session.DeleteAll(); Assert.That(session.ConvertPendingAdditions, Is.Empty, "Additions"); Verify(); }
public void Delete_MarkedForDeletion_ClearedOnRollback() { var r1 = new Record { Id = "12" }; session.Delete(r1); session.Rollback(); Assert.That(session.DocumentTracker.IsMarkedForDeletion(r1), Is.False, "IsMarkedForDeletion"); }
public void Delete_MarkedForDeletion() { var r1 = new Record { Id = "12" }; session.Delete(r1); Assert.That(session.DocumentTracker.IsMarkedForDeletion(r1), Is.True, "IsMarkedForDeletion"); }
public void PendingChanges_NoDirtyDocuments() { var record = new Record { Id = "1" }; var document = new Document(); document.Add(new Field("Id", "1", Field.Store.YES, Field.Index.NOT_ANALYZED)); var key = mapper.ToKey(record); detector.Expect(d => d.IsModified(record, document)).Return(false); mapper.Expect(m => m.ToDocument(Arg<Record>.Is.Same(record), Arg<Document>.Is.NotNull)); session.DocumentTracker.TrackDocument(key, record, document); session.StageModifiedDocuments(); Assert.That(session.PendingChanges, Is.False, "Should not stage unmodified document."); }
public void PendingChanges_DirtyDocuments() { var record = new Record { Id = "0" }; var document = new Document(); var key = mapper.ToKey(record); detector.Expect(d => d.IsModified(record, document)).Return(true); mapper.Expect(m => m.ToDocument(Arg<Record>.Is.Same(record), Arg<Document>.Is.NotNull)); session.DocumentTracker.TrackDocument(key, record, document); record.Id = "1"; session.StageModifiedDocuments(); Assert.That(session.PendingChanges, Is.True, "Should detect modified document."); }
public void Commit_Add_KeyConstraint_None_DoesNotDelete() { var record = new Record { Id = "1" }; session.Add(KeyConstraint.None, record); mapper.Expect(m => m.ToDocument(Arg<Record>.Is.Same(record), Arg<Document>.Is.NotNull)); writer.Expect(w => w.AddDocument(Arg<Document>.Is.NotNull)); writer.Expect(w => w.Commit()); session.Commit(); writer.AssertWasNotCalled(a => a.DeleteDocuments(Arg<Query[]>.Is.Anything)); Verify(); Assert.That(session.ConvertPendingAdditions, Is.Empty, "Commit should clear pending changes."); }