public void SuccessTest1() { using (IDocumentStore documentStore = new EmbeddableDocumentStore { RunInMemory = true }.Initialize()) { dynamic expando = new ExpandoObject(); using (IDocumentSession session = documentStore.OpenSession()) { session.Store(expando); JObject metadata = session.Advanced.GetMetadataFor((ExpandoObject)expando); metadata[PropertyName] = JToken.FromObject(true); session.SaveChanges(); } using (IDocumentSession session = documentStore.OpenSession()) { var loaded = session.Load<dynamic>((string)expando.Id); JObject metadata = session.Advanced.GetMetadataFor((DynamicJsonObject)loaded); JToken token = metadata[PropertyName]; Assert.NotNull(token); Assert.True(token.Value<bool>()); } } }
public void SuccessTest2() { using (IDocumentStore documentStore = new EmbeddableDocumentStore { RunInMemory = true }.Initialize()) { dynamic expando = new ExpandoObject(); using (IDocumentSession session = documentStore.OpenSession()) { session.Store(expando); JObject metadata = session.Advanced.GetMetadataFor((ExpandoObject)expando); metadata[PropertyName] = JToken.FromObject(true); session.SaveChanges(); } using (IDocumentSession session = documentStore.OpenSession()) { dynamic loaded = session.Advanced.LuceneQuery<dynamic>() .WhereEquals("@metadata.Raven-Entity-Name", documentStore.Conventions.GetTypeTagName(typeof(ExpandoObject))) .FirstOrDefault(); Assert.NotNull(loaded); } } }
public void AllArchetypesShouldBeAbleToBeStored() { var store = new EmbeddableDocumentStore() { RunInMemory = true }; store.Initialize(); int count; using (new DocumentSessionScope(store.OpenSession())) { var archetypeRepository = new ArchetypeRepository(); count = Directory.GetFiles(@"Archetypes\xml\", "*.xml").ToList().Count; foreach (var file in Directory.GetFiles(@"Archetypes\xml\", "*.xml")) { Debug.WriteLine(file); var archetypeString = File.ReadAllText(file); var archetype = new ArchetypeXmlParser().Parse(archetypeString); archetypeRepository.Save(archetype); } } using (var session = store.OpenSession()) { var result = session.Advanced.LuceneQuery<Archetype>().WaitForNonStaleResults().Take(count).ToList(); var ravenCount = result.Count(); Assert.AreEqual(count, ravenCount); } }
public void CanPassOperationHeadersUsingEmbedded() { using (var documentStore = new EmbeddableDocumentStore { Configuration = new RavenConfiguration { Catalog = { Catalogs = { new TypeCatalog(typeof(RecordOperationHeaders)) } }, DataDirectory = path, RunInUnreliableYetFastModeThatIsNotSuitableForProduction = true } }.Initialize()) { RecordOperationHeaders.Hello = null; using(var session = documentStore.OpenSession()) { session.Advanced.DatabaseCommands.OperationsHeaders["Hello"] = "World"; session.Store(new { Bar = "foo"}); session.SaveChanges(); Assert.Equal("World", RecordOperationHeaders.Hello); } } }
public void WillNotSerializeEvents() { IOExtensions.DeleteDirectory("Data"); try { using (var documentStore = new EmbeddableDocumentStore()) { documentStore.Configuration.DataDirectory = "Data"; documentStore.Conventions.CustomizeJsonSerializer = x => x.TypeNameHandling = TypeNameHandling.Auto; documentStore.Initialize(); var bar = new Bar(); var foo = new Foo(); foo.PropertyChanged += bar.FooChanged; using (var session = documentStore.OpenSession()) { session.Store(foo); session.SaveChanges(); } } } finally { IOExtensions.DeleteDirectory("Data"); } }
public void Can_Store_and_Load_Dynamic_Documents() { //When running in the XUnit GUI strange things happen is we just create a path relative to //the .exe itself, so make our folder in the System temp folder instead ("<user>\AppData\Local\Temp") string directoryName = Path.Combine(Path.GetTempPath(), "ravendb.RavenDynamicDocs"); IOExtensions.DeleteDirectory(directoryName); dynamic person = new CustomDynamicClass(); person.FirstName = "Ellen"; person.LastName = "Adams"; dynamic employee = new ExpandoObject(); employee.Name = "John Smith"; employee.Age = 33; employee.Phones = new ExpandoObject(); employee.Phones.Home = "0111 123123"; employee.Phones.Office = "0772 321123"; employee.Prices = new List<decimal>() { 123.4M, 123432.54M }; using (var db = new EmbeddableDocumentStore() { DataDirectory = directoryName }) { db.Initialize(); using (var session = db.OpenSession()) { session.Store(employee); string idEmployee = employee.Id; session.Store(person); string idPerson = person.Id; //Check that a field called "Id" is added to the dynamic object (as it doesn't already exist) //and that it has something in it (not null and not empty) Assert.False(String.IsNullOrEmpty(idEmployee)); Assert.False(String.IsNullOrEmpty(idPerson)); session.SaveChanges(); session.Advanced.Clear(); //Pull the docs back out of RavenDB and see if the values are the same dynamic employeeLoad = session.Load<object>(idEmployee); Assert.Equal("John Smith", employeeLoad.Name); Assert.Equal("0111 123123", employeeLoad.Phones.Home); Assert.Equal("0772 321123", employeeLoad.Phones.Office); Assert.Contains(123.4D, employeeLoad.Prices); Assert.Contains(123432.54D, employeeLoad.Prices); Assert.IsType<DynamicNullObject>(employeeLoad.Address); dynamic personLoad = session.Load<object>(idPerson); Assert.Equal("Ellen", personLoad.FirstName); Assert.Equal("Adams", personLoad.LastName); Assert.IsType<DynamicNullObject>(personLoad.Age); } } }
public void Can_perform_Skip_Take_Query() { using (var db = new EmbeddableDocumentStore() { DataDirectory = directoryName }) { db.Initialize(); string indexName = "UserIndex"; using (var session = db.OpenSession()) { AddData(session); db.DatabaseCommands.DeleteIndex(indexName); db.DatabaseCommands.PutIndex<User, User>(indexName, new IndexDefinition<User, User>() { Map = docs => from doc in docs select new { doc.Name, doc.Age }, SortOptions = {{x=>x.Name, SortOptions.StringVal}} }, true); WaitForQueryToComplete(session, indexName); var allResults = session.Query<User>(indexName).OrderBy(x => x.Name) .Where(x => x.Age > 0); Assert.Equal(4, allResults.ToArray().Count()); var takeResults = session.Query<User>(indexName).OrderBy(x => x.Name) .Where(x => x.Age > 0) .Take(3); //There are 4 items of data in the db, but using Take(1) means we should only see 4 Assert.Equal(3, takeResults.ToArray().Count()); var skipResults = session.Query<User>(indexName).OrderBy(x => x.Name) .Where(x => x.Age > 0) .Skip(1); //Using Skip(1) means we should only see the last 3 Assert.Equal(3, skipResults.ToArray().Count()); Assert.DoesNotContain(firstUser, skipResults.ToArray()); var skipTakeResults = session.Query<User>(indexName).OrderBy(x => x.Name) .Where(x => x.Age > 0) .Skip(1) .Take(2); //Using Skip(1), Take(2) means we shouldn't see the 1st or 4th (last) users Assert.Equal(2, skipTakeResults.ToArray().Count()); Assert.DoesNotContain<User>(firstUser, skipTakeResults.ToArray()); Assert.DoesNotContain<User>(lastUser, skipTakeResults.ToArray()); } } }
public void AndEntirelyInMemoryForUberFastTestingHAHAHAHA() { // Application start-up IDocumentStore store = new EmbeddableDocumentStore() { Configuration = new Raven.Database.RavenConfiguration() { RunInMemory = true } }; store.Initialize(); // Per unit of work using (var session = store.OpenSession()) { } }
public void AndICanAlsoCanRunInProcess() { // Application start-up IDocumentStore store = new EmbeddableDocumentStore() { Configuration = new Raven.Database.RavenConfiguration() { DataDirectory = "Data" } }; store.Initialize(); // Per unit of work using (var session = store.OpenSession()) { } }
public static void Main(string[] args) { Flickr flickr = new Flickr(); // PRIVATE KEY REMOVED var documentStore = new EmbeddableDocumentStore { Configuration = new RavenConfiguration { DataDirectory = RAVENPATH, } }; documentStore.Initialize(); using (var session = documentStore.OpenSession()) { PerformInitialSetup(session); session.Advanced.DatabaseCommands.DeleteByIndex("Raven/DocumentsByEntityName", new Raven.Database.Data.IndexQuery() { Query = "Tag:Images" }, true); FlickrImporter importer = new FlickrImporter(session, new ImageUploaderService( new RavenFileStorageService(documentStore), new ImageRepository(session)), new UserRepository(session)); importer.ImportSearchResults(flickr, IdUtil.CreateUserId("robashton"), "dog"); importer.ImportSearchResults(flickr, IdUtil.CreateUserId("robashton"), "swan"); importer.ImportSearchResults(flickr, IdUtil.CreateUserId("robashton"), "computer"); importer.ImportSearchResults(flickr, IdUtil.CreateUserId("robashton"), "megaman"); importer.ImportSearchResults(flickr, IdUtil.CreateUserId("robashton"), "rainbow"); importer.ImportSearchResults(flickr, IdUtil.CreateUserId("robashton"), "sunset"); importer.ImportSearchResults(flickr, IdUtil.CreateUserId("robashton"), "raven"); importer.ImportSearchResults(flickr, IdUtil.CreateUserId("robashton"), "coffee"); importer.ImportSearchResults(flickr, IdUtil.CreateUserId("robashton"), "jumper"); } while (documentStore.DocumentDatabase.Statistics.StaleIndexes.Length > 0) { Thread.Sleep(1000); Console.WriteLine("Waiting for indexing to complete"); } }
public void Can_perform_First_and_FirstOrDefault_Query() { using (var db = new EmbeddableDocumentStore() { DataDirectory = directoryName }) { db.Initialize(); string indexName = "UserIndex"; using (var session = db.OpenSession()) { AddData(session); db.DatabaseCommands.DeleteIndex(indexName); var result = db.DatabaseCommands.PutIndex<User, User>(indexName, new IndexDefinition<User, User>() { Map = docs => from doc in docs select new { doc.Name, doc.Age }, SortOptions = {{x=>x.Name, SortOptions.StringVal}} }, true); WaitForQueryToComplete(session, indexName); var firstItem = session.Query<User>(indexName).OrderBy(x=>x.Name) .First(); Assert.Equal(firstUser, firstItem); //This should pull out the 1st parson ages 60, i.e. "Bob" var firstAgeItem = session.Query<User>(indexName) .First(x => x.Age == 60); Assert.Equal("Bob", firstAgeItem.Name); //No-one is aged 15, so we should get null var firstDefaultItem = session.Query<User>(indexName) .FirstOrDefault(x => x.Age == 15); Assert.Null(firstDefaultItem); } } }
[Fact] // See issue #91 http://github.com/ravendb/ravendb/issues/issue/91 and //discussion here http://groups.google.com/group/ravendb/browse_thread/thread/3df57d19d41fc21 public void Can_do_projection_in_query_result() { using (var store = new EmbeddableDocumentStore() { DataDirectory = directoryName }) { store.Initialize(); store.DatabaseCommands.PutIndex("ByLineCost", new IndexDefinition { Map = @"from order in docs.Orders from line in order.Lines select new { Cost = line.Cost }", Stores = { { "Cost", FieldStorage.Yes } } }); using (var s = store.OpenSession()) { s.Store(new Order { Lines = new List<OrderItem> { new OrderItem { Cost = 1.59m, Quantity = 5 }, new OrderItem { Cost = 7.59m, Quantity = 3 } }, }); s.Store(new Order { Lines = new List<OrderItem> { new OrderItem { Cost = 0.59m, Quantity = 9 }, }, }); s.SaveChanges(); } using (var s = store.OpenSession()) { //Just issue a blank query to make sure there are no stale results WaitForQueryToComplete(s, "ByLineCost"); //This is the lucene query we want to mimic var luceneResult = s.Advanced.LuceneQuery<OrderItem>("ByLineCost") .Where("Cost_Range:{Dx1 TO NULL}") .SelectFields<SomeDataProjection>("Cost") .ToArray(); var projectionResult = s.Query<OrderItem>("ByLineCost") .Where(x => x.Cost > 1) .Select(x => new SomeDataProjection { Cost = x.Cost }) .ToArray(); Assert.Equal(luceneResult.Count(), projectionResult.Count()); int counter = 0; foreach (var item in luceneResult) { Assert.Equal(item.Cost, projectionResult[counter].Cost); counter++; } } } }
[Fact] // See issue #145 (http://github.com/ravendb/ravendb/issues/#issue/145) public void Can_use_inequality_to_compare_dates() { using (var db = new EmbeddableDocumentStore() { DataDirectory = directoryName }) { db.Initialize(); db.DatabaseCommands.PutIndex("DateTime", new IndexDefinition { Map = @"from info in docs.DateTimeInfos select new { info.TimeOfDay }", }); var currentTime = DateTime.Now; using (var s = db.OpenSession()) { s.Store(new DateTimeInfo { TimeOfDay = currentTime + TimeSpan.FromHours(1) }); s.Store(new DateTimeInfo { TimeOfDay = currentTime + TimeSpan.FromHours(2) }); s.Store(new DateTimeInfo { TimeOfDay = currentTime + TimeSpan.FromMinutes(1) }); s.Store(new DateTimeInfo { TimeOfDay = currentTime + TimeSpan.FromSeconds(10) }); s.SaveChanges(); } using (var s = db.OpenSession()) { //Just issue a blank query to make sure there are no stale results var test = s.Query<DateTimeInfo>("DateTime") .Customize(x => x.WaitForNonStaleResults()) .Where(x => x.TimeOfDay > currentTime) .ToArray(); Assert.Empty(s.Query<DateTimeInfo>("DateTime").Where(x => x.TimeOfDay != DateTime.MinValue)); } } }
[Fact] // See issue #145 (http://github.com/ravendb/ravendb/issues/#issue/145) public void Can_Use_Static_Fields_In_Where_Clauses() { using (var db = new EmbeddableDocumentStore() { DataDirectory = directoryName }) { db.Initialize(); db.DatabaseCommands.PutIndex("DateTime", new IndexDefinition { Map = @"from info in docs.DateTimeInfos select new { info.TimeOfDay }", }); var currentTime = DateTime.Now; using (var s = db.OpenSession()) { s.Store(new DateTimeInfo { TimeOfDay = currentTime + TimeSpan.FromHours(1) }); s.Store(new DateTimeInfo { TimeOfDay = currentTime + TimeSpan.FromHours(2) }); s.Store(new DateTimeInfo { TimeOfDay = currentTime + TimeSpan.FromMinutes(1) }); s.Store(new DateTimeInfo { TimeOfDay = currentTime + TimeSpan.FromSeconds(10) }); s.SaveChanges(); } using (var s = db.OpenSession()) { //Just issue a blank query to make sure there are no stale results var test = s.Query<DateTimeInfo>("DateTime") .Customize(x => x.WaitForNonStaleResults()) .Where(x => x.TimeOfDay > currentTime) .ToArray(); IQueryable<DateTimeInfo> testFail = null; Assert.DoesNotThrow(() => { testFail = s.Query<DateTimeInfo>("DateTime").Where(x => x.TimeOfDay > DateTime.MinValue); // =====> Throws an exception }); Assert.NotEqual(null, testFail); var dt = DateTime.MinValue; var testPass = s.Query<DateTimeInfo>("DateTime").Where(x => x.TimeOfDay > dt); //=====>Works Assert.Equal(testPass.Count(), testFail.Count()); } } }
[Fact] // See issue #105 (http://github.com/ravendb/ravendb/issues/#issue/105) public void Does_Not_Ignore_Expressions_Before_Where() { using (var db = new EmbeddableDocumentStore() { DataDirectory = directoryName }) { db.Initialize(); string indexName = "UserIndex"; using (var session = db.OpenSession()) { session.Store(new User() { Name = "Third", Age = 18}); session.Store(new User() { Name = "First" , Age = 10}); session.Store(new User() { Name = "Second", Age = 20}); session.SaveChanges(); db.DatabaseCommands.DeleteIndex(indexName); db.DatabaseCommands.PutIndex<User, User>(indexName, new IndexDefinition<User, User>() { Map = docs => from doc in docs select new { doc.Name, doc.Age }, }, true); WaitForQueryToComplete(session, indexName); var result = session.Query<User>(indexName).OrderBy(x => x.Name).Where(x => x.Age >= 18).ToList(); Assert.Equal(2, result.Count()); Assert.Equal("Second", result[0].Name); Assert.Equal("Third", result[1].Name); } } }
public void Can_perform_DateTime_Comparison_Queries() { DateTime firstTime = DateTime.UtcNow; DateTime secondTime = firstTime.AddMonths(1); // use .AddHours(1) to get a second bug, timezone related DateTime thirdTime = secondTime.AddMonths(1); // use .AddHours(1) to get a second bug, timezone related using (var db = new EmbeddableDocumentStore() { DataDirectory = directoryName }) { db.Initialize(); string indexName = "UserIndex"; using (var session = db.OpenSession()) { session.Store(new User { Name = "First", Created = firstTime }); session.Store(new User { Name = "Second", Created = secondTime}); session.Store(new User { Name = "Third", Created = thirdTime}); session.SaveChanges(); db.DatabaseCommands.DeleteIndex(indexName); var result = db.DatabaseCommands.PutIndex<User, User>(indexName, new IndexDefinition<User, User>() { Map = docs => from doc in docs select new { doc.Name, doc.Created }, }, true); WaitForQueryToComplete(session, indexName); Assert.Equal(3, session.Query<User>(indexName).ToArray().Length); var testQuery = session.Query<User>(indexName) .Where(x => x.Created > secondTime) .ToArray(); Assert.Equal(1, testQuery.Count()); Assert.True(testQuery.Select(q => q.Name).Contains("Third")); testQuery = session.Query<User>(indexName) .Where(x => x.Created >= secondTime) .ToArray(); Assert.Equal(2, testQuery.Count()); Assert.True(testQuery.Select(q => q.Name).Contains("Third")); Assert.True(testQuery.Select(q => q.Name).Contains("Second")); testQuery = session.Query<User>(indexName) .Where(x => x.Created < secondTime) .ToArray(); Assert.Equal(1, testQuery.Count()); Assert.True(testQuery.Select(q => q.Name).Contains("First")); testQuery = session.Query<User>(indexName) .Where(x => x.Created <= secondTime) .ToArray(); Assert.Equal(2, testQuery.Count()); Assert.True(testQuery.Select(q => q.Name).Contains("First")); Assert.True(testQuery.Select(q => q.Name).Contains("Second")); testQuery = session.Query<User>(indexName) .Where(x => x.Created == secondTime) .ToArray(); Assert.Equal(1, testQuery.Count()); Assert.True(testQuery.Select(q => q.Name).Contains("Second")); } } }
public void Can_perform_Boolean_Queries() { using (var db = new EmbeddableDocumentStore() { DataDirectory = directoryName }) { db.Initialize(); string indexName = "UserIndex"; using (var session = db.OpenSession()) { session.Store(new User() { Name = "Matt", Info = "Male Age 25" }); //Active = false by default session.Store(new User() { Name = "Matt", Info = "Male Age 28", Active = true }); session.Store(new User() { Name = "Matt", Info = "Male Age 35", Active = false }); session.SaveChanges(); db.DatabaseCommands.DeleteIndex(indexName); var result = db.DatabaseCommands.PutIndex<User, User>(indexName, new IndexDefinition<User, User>() { Map = docs => from doc in docs select new { doc.Name, doc.Age, doc.Info, doc.Active }, Indexes = {{x=>x.Name, FieldIndexing.Analyzed}} }, true); WaitForQueryToComplete(session, indexName); var testQuery = session.Query<User>(indexName) .Where(x => x.Name.Contains("Matt") && x.Active); Assert.Equal(1, testQuery.ToArray().Count()); foreach (var testResult in testQuery) Assert.True(testResult.Active); testQuery = session.Query<User>(indexName) .Where(x => x.Name.Contains("Matt") && !x.Active); Assert.Equal(2, testQuery.ToArray().Count()); foreach (var testResult in testQuery) Assert.False(testResult.Active); } } }
public void Can_Use_Where() { //When running in the XUnit GUI strange things happen is we just create a path relative to //the .exe itself, so make our folder in the System temp folder instead ("<user>\AppData\Local\Temp") string directoryName = Path.Combine(Path.GetTempPath(), "ravendb.RavenWhereTests"); IOExtensions.DeleteDirectory(directoryName); using (var db = new EmbeddableDocumentStore() { DataDirectory = directoryName }) { db.Initialize(); string indexName = "CommitByRevision"; using (var session = db.OpenSession()) { AddData(session); db.DatabaseCommands.DeleteIndex(indexName); var result = db.DatabaseCommands.PutIndex<CommitInfo, CommitInfo>(indexName, new IndexDefinition<CommitInfo, CommitInfo>() { Map = docs => from doc in docs select new { doc.Revision}, }, true); WaitForQueryToComplete(session, indexName); var Results = session.Query<CommitInfo>(indexName) .Where(x => x.Revision == 1); //There is one CommitInfo with Revision == 1 Assert.Equal(1, Results.ToArray().Count()); Results = session.Query<CommitInfo>(indexName) .Where(x => x.Revision == 0); //There is not CommitInfo with Revision = 0 so hopefully we do not get any result Assert.Equal(0, Results.ToArray().Count()); Results = session.Query<CommitInfo>(indexName) .Where(x => x.Revision < 1 ); //There are 0 CommitInfos which has Revision <1 Assert.Equal(0, Results.ToArray().Count()); Results = session.Query<CommitInfo>(indexName) .Where(x => x.Revision < 2); //There is one CommitInfo with Revision < 2 Assert.Equal(1, Results.ToArray().Count()); //Revision of resulted CommitInfo has to be 1 var cinfo = Results.ToArray()[0]; Assert.Equal(1, cinfo.Revision); Results = session.Query<CommitInfo>(indexName) .Where(x => x.Revision <= 2); //There are 2 CommitInfos which has Revision <=2 Assert.Equal(2, Results.ToArray().Count()); Results = session.Query<CommitInfo>(indexName) .Where(x => x.Revision > 7); //There are 0 CommitInfos which has Revision >7 Assert.Equal(0, Results.ToArray().Count()); Results = session.Query<CommitInfo>(indexName) .Where(x => x.Revision > 6); //There are 1 CommitInfos which has Revision >6 Assert.Equal(1, Results.ToArray().Count()); Results = session.Query<CommitInfo>(indexName) .Where(x => x.Revision >= 6); //There are 2 CommitInfos which has Revision >=6 Assert.Equal(2, Results.ToArray().Count()); Results = session.Query<CommitInfo>(indexName) .Where(x => x.Revision > 6 && x.Revision < 6); //There are 0 CommitInfos which has Revision >6 && <6 Assert.Equal(0, Results.ToArray().Count()); Results = session.Query<CommitInfo>(indexName) .Where(x => x.Revision >= 6 && x.Revision <= 6); //There are 1 CommitInfos which has Revision >=6 && <=6 Assert.Equal(1, Results.ToArray().Count()); Results = session.Query<CommitInfo>(indexName) .Where(x => x.Revision >= 6 && x.Revision < 6); //There are 0 CommitInfos which has Revision >=6 && <6 Assert.Equal(0, Results.ToArray().Count()); Results = session.Query<CommitInfo>(indexName) .Where(x => x.Revision > 6 && x.Revision <= 6); //There are 0 CommitInfos which has Revision >6 && <=6 Assert.Equal(0, Results.ToArray().Count()); Results = session.Query<CommitInfo>(indexName) .Where(x => x.Revision >= 7 && x.Revision <= 1); //There are 0 CommitInfos which has Revision >=7 && <= 1 Assert.Equal(0, Results.ToArray().Count()); Results = session.Query<CommitInfo>(indexName) .Where(x => x.Revision > 7 && x.Revision < 1); //There are 0 CommitInfos which has Revision >7 && < 1 Assert.Equal(0, Results.ToArray().Count()); Results = session.Query<CommitInfo>(indexName) .Where(x => x.Revision > 7 || x.Revision < 1); //There are 0 CommitInfos which has Revision >7 || < 1 Assert.Equal(0, Results.ToArray().Count()); Results = session.Query<CommitInfo>(indexName) .Where(x => x.Revision >= 7 || x.Revision < 1); //There are 1 CommitInfos which has Revision >=7 || < 1 Assert.Equal(1, Results.ToArray().Count()); Results = session.Query<CommitInfo>(indexName) .Where(x => x.Revision > 7 || x.Revision <= 1); //There are 1 CommitInfos which has Revision >7 || <= 1 Assert.Equal(1, Results.ToArray().Count()); Results = session.Query<CommitInfo>(indexName) .Where(x => x.Revision >= 7 || x.Revision <= 1); //There are 2 CommitInfos which has Revision >=7 || <= 1 Assert.Equal(2, Results.ToArray().Count()); } } }
public void Should_retrieve_all_entities_using_connection_string() { using (var documentStore = new EmbeddableDocumentStore { ConnectionStringName = "Local", Configuration = { RunInUnreliableYetFastModeThatIsNotSuitableForProduction = true } }) { path = documentStore.DataDirectory; documentStore.Initialize(); var session1 = documentStore.OpenSession(); session1.Store(new Company { Name = "Company 1" }); session1.Store(new Company { Name = "Company 2" }); session1.SaveChanges(); var session2 = documentStore.OpenSession(); var companyFound = session2.Advanced.LuceneQuery<Company>() .WaitForNonStaleResults() .ToArray(); Assert.Equal(2, companyFound.Length); } }
public void Can_Use_Static_Properties_In_Where_Clauses() { using (var db = new EmbeddableDocumentStore() { DataDirectory = directoryName }) { db.Initialize(); db.DatabaseCommands.PutIndex("DateTime", new IndexDefinition { Map = @"from info in docs.DateTimeInfos select new { info.TimeOfDay }", }); using (var s = db.OpenSession()) { s.Store(new DateTimeInfo { TimeOfDay = DateTime.Now.AddDays(1) }); s.Store(new DateTimeInfo { TimeOfDay = DateTime.Now.AddDays(-1) }); s.Store(new DateTimeInfo { TimeOfDay = DateTime.Now.AddDays(1) }); s.SaveChanges(); } using (var s = db.OpenSession()) { //Just issue a blank query to make sure there are no stale results s.Query<DateTimeInfo>("DateTime") .Customize(x => x.WaitForNonStaleResults()).FirstOrDefault(); var count = s.Query<DateTimeInfo>("DateTime").Where(x => x.TimeOfDay > DateTime.Now).Count(); Assert.Equal(2, count); } } }
private string CreateEntities(EmbeddableDocumentStore documentStore) { const string questionId = @"question\259"; const string answerId = @"answer\540"; using (var session = documentStore.OpenSession()) { var user = new User { Id = @"user\222", DisplayName = "John Doe" }; session.Store(user); var question = new Question { Id = questionId, Title = "How to do this in RavenDb?", Content = "I'm trying to find how to model documents for better DDD support.", UserId = @"user\222" }; session.Store(question); var answer = new AnswerEntity() { Id = answerId, Question = question, Content = "This is doable", UserId = user.Id }; Answer answerDb = Map(answer); session.Store(answerDb); var vote1 = new AnswerVoteEntity { Id = "votes\\1", Answer = answer, QuestionId = questionId, Delta = 2 }; AnswerVote vote1Db = Map(vote1); session.Store(vote1Db); var vote2 = new AnswerVoteEntity { Id = "votes\\2", Answer = answer, QuestionId = questionId, Delta = 3 }; AnswerVote vote2Db = Map(vote2); session.Store(vote2Db); session.SaveChanges(); } return answerId; }
public void Can_perform_Single_and_SingleOrDefault_Query() { using (var db = new EmbeddableDocumentStore() { DataDirectory = directoryName }) { db.Initialize(); string indexName = "UserIndex"; using (var session = db.OpenSession()) { AddData(session); db.DatabaseCommands.DeleteIndex(indexName); var result = db.DatabaseCommands.PutIndex<User, User>(indexName, new IndexDefinition<User, User>() { Map = docs => from doc in docs select new { doc.Name, doc.Age }, Indexes = {{x=>x.Name, FieldIndexing.Analyzed}} }, true); WaitForQueryToComplete(session, indexName); var singleItem = session.Query<User>(indexName) .Single(x => x.Name.Contains("James")); Assert.Equal(25, singleItem.Age); Assert.Equal("James", singleItem.Name); //A default query should return for results, so Single() should throw Assert.Throws(typeof(InvalidOperationException), () => session.Query<User>(indexName).Single()); //A query of age = 30 should return for 2 results, so Single() should throw Assert.Throws(typeof(InvalidOperationException), () => session.Query<User>(indexName).Single(x => x.Age == 30)); //A query of age = 30 should return for 2 results, so SingleOrDefault() should also throw Assert.Throws(typeof(InvalidOperationException), () => session.Query<User>(indexName).SingleOrDefault(x => x.Age == 30)); //A query of age = 75 should return for NO results, so SingleOrDefault() should return a default value var singleOrDefaultItem = session.Query<User>(indexName) .SingleOrDefault(x => x.Age == 75); Assert.Null(singleOrDefaultItem); } } }