public IEnumerable<Task> Can_perform_a_simple_where() { var dbname = GenerateNewDatabaseName(); var documentStore = new DocumentStore { Url = Url + Port }; documentStore.Initialize(); yield return documentStore.AsyncDatabaseCommands.EnsureDatabaseExistsAsync(dbname); var entity = new Company { Name = "Async Company #1", Id = "companies/1" }; using (var session = documentStore.OpenAsyncSession(dbname)) { session.Store(entity); yield return session.SaveChangesAsync(); } using (var session = documentStore.OpenAsyncSession(dbname)) { var query = session.Query<Company>() .Where(x => x.Name == "Async Company #1") .ToListAsync(); yield return query; Assert.AreEqual(1, query.Result.Count); Assert.AreEqual("Async Company #1", query.Result[0].Name); } }
public IEnumerable<Task> Can_get_total_count() { var dbname = GenerateNewDatabaseName(); var documentStore = new DocumentStore { Url = Url + Port }; documentStore.Initialize(); yield return documentStore.AsyncDatabaseCommands.EnsureDatabaseExistsAsync(dbname); var entity = new Company { Name = "Async Company #1", Id = "companies/1" }; using (var session = documentStore.OpenAsyncSession(dbname)) { session.Store(entity); yield return session.SaveChangesAsync(); } using (var session = documentStore.OpenAsyncSession(dbname)) { RavenQueryStatistics stats; var query = session.Query<Company>() .Customize(x=>x.WaitForNonStaleResults()) .Statistics(out stats) .Where(x => x.Name == "Async Company #1") .CountAsync(); yield return query; Assert.AreEqual(1, query.Result); } }
public IEnumerable<Task> Including_a_related_entity_should_avoid_hitting_the_server_twice() { var dbname = GenerateNewDatabaseName(); var documentStore = new DocumentStore { Url = Url + Port }; documentStore.Initialize(); yield return documentStore.AsyncDatabaseCommands.EnsureDatabaseExistsAsync(dbname); var customer = new Customer { Name = "Customer #1", Id = "customer/1", Email = "*****@*****.**" }; var order = new Order { Id = "orders/1", Note = "Hello", Customer = new DenormalizedReference { Id = customer.Id, Name = customer.Name } }; using (var session = documentStore.OpenAsyncSession(dbname)) { session.Store(customer); session.Store(order); yield return session.SaveChangesAsync(); } using (var session = documentStore.OpenAsyncSession(dbname)) { var query = session.Advanced.AsyncLuceneQuery<Order>() .Include(x => x.Customer.Id) .WhereEquals("Id", "orders/1") .QueryResultAsync; yield return query; Assert.Equal("Hello", query.Result.Results[0].Value<string>("Note")); // NOTE: this call should not hit the server var load = session.LoadAsync<Customer>(customer.Id); yield return load; Assert.Equal(1, session.Advanced.NumberOfRequests); } }
public IEnumerable<Task> Can_test_two_conditions_in_a_where_clause() { var dbname = GenerateNewDatabaseName(); var documentStore = new DocumentStore { Url = Url + Port }; documentStore.Initialize(); yield return documentStore.AsyncDatabaseCommands.EnsureDatabaseExistsAsync(dbname); using (var session = documentStore.OpenAsyncSession(dbname)) { session.Store(new Company { Name = "Async Company", Phone = 55555, Id = "companies/1" }); session.Store(new Company { Name = "Async Company", Phone = 12345, Id = "companies/2" }); yield return session.SaveChangesAsync(); } using (var session = documentStore.OpenAsyncSession(dbname)) { var query = session.Query<Company>() .Where(x => x.Name == "Async Company" && x.Phone == 12345) .ToListAsync(); yield return query; Assert.AreEqual(1, query.Result.Count); Assert.AreEqual(12345, query.Result[0].Phone); } }
internal override PreparedDatabaseCommand Prepare(DocumentStore store, Guid etag, int uniqueParameterIdentifier) { var values = ConvertAnonymousToProjections(table, projections); values[table.EtagColumn] = etag; values[table.ModifiedAtColumn] = DateTimeOffset.Now; var sql = new SqlBuilder() .Append("update {0} set {1} where {2}=@Id{3}", store.Database.FormatTableNameAndEscape(table.Name), string.Join(", ", from column in values.Keys select column.Name + "=@" + column.Name + uniqueParameterIdentifier), table.IdColumn.Name, uniqueParameterIdentifier) .Append(!lastWriteWins, "and {0}=@CurrentEtag{1}", table.EtagColumn.Name, uniqueParameterIdentifier) .ToString(); var parameters = MapProjectionsToParameters(values, uniqueParameterIdentifier); AddTo(parameters, "@Id" + uniqueParameterIdentifier, key, SqlTypeMap.Convert(table.IdColumn).DbType, null); if (!lastWriteWins) { AddTo(parameters, "@CurrentEtag" + uniqueParameterIdentifier, currentEtag, SqlTypeMap.Convert(table.EtagColumn).DbType, null); } return new PreparedDatabaseCommand { Sql = sql, Parameters = parameters.Values.ToList(), ExpectedRowCount = 1 }; }
public IEnumerable<Task> Can_delete_an_attachment() { var store = new DocumentStore {Url = Url + Port}; store.Initialize(); var dbname = GenerateNewDatabaseName(); yield return store.AsyncDatabaseCommands.EnsureDatabaseExistsAsync(dbname); const string someData = "The quick brown fox jumps over the lazy dog"; var encoding = new UTF8Encoding(); var bytes = encoding.GetBytes(someData); yield return store.AsyncDatabaseCommands .ForDatabase(dbname) .PutAttachmentAsync("123", Guid.Empty, bytes, null); yield return store.AsyncDatabaseCommands .ForDatabase(dbname) .DeleteAttachmentAsync("123", null); var get = store.AsyncDatabaseCommands .ForDatabase(dbname) .GetAttachmentAsync("123"); yield return get; Assert.AreEqual(null, get.Result); }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); WebApiConfig.Register(GlobalConfiguration.Configuration); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); var estore = new EventStore(); var dstore = new DocumentStore(); Action<Command> future = cmd => DiContainer.Current.CommandBus.Submit(cmd); DiContainer.Current = new DiContainer { Store = estore, DocumentStore = dstore, CommandBus = new CommandDispatcher( estore, e => estore.Store(e), future ), Projektor = new Projektor(estore, dstore) }; if (!estore.All.Any()) GenerateDemoData(estore); }
internal override PreparedDatabaseCommand Prepare(DocumentStore store, Guid etag, int uniqueParameterIdentifier) { var sql = new SqlBuilder() .Append("delete from {0} where {1} = @Id{2}", store.Database.FormatTableNameAndEscape(table.Name), table.IdColumn.Name, uniqueParameterIdentifier) .Append(!lastWriteWins, "and {0} = @CurrentEtag{1}", table.EtagColumn.Name, uniqueParameterIdentifier) .ToString(); var parameters = new Dictionary<string, Parameter>(); AddTo(parameters, "@Id" + uniqueParameterIdentifier, key, SqlTypeMap.Convert(table.IdColumn).DbType, null); if (!lastWriteWins) { AddTo(parameters, "@CurrentEtag" + uniqueParameterIdentifier, currentEtag, SqlTypeMap.Convert(table.EtagColumn).DbType, null); } return new PreparedDatabaseCommand { Sql = sql, Parameters = parameters.Values.ToList(), ExpectedRowCount = 1 }; }
internal override PreparedDatabaseCommand Prepare(DocumentStore store, Guid etag, int uniqueParameterIdentifier) { var name = string.Format("{0}_{1}_{2}.bak", design.DocumentType.FullName, key, version); writer.Write(name, document); return command.Prepare(store, etag, uniqueParameterIdentifier); }
public IEnumerable<Task> Should_not_cache_the_list_of_databases() { var documentStore = new DocumentStore { Url = Url + Port }; documentStore.Initialize(); var first = GenerateNewDatabaseName(); yield return documentStore.AsyncDatabaseCommands .EnsureDatabaseExistsAsync(first); var task = documentStore.AsyncDatabaseCommands .GetDatabaseNamesAsync(); yield return task; Assert.IsTrue(task.Result.Contains(first)); var second = GenerateNewDatabaseName(); yield return documentStore.AsyncDatabaseCommands .EnsureDatabaseExistsAsync(second); var verify = documentStore.AsyncDatabaseCommands .GetDatabaseNamesAsync(); yield return verify; Assert.IsTrue(verify.Result.Contains(second)); }
public IEnumerable<Task> Some_sample_data() { var store = new DocumentStore {Url = Url + Port}; store.Initialize(); using (var session = store.OpenAsyncSession()) { Enumerable.Range(0, 25).ToList() .ForEach(i => session.Store(new Company {Id = "Companies/" + i, Name = i.ToString()})); Enumerable.Range(0, 250).ToList() .ForEach(i => session.Store(new Order { Id = "Orders/" + i, Note = i.ToString() })); Enumerable.Range(0, 100).ToList() .ForEach(i => session.Store(new Customer { Name = "Joe " + i})); Enumerable.Range(0, 75).ToList() .ForEach(i => session.Store(new Contact { FirstName = "Bob" + i, Surname = i.ToString() + "0101001" })); session.Store(new Customer { Name = "Henry"}); session.Store(new Order { Note = "An order" }); session.Store(new Company {Name = "My Company"}); yield return session.SaveChangesAsync(); } }
public IEnumerable<Task> Can_insert_async_and_multi_get_async() { var dbname = GenerateNewDatabaseName(); var documentStore = new DocumentStore {Url = Url + Port}; documentStore.Initialize(); yield return documentStore.AsyncDatabaseCommands.EnsureDatabaseExistsAsync(dbname); var entity1 = new Company {Name = "Async Company #1"}; var entity2 = new Company {Name = "Async Company #2"}; using (var session_for_storing = documentStore.OpenAsyncSession(dbname)) { session_for_storing.Store(entity1); session_for_storing.Store(entity2); yield return session_for_storing.SaveChangesAsync(); } using (var session_for_loading = documentStore.OpenAsyncSession(dbname)) { var task = session_for_loading.MultiLoadAsync<Company>(new[] {entity1.Id, entity2.Id}); yield return task; Assert.Equal(entity1.Name, task.Result[0].Name); Assert.Equal(entity2.Name, task.Result[1].Name); } }
public IEnumerable<Task> Can_delete_an_index_async() { var dbname = GenerateNewDatabaseName(); var documentStore = new DocumentStore {Url = Url + Port}; documentStore.Initialize(); yield return documentStore.AsyncDatabaseCommands.EnsureDatabaseExistsAsync(dbname); yield return documentStore.AsyncDatabaseCommands .ForDatabase(dbname) .PutIndexAsync("Test", new IndexDefinition { Map = "from doc in docs.Companies select new { doc.Name }" }, true); var verify_put = documentStore.AsyncDatabaseCommands .ForDatabase(dbname) .GetIndexNamesAsync(0, 25); yield return verify_put; Assert.IsTrue(verify_put.Result.Contains("Test")); yield return documentStore.AsyncDatabaseCommands .ForDatabase(dbname) .DeleteIndexAsync("Test"); var verify_delete = documentStore.AsyncDatabaseCommands .ForDatabase(dbname) .GetIndexNamesAsync(0, 25); yield return verify_delete; //NOTE: this is failing because Silverlight is caching the response from the first verification Assert.IsFalse(verify_delete.Result.Contains("Test")); }
public void SetUp() { var path = Path.Combine(Environment.CurrentDirectory, GetType().Name + "Test"); EnsurePath(path); DocumentStore = new DocumentStore(path); }
public Replication() { var store = new DocumentStore(); DocumentConvention Conventions = store.Conventions; #region failover_behavior Conventions.FailoverBehavior = FailoverBehavior.AllowReadsFromSecondaries; #endregion #region cluster_failover_behavior Conventions.FailoverBehavior = FailoverBehavior.ReadFromAllWriteToLeader; #endregion #region replication_informer Conventions.ReplicationInformerFactory = (url, jsonRequestFactory, requestTimeMetricGetter) => new ReplicationInformer(Conventions, jsonRequestFactory, requestTimeMetricGetter); #endregion #region index_and_transformer_replication_mode Conventions.IndexAndTransformerReplicationMode = IndexAndTransformerReplicationMode.Indexes | IndexAndTransformerReplicationMode.Transformers; #endregion }
public Querying() { var store = new DocumentStore(); DocumentConvention Conventions = store.Conventions; #region find_prop_name Conventions.FindPropertyNameForIndex = (indexedType, indexName, path, prop) => (path + prop).Replace(",", "_").Replace(".", "_"); Conventions.FindPropertyNameForDynamicIndex = (indexedType, indexName, path, prop) => path + prop; #endregion #region querying_consistency Conventions.DefaultQueryingConsistency = ConsistencyOptions.None; #endregion #region querying_consistency_2 Conventions.DefaultQueryingConsistency = ConsistencyOptions.AlwaysWaitForNonStaleResultsAsOfLastWrite; #endregion #region apply_reduce_func Conventions.ApplyReduceFunction = (type, resultType, results, transformResults) => // carry out the reduction over results from different shards #endregion null; #region allow_queries_on_id Conventions.AllowQueriesOnId = false; #endregion }
public DtcTransactions() { var store = new DocumentStore(); using (var session = store.OpenSession()) { #region transaction_scope_usage using (var transaction = new TransactionScope()) { Employee employee = session.Load<Employee>("employees/1"); employee.FirstName = "James"; session.SaveChanges(); // will create HTTP request session.Delete(employee); session.SaveChanges(); // will create HTTP request transaction.Complete(); // will commit the transaction } #endregion } #region default_transaction_recovery_storage store.TransactionRecoveryStorage = new VolatileOnlyTransactionRecoveryStorage(); #endregion #region local_directory_transaction_recovery_storage store.TransactionRecoveryStorage = new LocalDirectoryTransactionRecoveryStorage(@"C:\tx_recovery_data"); #endregion }
public static void Configure(PhoneApplicationFrame rootFrame) { DocumentStore = new DocumentStore(); Container = new Container(); Container.Register<IDocumentStore>(c => new DocumentStore()); Container.Register<IBus>(c => new Bus(c)); Container.Register(c => new ActivityNewActivityHandler { Bus = c.Resolve<IBus>(), DocumentStore = DocumentStore }); Container.Register(c => new TestModeActivatedHandler { Bus = c.Resolve<IBus>() }); Container.Register(c => new ActivateTestModeHandler { Bus = c.Resolve<IBus>() }); Container.Register(c => new ClearCacheHandler { DocumentStore = c.Resolve<IDocumentStore>() }); Container.Register(c => new Contexts.Review.Domain.ClearCacheHandler { DocumentStore = c.Resolve<IDocumentStore>() }); var bus = Container.Resolve<IBus>(); bus.RegisterHandler<ActivityNewActivityHandler, NewActivityEvent>(); bus.RegisterHandler<TestModeActivatedHandler, TestModeActivatedEvent>(); bus.RegisterHandler<ActivateTestModeHandler, ActivateCommand>(); bus.RegisterHandler<Contexts.Settings.ClearCacheHandler, ClearCacheCommand>(); bus.RegisterHandler<Contexts.Review.Domain.ClearCacheHandler, ClearCacheCommand>(); Contexts.Import.Module.Configure(Container); Contexts.Import.ModuleUi.Configure(Container, rootFrame); Contexts.Review.Module.Confiure(Container); }
public WhatAreConventions() { var store = new DocumentStore(); #region conventions_1 DocumentConvention conventions = store.Conventions; #endregion }
void InitializeSession() { var store = new DocumentStore { Url = Address }; store.Initialize(); Session = store.OpenAsyncSession(); }
public ProjectionStore(string parentDirectory, IEnumerable<Projection> projections, DocumentStore documentStore) { return; _parentDirectory = parentDirectory; _documentStore = documentStore; _projections = projections.ToList(); _projections.ForEach(x => CollectionChanged(x.InputType)); documentStore.DocumentChanged += CollectionChanged; }
public void ShouldCreateADocumentStoreBackendFile() { Assert.IsFalse(File.Exists(storePath)); var store = new DocumentStore(storePath); store.Close(); Assert.IsTrue(File.Exists(storePath)); }
private static IDocumentStore CreateStore() { IDocumentStore store = new DocumentStore() { Url = "http://localhost:8080", DefaultDatabase = "Northwind" }.Initialize(); return store; }
public IEnumerable<Task> Can_retrieve_statistics_for_the_default_database() { var store = new DocumentStore { Url = Url + Port }; store.Initialize(); var getStats = store.AsyncDatabaseCommands .GetStatisticsAsync(); yield return getStats; Assert.IsNotNull(getStats.Result); }
public IEnumerable<Task> Can_get_a_list_of_databases_async() { var dbname = GenerateNewDatabaseName(); var documentStore = new DocumentStore { Url = Url + Port }; documentStore.Initialize(); yield return documentStore.AsyncDatabaseCommands.EnsureDatabaseExistsAsync(dbname); var task = documentStore.AsyncDatabaseCommands.GetDatabaseNamesAsync(); yield return task; Assert.IsTrue(task.Result.Contains(dbname)); }
public void SetUp() { ConfigureRavenPersistence.AutoCreateDatabase = false; var config = Configure.With(new[] { GetType().Assembly }) .DefineEndpointName("UnitTests") .DefaultBuilder(); Initialize(config); store = config.Builder.Build<IDocumentStore>() as DocumentStore; }
public CreatingDocumentStore() { #region document_store_creation using (IDocumentStore store = new DocumentStore() { Url = "http://localhost:8080" }.Initialize()) { } #endregion }
public BewareOf() { var store = new DocumentStore(); using (var session = store.OpenSession()) { #region session_value_types Employee employee = session.Load<Employee>(9); // get "employees/9" session.Delete<Employee>(12); // delete "employees/12" #endregion } }
public void CreateDbAndLoad() { const string DbName = "CreationTest"; using (var documentStore = new DocumentStore { Url = "http://localhost:8080/databases/" + DbName }.Initialize()) { documentStore.DatabaseCommands.EnsureDatabaseExists(DbName); using (var session = documentStore.OpenSession()) { session.Load<Order>("1"); } } }
public CustomizeCollectionAssignmentForEntities() { var store = new DocumentStore(); #region custom_collection_name store.Conventions.FindTypeTagName = type => { if (typeof(Category).IsAssignableFrom(type)) return "ProductGroups"; return DocumentConvention.DefaultTypeTagName(type); }; #endregion }