public void DoNotStoreSourceRoundtripException()
        {
            MappingSettings settings = new MappingSettings()
            {
                ObjectMapper  = new JsonObjectMapper(),
                StoreSettings = new StoreSettings()
                {
                    StoreSource = false,
                },
            };

            DateTime now = DateTime.Now;

            SimpleObject obj = new SimpleObject()
            {
                Id = Guid.NewGuid(),

                Text      = "This object's source is not stored in the index.",
                Timestamp = DateTime.UtcNow,
            };

            Document doc = obj.ToDocument(settings);

            Assert.NotNull(doc);

            try
            {
                doc.ToObject <SimpleObject>();
                Assert.Fail("Must get an exception.");
            }
            catch (InvalidOperationException ex)
            {
                Assert.AreEqual(
                    "Cannot convert the Document to an object of type <Lucene.Net.ObjectMapping.Tests.Model.SimpleObject>: The '$source' field is missing.",
                    ex.Message);
            }
        }
        public void DoNotStoreSource()
        {
            MappingSettings settings = new MappingSettings()
            {
                ObjectMapper  = new JsonObjectMapper(),
                StoreSettings = new StoreSettings()
                {
                    StoreSource = false,
                },
            };

            DateTime now = DateTime.Now;

            SimpleObject obj = new SimpleObject()
            {
                Id = Guid.NewGuid(),

                Text      = "This object's source is not stored in the index.",
                Timestamp = DateTime.UtcNow,
            };

            Document doc = obj.ToDocument(settings);

            Assert.NotNull(doc);
            int remainingFields = 3 /* total fields */;

            foreach (IIndexableField field in doc.Fields)
            {
                if (field.FieldType.IsStored)
                {
                    switch (field.Name)
                    {
                    case "$actualType":
                    case "$staticType":
                    case "$timestamp":
                        // These fields are all expected.
                        break;

                    case "$source":
                    default:
                        Assert.Fail("Unspected stored field: {0}", field.Name);
                        break;
                    }
                }
                else
                {
                    remainingFields--;

                    switch (field.Name)
                    {
                    case "Id":
                        Assert.False(field.FieldType.IsTokenized);
                        Assert.True(field.FieldType.IsIndexed);
                        Assert.AreEqual(obj.Id.ToString(), field.GetStringValue());
                        break;

                    case "Text":
                        Assert.True(field.FieldType.IsTokenized);
                        Assert.True(field.FieldType.IsIndexed);
                        Assert.AreEqual(obj.Text.ToString(), field.GetStringValue());
                        break;

                    case "Timestamp":
                        Assert.True(field.FieldType.IsTokenized);
                        Assert.True(field.FieldType.IsIndexed);
                        Assert.AreEqual(obj.Timestamp.Ticks.ToString(), field.GetStringValue());
                        break;

                    default:
                        Assert.Fail("Must get one of the expected fields.");
                        break;
                    }
                }
            }

            Assert.AreEqual(0, remainingFields);
        }