Ejemplo n.º 1
0
        public void can_generate_a_computed_index()
        {
            using (var store = TestingDocumentStore.Basic())
            {
                store.Schema.EnsureStorageExists(typeof(User));

                var mapping = store.Schema.MappingFor(typeof(User));
                var sql     = mapping.As <DocumentMapping>().FieldFor(nameof(User.UserName)).As <JsonLocatorField>().ToComputedIndex(mapping.Table)
                              .Replace("d.data", "data");

                using (var conn = store.Advanced.OpenConnection())
                {
                    conn.Execute(cmd => cmd.Sql(sql).ExecuteNonQuery());
                }

                using (var session = store.OpenSession())
                {
                    var query =
                        session.Query <User>()
                        .Where(x => x.UserName == "hank")
                        .ToCommand(FetchType.FetchMany)
                        .CommandText;

                    _output.WriteLine(query);

                    var plan = session.Query <User>().Where(x => x.UserName == "hank").Explain();
                    _output.WriteLine(plan.ToString());
                }
            }
        }
Ejemplo n.º 2
0
        public void read_as_text_reader()
        {
            using (var store = TestingDocumentStore.Basic())
            {
                var target = Target.Random(true);

                using (var session = store.OpenSession())
                {
                    session.Store(target);
                    session.SaveChanges();
                }

                using (var conn = store.Advanced.OpenConnection())
                {
                    var json = conn.Execute(cmd =>
                    {
                        using (var reader = cmd.Sql("select data from mt_doc_target").ExecuteReader())
                        {
                            reader.Read();
                            return(reader.GetTextReader(0).ReadToEnd());
                        }
                    });

                    Console.WriteLine(json);
                }
            }
        }
Ejemplo n.º 3
0
        public MartenRegistryTests()
        {
            var storeOptions = new StoreOptions();

            storeOptions.Schema.Include <TestRegistry>();

            var store = TestingDocumentStore.For(_ => _.Schema.Include <TestRegistry>());

            theStorage = store.Storage;
        }
Ejemplo n.º 4
0
 protected void StoreOptions(Action <StoreOptions> configure)
 {
     _store = new Lazy <IDocumentStore>(() => TestingDocumentStore.For(_ =>
     {
         if (EnableCommandLogging)
         {
             _.Logger(new TestOutputMartenLogger(_output));
         }
         configure(_);
     }));
 }
Ejemplo n.º 5
0
 public void fetch_index_definitions()
 {
     using (var store = TestingDocumentStore.For(_ =>
     {
         _.Schema.For <User>().Duplicate(x => x.UserName);
     }))
     {
         store.BulkInsert(new User[] { new User {
                                           UserName = "******"
                                       }, new User {
                                           UserName = "******"
                                       }, });
     }
 }
Ejemplo n.º 6
0
        public new static IDocumentStore For(Action<StoreOptions> configure)
        {
            var options = new StoreOptions();
            options.Connection(ConnectionSource.ConnectionString);
            options.Serializer<TestsSerializer>();


            configure(options);

            

            var store = new TestingDocumentStore(options);
            store.Advanced.Clean.CompletelyRemoveAll();

            return store;
        }
Ejemplo n.º 7
0
        protected IntegratedFixture(ITestOutputHelper output = null)
        {
            _output = output;
            _store  = new Lazy <IDocumentStore>(() => TestingDocumentStore.Basic(EnableCommandLogging ? _output : null));

            if (GetType().GetTypeInfo().GetCustomAttribute <CollectionAttribute>(true) != null)
            {
                UseDefaultSchema();
            }

#if NET46
            _originalCulture = Thread.CurrentThread.CurrentCulture;
            Thread.CurrentThread.CurrentCulture   = new CultureInfo("en-US");
            Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
#endif
        }
Ejemplo n.º 8
0
        public new static IDocumentStore For(Action <StoreOptions> configure)
        {
            var options = new StoreOptions();

            options.Connection(ConnectionSource.ConnectionString);
            options.Serializer <JilSerializer>();


            configure(options);



            var store = new TestingDocumentStore(options);

            store.Advanced.Clean.CompletelyRemoveAll();

            return(store);
        }
Ejemplo n.º 9
0
        public new static IDocumentStore For(Action<StoreOptions> configure)
        {
            var options = new StoreOptions();
            options.Connection(ConnectionSource.ConnectionString);

            lock (_locker)
            {
                //options.DatabaseSchemaName = "Test_" + SchemaCount++;
            }
            

            configure(options);

            var store = new TestingDocumentStore(options);
            store.Advanced.Clean.CompletelyRemoveAll();

            return store;
        }
Ejemplo n.º 10
0
        public new static DocumentStore For(Action <StoreOptions> configure)
        {
            var options = new StoreOptions();

            options.Connection(ConnectionSource.ConnectionString);
            options.Serializer <TestsSerializer>();
            options.AutoCreateSchemaObjects = AutoCreate.All;
            options.NameDataLength          = 100;

            configure(options);



            var store = new TestingDocumentStore(options);

            store.Advanced.Clean.CompletelyRemoveAll();

            return(store);
        }
        public void persist_and_reload_a_document_using_buffers()
        {
            var user = new User {
                FirstName = "James", LastName = "Worthy"
            };

            using (var store = TestingDocumentStore.For(_ => { _.UseCharBufferPooling = true; }))
            {
                using (var session1 = store.OpenSession())
                {
                    session1.Store(user);
                    session1.SaveChanges();
                }

                using (var session2 = store.OpenSession())
                {
                    var user2 = session2.Load <User>(user.Id);

                    user.ShouldNotBeSameAs(user2);
                    user2.FirstName.ShouldBe(user.FirstName);
                    user2.LastName.ShouldBe(user.LastName);
                }
            }
        }
        public async Task persist_and_reload_a_document_async_using_buffers()
        {
            var user = new User {
                FirstName = "James", LastName = "Worthy"
            };

            using (var store = TestingDocumentStore.For(_ => { _.UseCharBufferPooling = true; }))
            {
                using (var session1 = store.OpenSession())
                {
                    session1.Store(user);
                    await session1.SaveChangesAsync().ConfigureAwait(false);
                }

                using (var session2 = store.OpenSession())
                {
                    var user2 = await session2.LoadAsync <User>(user.Id).ConfigureAwait(false);

                    user.ShouldNotBeSameAs(user2);
                    user2.FirstName.ShouldBe(user.FirstName);
                    user2.LastName.ShouldBe(user.LastName);
                }
            }
        }
Ejemplo n.º 13
0
 protected void UseDefaultSchema()
 {
     _store = new Lazy <IDocumentStore>(() => TestingDocumentStore.DefaultSchema(EnableCommandLogging ? _output : null));
 }
Ejemplo n.º 14
0
 protected void StoreOptions(Action <StoreOptions> configure)
 {
     _store = new Lazy <IDocumentStore>(() => TestingDocumentStore.For(configure));
 }