コード例 #1
0
ファイル: TestingUsage.cs プロジェクト: mallickhruday/Projac
        public static async Task Assert(this ProjectionTestSpecification <IAsyncDocumentSession> specification)
        {
            if (specification == null)
            {
                throw new ArgumentNullException("specification");
            }
            using (var store = new EmbeddableDocumentStore
            {
                RunInMemory = true,
                DataDirectory = Path.GetTempPath()
            })
            {
                store.Configuration.Storage.Voron.AllowOn32Bits = true;
                store.Initialize();
                using (var session = store.OpenAsyncSession())
                {
                    await new Projector <IAsyncDocumentSession>(specification.Resolver).
                    ProjectAsync(session, specification.Messages);
                    await session.SaveChangesAsync();

                    var result = await specification.Verification(session, CancellationToken.None);

                    if (result.Failed)
                    {
                        throw new AssertionException(result.Message);
                    }
                }
            }
        }
コード例 #2
0
        public static void Main(string[] args)
        {
            var container = TinyIoCContainer.Current;

            var eventStore = new JsonFileEventStore("ExampleEvents.zip", 100);

            EmbeddableDocumentStore store = BuildDocumentStore(".\\", 9001);

            container.Register <Func <IAsyncDocumentSession> >(() => store.OpenAsyncSession());
            var dispatcher = new Dispatcher(eventStore);

            var bootstrapper = new CountsProjector(dispatcher, store.OpenAsyncSession);

            var startOptions = new StartOptions($"http://localhost:9000");

            using (WebApp.Start(startOptions, builder => builder.UseControllers(container)))
            {
                bootstrapper.Start().Wait();

                Console.WriteLine($"HTTP endpoint available at http://localhost:9000/api/Statistics/CountsPerState");
                Console.WriteLine($"Management Studio available at http://localhost:9001");

                Console.ReadLine();
            }
        }
コード例 #3
0
        public async Task CanRefreshEntityFromDatabaseAsync()
        {
            var company = new Company {
                Name = "Company Name"
            };

            using (var session = documentStore.OpenAsyncSession())
            {
                await session.StoreAsync(company);

                await session.SaveChangesAsync();

                using (var session2 = documentStore.OpenSession())
                {
                    var company2 = session2.Load <Company>(company.Id);
                    company2.Name = "Hibernating Rhinos";
                    session2.Store(company2);
                    session2.SaveChanges();
                }

                var old = session.Advanced.GetEtagFor(company);
                await session.Advanced.RefreshAsync(company);

                Assert.NotEqual(old, session.Advanced.GetEtagFor(company));
                Assert.NotEqual(Etag.Empty, session.Advanced.GetEtagFor(company));
                Assert.Equal("Hibernating Rhinos", company.Name);
            }
        }
コード例 #4
0
 public async void Show()
 {
     using (var store = new EmbeddableDocumentStore
     {
         RunInMemory = true,
         DataDirectory = Path.GetTempPath()
     })
     {
         store.Initialize();
         using (var session = store.OpenAsyncSession())
         {
             var portfolioId = Guid.NewGuid();
             await new AsyncRavenProjector(Projection.Handlers).
             ProjectAsync(session, new object[]
             {
                 new PortfolioAdded {
                     Id = portfolioId, Name = "My portfolio"
                 },
                 new PortfolioRenamed {
                     Id = portfolioId, Name = "Your portfolio"
                 },
                 new PortfolioRemoved {
                     Id = portfolioId
                 }
             });
         }
     }
 }
コード例 #5
0
 public async Task Show()
 {
     using (var store = new EmbeddableDocumentStore
     {
         RunInMemory = true,
         DataDirectory = Path.GetTempPath()
     })
     {
         store.Initialize();
         using (var session = store.OpenAsyncSession())
         {
             var portfolioId = Guid.NewGuid();
             await new Projector <IAsyncDocumentSession>(Resolve.WhenEqualToHandlerMessageType(Projection.Handlers)).
             ProjectAsync(session, new object[]
             {
                 new PortfolioAdded {
                     Id = portfolioId, Name = "My portfolio"
                 },
                 new PortfolioRenamed {
                     Id = portfolioId, Name = "Your portfolio"
                 },
                 new PortfolioRemoved {
                     Id = portfolioId
                 }
             });
         }
     }
 }
コード例 #6
0
 public void SetUp()
 {
     _store = new EmbeddableDocumentStore
     {
         RunInMemory   = true,
         DataDirectory = Path.GetTempPath()
     };
     _store.Initialize();
     _session = _store.OpenAsyncSession();
 }
コード例 #7
0
 public void TestInitialize()
 {
     // Arrange
     _documentStore = new EmbeddableDocumentStore
     {
         ConnectionStringName = "RavenDB"
     };
     _documentStore.Initialize();
     _session    = _documentStore.OpenAsyncSession();
     _controller = new MoviesController(_session);
 }
コード例 #8
0
        public async Task SpatialIndexTest()
        {
            using (EmbeddableDocumentStore db = NewDocumentStore())
            {
                new Promos_Index().Execute(db);

                using (IAsyncDocumentSession session = db.OpenAsyncSession())
                {
                    await session.StoreAsync(new Promo
                    {
                        Title      = "IPHONES",
                        Coordinate = new Coordinate {
                            latitude = 41.145556, longitude = -73.995
                        }
                    });

                    await session.StoreAsync(new Promo
                    {
                        Title      = "ANDROIDS",
                        Coordinate = new Coordinate {
                            latitude = 41.145533, longitude = -73.999
                        }
                    });

                    await session.StoreAsync(new Promo
                    {
                        Title      = "BLACKBERRY",
                        Coordinate = new Coordinate {
                            latitude = 12.233, longitude = -73.995
                        }
                    });

                    await session.SaveChangesAsync();

                    WaitForIndexing(db);

                    var result = await session.Query <Promo, Promos_Index>()
                                 .Customize(
                        x => x.WithinRadiusOf(
                            radius: 3.0,
                            latitude: 41.145556,
                            longitude: -73.995))
                                 .ToListAsync();

                    Assert.Equal(2, result.Count);
                }
            }
        }
コード例 #9
0
        protected async Task ExecuteAction <TController>(Func <TController, Task> action)
            where TController : DragonContractsController, new()
        {
            var controller = new TController {
                Session = documentStore.OpenAsyncSession()
            };

            //var httpConfiguration = MockRepository.GenerateStub<HttpConfiguration>();
            //var httpRouteData = MockRepository.GenerateStub<HttpRouteData>();
            //var httpRequestMessage = MockRepository.GenerateStub<HttpRequestMessage>();
            //ControllerContext = new HttpControllerContext(httpConfiguration, httpRouteData, httpRequestMessage);
            //controller.ControllerContext = ControllerContext;

            await action(controller);

            await controller.Session.SaveChangesAsync();
        }
コード例 #10
0
            public void SetUp()
            {
                _store = new EmbeddableDocumentStore
                {
                    RunInMemory   = true,
                    DataDirectory = Path.GetTempPath()
                };
                _store.Initialize();
                _session = _store.OpenAsyncSession();
                _calls   = new List <RavenProjectionHandlerCall>();
                var handler = new RavenProjectionHandler(
                    typeof(MatchMessage1),
                    (session, msg, token) =>
                {
                    _calls.Add(new RavenProjectionHandlerCall(session, msg, token));
                    return(Task.FromResult(false));
                });

                _sut = SutFactory(new[] { handler });
            }
        public async Task When_delete_revision_and_load_Then_should_get_null()
        {
            using (var session = _documentStore.OpenAsyncSession())
            {
                var doc = new RevisionedDocument {
                    Id = "key", Revision = 1, Data = "Alpha"
                };
                await session.StoreAsync(doc);

                await session.SaveChangesAsync();
            }

            await _documentStore.AsyncDatabaseCommands.DeleteRevision("key", 1, null);

            using (var session = _documentStore.OpenAsyncSession())
            {
                Assert.Null(await session.LoadRevision <RevisionedDocument>("key", 1));
            }
        }
コード例 #12
0
 public IAsyncDocumentSession OpenAsyncSession()
 {
     return(_documentStore.OpenAsyncSession());
 }