public void HashCode_NotEqualForDifferentKeys()
        {
            var key1 = new DocumentKey(new Dictionary<IFieldMappingInfo, object> { { new FakeFieldMappingInfo { FieldName = "id1" }, "**mykey**" } });
            var key2 = new DocumentKey(new Dictionary<IFieldMappingInfo, object> { { new FakeFieldMappingInfo { FieldName = "id2" }, "**mykey**" } });

            Assert.That(key1.GetHashCode(), Is.Not.EqualTo(key2.GetHashCode()));
        }
        public void EmptyKeys_NotEqual()
        {
            var key1 = new DocumentKey();
            var key2 = new DocumentKey();

            Assert.That(key1, Is.Not.EqualTo(key2));
        }
        public void HashCode_NullSafe()
        {
            var key = new DocumentKey(new Dictionary<IFieldMappingInfo, object> { { new FakeFieldMappingInfo { FieldName = "id1" }, null } });

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

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

            TestDelegate call = () => key.ToQuery(new LowercaseKeywordAnalyzer(), Version.LUCENE_29);

            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(new LowercaseKeywordAnalyzer(), Version.LUCENE_29);

            Assert.That(query.ToString(), Is.EqualTo("+id:**mykey**"));
        }
        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 bool Equals(DocumentKey other)
        {
            if (ReferenceEquals(null, other)) return false;
            if (ReferenceEquals(this, other)) return true;

            if (Empty) return false;

            return values.SequenceEqual(other.values);
        }
Esempio n. 8
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_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"));
        }
        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 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.");
        }
Esempio n. 13
0
        public void Commit_Add_DeletesAllKeys()
        {
            var key1 = new DocumentKey(new Dictionary<IFieldMappingInfo, object> { { new FakeFieldMappingInfo { FieldName = "Id" }, 1 } });
            var key2 = new DocumentKey(new Dictionary<IFieldMappingInfo, object> { { new FakeFieldMappingInfo { FieldName = "Id" }, 2 } });

            var records = new[] {
                new Record { Id = "1" },
                new Record { Id = "2" }
            };

            session.Add(records);

            mapper.Expect(m => m.ToDocument(Arg<Record>.Is.NotNull, Arg<Document>.Is.NotNull));
            writer.Expect(w => w.DeleteDocuments(new[] { key2.ToQuery(), key1.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 changes.");
        }