Exemplo n.º 1
0
        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() }));
            writer.Expect(w => w.Commit());

            session.Commit();

            Assert.That(session.Deletions, Is.Empty, "Commit should clear pending deletions.");

            Verify();
        }
Exemplo n.º 2
0
        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() }));
            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.");
        }
Exemplo n.º 3
0
        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();

            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 ToQuery_ThrowsOnBlankValue()
        {
            var key = new DocumentKey(new Dictionary <IFieldMappingInfo, object> {
                { new FakeFieldMappingInfo {
                      FieldName = "id"
                  }, "" }
            });

            TestDelegate call = () => key.ToQuery();

            Assert.That(call, Throws.InvalidOperationException);
        }
        public void ToQuery_EscapesSpecialCharacters()
        {
            var key = new DocumentKey(new Dictionary <IFieldMappingInfo, object> {
                { new FakeFieldMappingInfo {
                      FieldName = "id"
                  }, "**mykey**" }
            });

            var query = key.ToQuery();

            Assert.That(query.ToString(), Is.EqualTo("+id:**mykey**"));
        }
Exemplo n.º 6
0
        public void ToQuery()
        {
            var key = new DocumentKey(new Dictionary <IFieldMappingInfo, object> {
                { new FakeFieldMappingInfo {
                      FieldName = "id"
                  }, "some value" }
            });

            var query = key.ToQuery();

            Assert.That(query.ToString(), Is.EqualTo("+id:some value"));
        }
        public void ToQuery()
        {
            var key = new DocumentKey(new Dictionary <IFieldMappingInfo, object>
            {
                { new FakeFieldMappingInfo {
                      FieldName = "id"
                  }, "AnalyzeThis" }
            });

            var query = key.ToQuery(new LowercaseKeywordAnalyzer(), Version.LUCENE_29);

            Assert.That(query.ToString(), Is.EqualTo("+id:analyzethis"));
        }
        public void ToQuery_ConvertsComplexTypes()
        {
            var customValue = new object();
            var mapping     = MockRepository.GenerateStub <IFieldMappingInfo>();

            mapping.Expect(m => m.FieldName).Return("id");
            mapping.Expect(m => m.ConvertToQueryExpression(customValue)).Return("custom*value*as*string");
            var key = new DocumentKey(new Dictionary <IFieldMappingInfo, object> {
                { mapping, customValue }
            });

            var query = key.ToQuery(new LowercaseKeywordAnalyzer(), Version.LUCENE_29);

            Assert.That(query.ToString(), Is.EqualTo("+id:custom*value*as*string"));
        }