Exemplo n.º 1
0
        protected async Task <IWidgetRepository> CreateWidgetRepository(
            Mock <IDatabaseConnectionFactory> connectionFactoryMock = null)
        {
            if (connectionFactoryMock == null)
            {
                var db = new InMemoryDatabase();
                db.OpenConnection();

                connectionFactoryMock = new Mock <IDatabaseConnectionFactory>();
                connectionFactoryMock.Setup(c => c.GetConnection()).Returns(db.OpenConnection());
            }

            IWidgetRepository widgetRepository = new WidgetRepository(connectionFactoryMock.Object);

            var projectRoot = AppContext.BaseDirectory.Substring(0,
                                                                 AppContext.BaseDirectory.LastIndexOf("bin", StringComparison.Ordinal));
            var script = File.ReadAllText(Path.Combine(projectRoot, XyzWidgetSchema));

            await widgetRepository.CreateSqliteSchema(script);

            return(widgetRepository);
        }