Ejemplo n.º 1
0
        public void GivenSomeUsers_QueryWithAnIndex_ReturnsUsersWithNamesReversed()
        {
            using (EmbeddableDocumentStore store = NewDocumentStore())
            {
                store.DatabaseCommands.PutIndex("StringReverseIndex",
                                                new IndexDefinition
                {
                    Map =
                        "from doc in docs select new { doc.Name, ReverseName = doc.Name.Reverse()}"
                });

                using (IDocumentSession documentSession = store.OpenSession())
                {
                    documentSession.Store(new User {
                        Name = "Ayende"
                    });
                    documentSession.Store(new User {
                        Name = "Itamar"
                    });
                    documentSession.Store(new User {
                        Name = "Pure Krome"
                    });
                    documentSession.Store(new User {
                        Name = "John Skeet"
                    });
                    documentSession.Store(new User {
                        Name = "StackOverflow"
                    });
                    documentSession.Store(new User {
                        Name = "Wow"
                    });
                    documentSession.SaveChanges();
                }

                using (IDocumentSession documentSession = store.OpenSession())
                {
                    var users = documentSession
                                .Query <User>("StringReverseIndex")
                                .Customize(x => x.WaitForNonStaleResults())
                                .ToList();

                    Assert.Empty(store.SystemDatabase.Statistics.Errors);
                    Assert.NotNull(users);
                    Assert.True(users.Count > 0);
                }
            }
        }
Ejemplo n.º 2
0
        public void FourOrClauses_fails()
        {
            using (EmbeddableDocumentStore store = NewDocumentStore())
            {
                store.Initialize();

                var itemList = new List <Item> {
                    new Item("A")
                };

                using (IDocumentSession s = store.OpenSession())
                {
                    s.Store(new MyDoc
                    {
                        Foo           = "monkey",
                        ItemListOne   = itemList,
                        ItemListTwo   = itemList,
                        ItemListThree = itemList,
                        ItemListFour  = itemList
                    });
                    s.Store(new MyDoc
                    {
                        Foo           = "monkey",
                        ItemListOne   = itemList,
                        ItemListTwo   = itemList,
                        ItemListThree = itemList,
                        ItemListFour  = itemList
                    });
                    s.SaveChanges();
                }
                using (IDocumentSession s = store.OpenSession())
                {
                    MyDoc[] res = s.Query <MyDoc>()
                                  .Where(x => x.Foo == "monkey" && (
                                             x.ItemListOne.Any(i => i.MyProp == "A") ||
                                             x.ItemListTwo.Any(i => i.MyProp == "A") ||
                                             x.ItemListThree.Any(i => i.MyProp == "A") ||
                                             x.ItemListFour.Any(i => i.MyProp == "A")))
                                  //Additional Or clause
                                  .OrderByDescending(x => x.CreatedDate)
                                  .ToArray();


                    Assert.True(res.Count() == 2);
                }
            }
        }
Ejemplo n.º 3
0
        public void can_index_on_a_reference2()
        {
            using (var store = new EmbeddableDocumentStore
            {
                RunInMemory = true
            })
            {
                store.Initialize();
                using (var session = store.OpenSession())
                {
                    var category = new Category()
                    {
                        Name = "Parent"
                    };

                    category.Add(new Category()
                    {
                        Name = "Child"
                    });

                    session.Store(category);
                    session.SaveChanges();
                }

                using (var session = store.OpenSession())
                {
                    var results0 = session.Query <Category>()
                                   .Customize(x => x.WaitForNonStaleResults(TimeSpan.FromHours(1)))
                                   .ToList();
                    Assert.Equal(1, results0.Count);

                    // WORKS
                    var results1 = session.Query <Category>()
                                   .Customize(x => x.WaitForNonStaleResults())
                                   .Where(x => x.Children.Any(y => y.Name == "Child")).
                                   ToList();
                    Assert.Equal(1, results1.Count);

                    // FAILS
                    var results2 = session.Query <Category>()
                                   .Customize(x => x.WaitForNonStaleResults())
                                   .Where(x => x.Children.Any(y => y.Parent.Name == "Parent"))
                                   .ToList();
                    Assert.Equal(1, results2.Count);
                }
            }
        }
 public AccountRepositoryTests()
 {
     _documentStore = new EmbeddableDocumentStore {
         Conventions = { IdentityPartsSeparator = "-" }
     };
     _documentStore.Initialize();
     _session = _documentStore.OpenSession();
 }
Ejemplo n.º 5
0
 protected void SetupData(Action <IDocumentSession> action)
 {
     using (var session = documentStore.OpenSession())
     {
         action(session);
         session.SaveChanges();
     }
 }
        public void write_then_read_from_stack_over_flow_types()
        {
            using (EmbeddableDocumentStore documentStore = NewDocumentStore())
            {
                new QuestionWithVoteTotalIndex().Execute(documentStore);

                const string questionId = @"question/259";
                using (IDocumentSession 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 vote1 = new QuestionVote {
                        QuestionId = questionId, Delta = 2
                    };
                    session.Store(vote1);
                    var vote2 = new QuestionVote {
                        QuestionId = questionId, Delta = 3
                    };
                    session.Store(vote2);

                    session.SaveChanges();
                }

                using (IDocumentSession session = documentStore.OpenSession())
                {
                    QuestionView questionInfo = session.Query <QuestionView, QuestionWithVoteTotalIndex>()
                                                .Customize(x => x.WaitForNonStaleResultsAsOfNow())
                                                .Where(x => x.QuestionId == questionId)
                                                .SingleOrDefault();
                    Assert.NotNull(questionInfo);
                    Assert.False(string.IsNullOrEmpty(questionInfo.User.DisplayName), "User.DisplayName was not loaded");
                }
            }
        }
Ejemplo n.º 7
0
        public IDocumentSession GetSession()
        {
            lock (isStoreSet)
            {
                if (!(bool)isStoreSet)
                {
                    RavenConfiguration ravenConfiguration = null;

                    bool webUIEnabled = false;
                    int  webUIPort    = 0;

                    var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                    var serviceConfigurationSection = config.GetSection("ServiceConfigurationSection") as ServiceConfigurationSection;
                    if (serviceConfigurationSection != null)
                    {
                        ravenConfiguration = serviceConfigurationSection.ravendb;
                        if (ravenConfiguration != null)
                        {
                            webUIEnabled = ravenConfiguration.WebUIEnabled;
                            webUIPort    = ravenConfiguration.WebUIPort;

                            if (webUIEnabled)
                            {
                                if (webUIPort < 0 || webUIPort > 65535)
                                {
                                    webUIEnabled = false;
                                }
                                else
                                {
                                    webUIEnabled = CheckPortIsAvailable(webUIPort);
                                }
                            }
                        }
                    }

                    documentStore = new EmbeddableDocumentStore();
                    documentStore.Configuration.DataDirectory               = "Data\\RavenDB";
                    documentStore.Configuration.DefaultStorageTypeName      = typeof(Raven.Storage.Esent.TransactionalStorage).AssemblyQualifiedName;
                    documentStore.Conventions.FindIdentityProperty          = x => x.Name == "Oid";
                    documentStore.Conventions.MaxNumberOfRequestsPerSession = 1000;
                    documentStore.Initialize();

                    IndexCreation.CreateIndexes(GetType().Assembly, documentStore);

                    if (webUIEnabled)
                    {
                        documentStore.Configuration.Port = webUIPort;
                        var httpServer = new HttpServer(documentStore.Configuration, documentStore.DocumentDatabase);
                        httpServer.Init();
                        httpServer.StartListening();
                    }

                    isStoreSet = true;
                }
            }

            return(documentStore.OpenSession());
        }
Ejemplo n.º 8
0
 public RepositoryContext()
 {
     _documentStore = new EmbeddableDocumentStore()
     {
         ConnectionStringName = "ContentRepository"
     };
     _documentStore.Initialize();
     _session = _documentStore.OpenSession();
 }
Ejemplo n.º 9
0
 public WhereStringEqualsInCollection()
 {
     store = NewDocumentStore();
     using (var session = store.OpenSession())
     {
         session.Store(new MyEntity { StringData = "Entity with collection", StringCollection = new List<string> { "CollectionItem1", "CollectionItem2" } });
         session.SaveChanges();
     }
 }
        public PostSchedulingStrategyTests()
        {
            Now = DateTimeOffset.Now;

            DocumentStore = new EmbeddableDocumentStore {
                RunInMemory = true
            }.Initialize();
            Session = DocumentStore.OpenSession();
        }
        public void versioning_should_work()
        {
            var store = new EmbeddableDocumentStore {
                RunInMemory = true
            };

            store.Configuration.Settings.Add("Raven/ActiveBundles", "Versioning");
            store.Initialize();

            using (IDocumentSession db = store.OpenSession())
            {
                db.Store(new VersioningConfiguration
                {
                    Exclude      = false,
                    Id           = "Raven/Versioning/Items",
                    MaxRevisions = int.MaxValue
                });
                db.SaveChanges();
            }

            using (IDocumentSession db = store.OpenSession())
            {
                db.Store(new Item {
                    Value = "first revision"
                });
                db.SaveChanges();
            }

            using (IDocumentSession db = store.OpenSession())
            {
                Item item = db.Query <Item>().Customize(x => x.WaitForNonStaleResults()).First();
                item.Value = "second revision";
                db.SaveChanges();
            }

            using (IDocumentSession db = store.OpenSession())
            {
                Item   item      = db.Query <Item>().Customize(x => x.WaitForNonStaleResults()).First();
                string id        = db.Advanced.GetDocumentId(item);
                Item[] revisions = db.Advanced.GetRevisionsFor <Item>(id, 0, 10);

                revisions.Should().NotBeEmpty();
            }
        }
        public void Can_Use_In_IEnumerable_Not_In_Where_Clause_on_Id()
        {
            using (var store = new EmbeddableDocumentStore()
            {
                RunInMemory = true
            })
            {
                store.Initialize();
                var guid1      = Guid.NewGuid();
                var guid2      = Guid.NewGuid();
                var customerId = Guid.NewGuid();
                using (var s = store.OpenSession())
                {
                    s.Store(new OrderItem {
                        Id = Guid.NewGuid(), CustomerId = customerId, Cost = 1.59m, Quantity = 5
                    });
                    s.Store(new OrderItem {
                        Id = guid1, CustomerId = customerId, Cost = 7.59m, Quantity = 3
                    });
                    s.Store(new OrderItem {
                        Id = guid2, CustomerId = customerId, Cost = 1.59m, Quantity = 4
                    });
                    s.Store(new OrderItem {
                        Id = Guid.NewGuid(), CustomerId = customerId, Cost = 1.39m, Quantity = 3
                    });
                    s.SaveChanges();
                }

                var list = new List <Guid> {
                    guid1
                };                                                   //, guid2 };

                using (var s = store.OpenSession())
                {
                    var items = (from item in s.Query <OrderItem>()
                                 where item.Quantity > 4 && item.CustomerId == customerId &&
                                 !item.Id.In(list)
                                 select item
                                 ).ToArray();

                    Assert.Equal(items.Length, 1);
                }
            }
        }
Ejemplo n.º 13
0
        public void ShouldDeleteDocumentTombStoneAfterNextPut()
        {
            using (EmbeddableDocumentStore store = NewDocumentStore())
            {
                // create document
                string userId;
                using (var session = store.OpenSession())
                {
                    var user = new User {
                        Name = "oren"
                    };
                    session.Store(user);
                    userId = user.Id;
                    session.SaveChanges();
                }

                //now delete it and check for tombstone
                using (var session = store.OpenSession())
                {
                    session.Delete(userId);
                    session.SaveChanges();
                }

                store.SystemDatabase.TransactionalStorage.Batch(accessor =>
                {
                    var tombstone = accessor.Lists.Read(Constants.RavenPeriodicExportsDocsTombstones, userId);
                    Assert.NotNull(tombstone);
                });

                using (var session = store.OpenSession())
                {
                    session.Store(new User {
                        Name = "ayende"
                    }, userId);
                    session.SaveChanges();
                }

                store.SystemDatabase.TransactionalStorage.Batch(accessor =>
                {
                    var tombstone = accessor.Lists.Read(Constants.RavenPeriodicExportsDocsTombstones, userId);
                    Assert.Null(tombstone);
                });
            }
        }
Ejemplo n.º 14
0
        //Failing test from http://groups.google.com/group/ravendb/browse_thread/thread/7a93f37036297d48/
        public void CanSuccessfullyDoSpatialQueryOfNearbyLocations()
        {
            // These items is in a radius of 4 miles (approx 6,5 km)
            var areaOneDocOne   = new DummyGeoDoc(55.6880508001, 13.5717346673);
            var areaOneDocTwo   = new DummyGeoDoc(55.6821978456, 13.6076183965);
            var areaOneDocThree = new DummyGeoDoc(55.673251569, 13.5946697607);

            // This item is 12 miles (approx 19 km) from the closest in areaOne
            var closeButOutsideAreaOne = new DummyGeoDoc(55.8634157297, 13.5497731987);

            // This item is about 3900 miles from areaOne
            var newYork = new DummyGeoDoc(40.7137578228, -74.0126901936);

            using (var documentStore = new EmbeddableDocumentStore {
                RunInMemory = true
            }.Initialize())
                using (var session = documentStore.OpenSession())
                {
                    session.Store(areaOneDocOne);
                    session.Store(areaOneDocTwo);
                    session.Store(areaOneDocThree);
                    session.Store(closeButOutsideAreaOne);
                    session.Store(newYork);
                    session.SaveChanges();

                    var indexDefinition = new IndexDefinition
                    {
                        Map = "from doc in docs select new { _ = SpatialIndex.Generate(doc.Latitude, doc.Longitude) }"
                    };

                    documentStore.DatabaseCommands.PutIndex("FindByLatLng", indexDefinition);

                    // Wait until the index is built
                    session.Advanced.LuceneQuery <DummyGeoDoc>("FindByLatLng")
                    .WaitForNonStaleResults()
                    .ToArray();

                    const double lat = 55.6836422426, lng = 13.5871808352;             // in the middle of AreaOne
                    const double radius = 5.0;

                    // Expected is that 5.0 will return 3 results
                    var nearbyDocs = session.Advanced.LuceneQuery <DummyGeoDoc>("FindByLatLng")
                                     .WithinRadiusOf(radius, lat, lng)
                                     .WaitForNonStaleResults()
                                     .ToArray();

                    Assert.NotEqual(null, nearbyDocs);
                    Assert.Equal(3, nearbyDocs.Length);

                    //TODO
                    //var dist = DistanceUtils.GetInstance();
                    //Assert.Equal(true, nearbyDocs.All(x => dist.GetDistanceMi(x.Latitude, x.Longitude, lat, lng) < radius));

                    session.Dispose();
                }
        }
Ejemplo n.º 15
0
        public void AllowNonAuthoratativeInformationAlwaysWorks()
        {
            const int callCount = 10000;

            using (IDocumentStore documentStore = new EmbeddableDocumentStore {
                RunInMemory = true
            })
            {
                documentStore.Initialize();

                int documentId;

                // create test document
                using (IDocumentSession session = documentStore.OpenSession())
                {
                    var testDocument = new TestDocument();
                    session.Store(testDocument);
                    session.SaveChanges();

                    documentId = testDocument.Id;
                }

                // do many 'set property and check value' tests
                for (int i = 0; i < callCount; i++)
                {
                    using (IDocumentSession session = documentStore.OpenSession())
                        using (var tx = new TransactionScope())
                        {
                            session.Load <TestDocument>(documentId).Value = i;
                            session.SaveChanges();

                            tx.Complete();
                        }

                    using (IDocumentSession session = documentStore.OpenSession())
                    {
                        session.Advanced.AllowNonAuthoritativeInformation = false;
                        var loadedDoc = session.Load <TestDocument>(documentId);
                        Assert.Equal(i, loadedDoc.Value);
                    }
                }
            }
        }
        public void AddUserToProjectSuccess()
        {
            var pm = new ProjectManager {
                Session = _embeddedDocStore.OpenSession()
            };

            pm.AddUserToProject(_existingProject.Name, _newActiveUser.Username, _existingUser.Username);
            var session        = _embeddedDocStore.OpenSession();
            var updatedProject = session.Query <Project>().Where(p => p.Name == _existingProject.Name).First();

            Assert.IsTrue(updatedProject.Users.Contains(_newActiveUser.Username));
        }
Ejemplo n.º 17
0
        protected static IDocumentSession WithEmptySession()
        {
            var store = new EmbeddableDocumentStore
            {
                RunInMemory   = true,
                Configuration = { Storage = { Voron = { AllowOn32Bits = true } } }
            }.Initialize();

            return(store.OpenSession());
        }
        public void Can_perform_Boolean_Queries()
        {
            using (var db = new EmbeddableDocumentStore()
            {
                RunInMemory = true
            })
            {
                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 IndexDefinitionBuilder <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 == ("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 == ("Matt") && !x.Active);
                    Assert.Equal(2, testQuery.ToArray().Count());
                    foreach (var testResult in testQuery)
                    {
                        Assert.False(testResult.Active);
                    }
                }
            }
        }
Ejemplo n.º 19
0
        public void Spatial_Search_Should_Integrate_Distance_As_A_Boost_Factor()
        {
            using (var store = new EmbeddableDocumentStore {
                RunInMemory = true
            }.Initialize())
            {
                store.ExecuteIndex(new SpatialIndex());

                using (var session = store.OpenSession())
                {
                    session.Store(new SpatialEntity(45.70955, -73.569131)                     // 22.23 Kb
                    {
                        Id = "se/1",
                    });

                    session.Store(new SpatialEntity(45.50955, -73.569131)                     // 0 Km
                    {
                        Id = "se/2",
                    });

                    session.Store(new SpatialEntity(45.60955, -73.569131)                     // 11.11 KM
                    {
                        Id = "se/3",
                    });

                    session.SaveChanges();
                }

                WaitForIndexing(store);

                using (var session = store.OpenSession())
                {
                    var results = session.Advanced.LuceneQuery <SpatialEntity>("SpatialIndex")
                                  .WithinRadiusOf(500, 45.50955, -73.569133)
                                  .ToList();

                    Assert.Equal(results[0].Id, "se/2");
                    Assert.Equal(results[1].Id, "se/3");
                    Assert.Equal(results[2].Id, "se/1");
                }
            }
        }
Ejemplo n.º 20
0
 public void TestInitialize()
 {
     // Arrange
     _documentStore = new EmbeddableDocumentStore
     {
         ConnectionStringName = "RavenDB"
     };
     _documentStore.Initialize();
     _session    = _documentStore.OpenSession();
     _controller = new MoviesController(_session);
 }
        private void AssertProjectIsCreated(string projectName, string username)
        {
            var session      = _embeddedDocStore.OpenSession();
            var projectCount = session.Query <Project>().Where(p => p.Name == projectName && p.Owner == username).Count();

            Assert.That(projectCount, Is.EqualTo(1));
            var project = session.Query <Project>().Where(p => p.Name == projectName && p.Owner == username).First();

            Assert.That(project.Users.Count(), Is.EqualTo(1));
            Assert.That(project.Users[0], Is.EqualTo(username));
        }
        public void Can_Use_In_IEnumerable_In_Where_Clause()
        {
            using (var store = new EmbeddableDocumentStore()
            {
                RunInMemory = true
            })
            {
                store.Initialize();

                using (var s = store.OpenSession())
                {
                    s.Store(new OrderItem {
                        Cost = 1.59m, Quantity = 5
                    });
                    s.Store(new OrderItem {
                        Cost = 7.59m, Quantity = 3
                    });
                    s.Store(new OrderItem {
                        Cost = 1.59m, Quantity = 4
                    });
                    s.Store(new OrderItem {
                        Cost = 1.39m, Quantity = 3
                    });
                    s.SaveChanges();
                }

                var list = new List <decimal> {
                    3, 5
                };

                using (var s = store.OpenSession())
                {
                    var items = (from item in s.Query <OrderItem>()
                                 where item.Quantity.In(list)
                                 select item
                                 ).ToArray();

                    Assert.Equal(items.Length, 3);
                }
            }
        }
        public void Can_Use_Enums_In_IEnumerable_In_Where_Clause()
        {
            using (var store = new EmbeddableDocumentStore()
            {
                RunInMemory = true
            })
            {
                store.Initialize();

                using (var s = store.OpenSession())
                {
                    s.Store(new OrderItem {
                        Cost = 1.59m, Quantity = 5, Country = Origin.Africa
                    });
                    s.Store(new OrderItem {
                        Cost = 7.59m, Quantity = 3, Country = Origin.Africa
                    });
                    s.Store(new OrderItem {
                        Cost = 1.59m, Quantity = 4, Country = Origin.UnitedStates
                    });
                    s.Store(new OrderItem {
                        Cost = 1.39m, Quantity = 3, Country = Origin.Africa
                    });
                    s.SaveChanges();
                }

                var list = new List <Origin> {
                    Origin.Africa
                };

                using (var s = store.OpenSession())
                {
                    var items = (from item in s.Query <OrderItem>()
                                 where item.Country.In(list)
                                 select item
                                 ).ToArray();

                    Assert.Equal(items.Length, 3);
                }
            }
        }
        public void Can_Use_Static_Properties_In_Where_Clauses()
        {
            using (var db = new EmbeddableDocumentStore()
            {
                RunInMemory = true
            })
            {
                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 = SystemTime.Now.AddDays(1)
                    });
                    s.Store(new DateTimeInfo {
                        TimeOfDay = SystemTime.Now.AddDays(-1)
                    });
                    s.Store(new DateTimeInfo {
                        TimeOfDay = SystemTime.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 > SystemTime.Now).Count();
                    Assert.Equal(2, count);
                }
            }
        }
Ejemplo n.º 25
0
        private static void DoTest(DateTime dt, DateTimeKind inKind, DateTimeKind outKind)
        {
            Assert.Equal(inKind, dt.Kind);

            using (var documentStore = new EmbeddableDocumentStore {
                RunInMemory = true
            })
            {
                documentStore.Initialize();
                new FoosAndBars_ByDateTime().Execute(documentStore);

                using (var session = documentStore.OpenSession())
                {
                    session.Store(new Foo {
                        Id = "foos/1", DateTime1 = dt
                    });
                    session.Store(new Bar {
                        Id = "bars/1", DateTime2 = dt
                    });
                    session.SaveChanges();
                }

                using (var session = documentStore.OpenSession())
                {
                    var results = session.Query <FoosAndBars_ByDateTime.Result, FoosAndBars_ByDateTime>()
                                  .Customize(x => x.WaitForNonStaleResults())
                                  .Where(x => x.DateTime == dt)
                                  .As <object>()
                                  .ToList();

                    var foo = results.OfType <Foo>().First();
                    var bar = results.OfType <Bar>().First();

                    Assert.Equal(dt, foo.DateTime1);
                    Assert.Equal(outKind, foo.DateTime1.Kind);

                    Assert.Equal(dt, bar.DateTime2);
                    Assert.Equal(outKind, bar.DateTime2.Kind);
                }
            }
        }
Ejemplo n.º 26
0
 public void Test()
 {
     using (var session = _documentStore.OpenSession())
     {
         TestEntity entity = new TestEntity {
             LastSavedDate = DateTime.Now
         };
         session.Store(entity);
         session.SaveChanges();
         entity = session.Include("RelatedEntityId").Load <TestEntity>(entity.Id);
     }
 }
        public void Can_perform_Skip_Take_Query()
        {
            using (var db = new EmbeddableDocumentStore()
            {
                RunInMemory = true
            })
            {
                db.Initialize();

                string indexName = "UserIndex";
                using (var session = db.OpenSession())
                {
                    AddData(session);

                    db.DatabaseCommands.DeleteIndex(indexName);
                    db.DatabaseCommands.PutIndex <User, User>(indexName,
                                                              new IndexDefinitionBuilder <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());
                }
            }
        }
Ejemplo n.º 28
0
 public void DoSomeActions()
 {
     using (var documentStore = new EmbeddableDocumentStore {
         RunInMemory = true
     }.Initialize())
     {
         using (var session = documentStore.OpenSession())
         {
             // Run complex test scenarious
         }
     }
 }
Ejemplo n.º 29
0
 public void Can_query_active_campaigns()
 {
     using (var session = Store.OpenSession())
     {
         var results = session.Query <VacancyCampaignsIndex.ReduceResult, VacancyCampaignsIndex>()
                       .Customize(x => x.WaitForNonStaleResults())
                       .Where(x => x.Active)
                       .AsProjection <VacancyCampaignsIndex.ReduceResult>()
                       .ToList();
         Assert.Equal(2, results.Count());
     }
 }
Ejemplo n.º 30
0
        private static void PutSampleData(EmbeddableDocumentStore documentStore)
        {
            using (var session = documentStore.OpenSession())
            {
                session.Store(new Foo
                {
                    Id   = "foos/1",
                    Bars = new Dictionary <string, Bar>
                    {
                        { "A", new Bar {
                              Name = "A", Value = "1"
                          } },
                        { "B", new Bar {
                              Name = "B", Value = "2"
                          } },
                        { "C", new Bar {
                              Name = "C", Value = "3"
                          } },
                    }
                });

                session.Store(new Foo
                {
                    Id   = "foos/2",
                    Bars = new Dictionary <string, Bar>
                    {
                        { "D", new Bar {
                              Name = "D", Value = "4"
                          } },
                        { "E", new Bar {
                              Name = "E", Value = "5"
                          } },
                        { "F", new Bar {
                              Name = "F", Value = "6"
                          } },
                    }
                });

                session.Store(new Foo
                {
                    Id   = "foos/3",
                    Bars = new Dictionary <string, Bar>()
                });

                session.Store(new Foo
                {
                    Id   = "foos/4",
                    Bars = new Dictionary <string, Bar>()
                });

                session.SaveChanges();
            }
        }