Lucene.Net.Index.TestBinaryDocValuesUpdates.TestUpdateNonBinaryDocValuesField C# (CSharp) Method

TestUpdateNonBinaryDocValuesField() private method

private TestUpdateNonBinaryDocValuesField ( ) : void
return void
        public virtual void TestUpdateNonBinaryDocValuesField()
        {
            // we don't support adding new fields or updating existing non-binary-dv
            // fields through binary updates
            Directory dir = NewDirectory();
            IndexWriterConfig conf = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random()));
            IndexWriter writer = new IndexWriter(dir, conf);

            Document doc = new Document();
            doc.Add(new StringField("key", "doc", Store.NO));
            doc.Add(new StringField("foo", "bar", Store.NO));
            writer.AddDocument(doc); // flushed document
            writer.Commit();
            writer.AddDocument(doc); // in-memory document

            try
            {
                writer.UpdateBinaryDocValue(new Term("key", "doc"), "bdv", ToBytes(17L));
                Assert.Fail("should not have allowed creating new fields through update");
            }
            catch (System.ArgumentException e)
            {
                // ok
            }

            try
            {
                writer.UpdateBinaryDocValue(new Term("key", "doc"), "foo", ToBytes(17L));
                Assert.Fail("should not have allowed updating an existing field to binary-dv");
            }
            catch (System.ArgumentException e)
            {
                // ok
            }

            writer.Dispose();
            dir.Dispose();
        }