public void Startup(DataStoreType dataStoreType, string connectionString, bool enableCache) { if (!string.IsNullOrEmpty(connectionString)) { LightSpeedContext context = new LightSpeedContext(); context.ConnectionString = connectionString; context.DataProvider = dataStoreType.LightSpeedDbType; context.IdentityMethod = IdentityMethod.GuidComb; context.CascadeDeletes = true; context.VerboseLogging = true; context.Logger = new DatabaseLogger(); if (enableCache) context.Cache = new CacheBroker(new DefaultCache()); ObjectFactory.Configure(x => { x.For<LightSpeedContext>().Singleton().Use(context); x.For<IUnitOfWork>().HybridHttpOrThreadLocalScoped().Use(ctx => ctx.GetInstance<LightSpeedContext>().CreateUnitOfWork()); }); } else { Log.Warn("LightSpeedRepository.Startup skipped as no connection string was provided"); } }
public void Startup(DataStoreType dataStoreType, string connectionString, bool enableCache) { if (!string.IsNullOrEmpty(connectionString)) { LightSpeedContext context = new LightSpeedContext(); context.ConnectionString = connectionString; context.DataProvider = dataStoreType.LightSpeedDbType; context.IdentityMethod = IdentityMethod.GuidComb; context.CascadeDeletes = true; if (_applicationSettings.IsLoggingEnabled) { context.VerboseLogging = true; context.Logger = new DatabaseLogger(); } if (enableCache) { context.Cache = new CacheBroker(new DefaultCache()); } ObjectFactory.Configure(x => { x.For <LightSpeedContext>().Singleton().Use(context); x.For <IUnitOfWork>().HybridHttpOrThreadLocalScoped().Use(ctx => ctx.GetInstance <LightSpeedContext>().CreateUnitOfWork()); }); } else { Log.Warn("LightSpeedRepository.Startup skipped as no connection string was provided"); } }
static void Main(string[] args) { //contextの定義はapp.configに書くこともできる(たぶんそっちが推奨のやり方) var context = new LightSpeedContext { ConnectionString = @"Data Source=LOCALHOST\SQLEXPRESS;Initial Catalog=パズルドラゴンズ;Integrated Security=True;", PluralizeTableNames = false, DataProvider = Mindscape.LightSpeed.DataProvider.SqlServer2005, IdentityMethod = IdentityMethod.IdentityColumn }; using (var uow = context.CreateUnitOfWork()) { //Create(モンスターテーブルに行を追加) uow.Add(new モンスター { モンスター名 = "プレシィ", レア度 = 2, 最大lv = 5, スキル = "コールドブレス" }); uow.SaveChanges(); //Read(モンスターテーブルの各行を表示) foreach (var m in uow.Query <モンスター>()) { Console.WriteLine(m.モンスター名); } //Update(モンスターテーブルを一行更新) var ティラ = uow.Query <モンスター>().Single(x => x.モンスター名 == "ティラ"); ティラ.最大lv = 6; uow.SaveChanges(); //Delete(モンスターテーブルから一行削除) var プレシィ = uow.Query <モンスター>().Single(x => x.モンスター名 == "プレシィ"); uow.Remove(プレシィ); uow.SaveChanges(); //動的クエリ生成(実行時に動的にクエリを生成して実行) System.Random rand = new Random(); IQueryable <モンスター> ms = uow.Query <モンスター>(); if (rand.Next(3) < 1) { ms = ms.Where(x => x.最大lv < 20); } if (rand.Next(3) < 1) { ms = ms.Where(x => x.レア度 > 3); } foreach (var m in ms) { Console.WriteLine(m.モンスター名); } } Console.WriteLine("Press the Enter key to exit"); Console.ReadLine(); }
static void Main(string[] args) { //contextの定義はapp.configに書くこともできる(たぶんそっちが推奨のやり方) var context = new LightSpeedContext { ConnectionString = @"Data Source=LOCALHOST\SQLEXPRESS;Initial Catalog=パズルドラゴンズ;Integrated Security=True;", PluralizeTableNames = false, DataProvider = Mindscape.LightSpeed.DataProvider.SqlServer2005, IdentityMethod = IdentityMethod.IdentityColumn }; using (var uow = context.CreateUnitOfWork()) { //Create(モンスターテーブルに行を追加) uow.Add(new モンスター { モンスター名 = "プレシィ", レア度 = 2, 最大lv = 5, スキル = "コールドブレス" }); uow.SaveChanges(); //Read(モンスターテーブルの各行を表示) foreach (var m in uow.Query<モンスター>()) { Console.WriteLine(m.モンスター名); } //Update(モンスターテーブルを一行更新) var ティラ = uow.Query<モンスター>().Single(x => x.モンスター名 == "ティラ"); ティラ.最大lv = 6; uow.SaveChanges(); //Delete(モンスターテーブルから一行削除) var プレシィ = uow.Query<モンスター>().Single(x => x.モンスター名 == "プレシィ"); uow.Remove(プレシィ); uow.SaveChanges(); //動的クエリ生成(実行時に動的にクエリを生成して実行) System.Random rand = new Random(); IQueryable<モンスター> ms = uow.Query<モンスター>(); if (rand.Next(3) < 1) { ms = ms.Where(x => x.最大lv < 20); } if (rand.Next(3) < 1) { ms = ms.Where(x => x.レア度 > 3); } foreach (var m in ms) { Console.WriteLine(m.モンスター名); } } Console.WriteLine("Press the Enter key to exit"); Console.ReadLine(); }
public LightSpeedInstallerRepository(DataProvider dataProvider, SchemaBase schema, string connectionString) { DataProvider = dataProvider; Schema = schema; ConnectionString = connectionString; _context = CreateLightSpeedContext(dataProvider, connectionString); }
public Repository() { var context = new LightSpeedContext <LightSpeedModelUnitOfWork>(); context.ConnectionString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString; context.IdentityMethod = IdentityMethod.IdentityColumn; _unitOfWork = context.CreateUnitOfWork(); }
/// <summary> /// Create a new UserAuth model unit of work. /// </summary> /// <param name="context">The context.</param> /// <returns>The <see cref="IUnitOfWork"/>.</returns> public IUnitOfWork Create(LightSpeedContext context) { return new UserAuthModelUnitOfWork { Context = context, Serializer = serializer }; }
private static LightSpeedContext<IdsUnitOfWork> getContext() { LightSpeedContext<IdsUnitOfWork> context = new LightSpeedContext<IdsUnitOfWork>(); context.DataProvider = DataProvider.MySql5; context.ConnectionString = LightSpeedContext.Default.ConnectionString; context.PluralizeTableNames = LightSpeedContext.Default.PluralizeTableNames; context.IdentityMethod = LightSpeedContext.Default.IdentityMethod; return context; }
public static List<UserInfo> GetData() { var _context1 = new LightSpeedContext<ChargeModalUnitOfWork>("default"); using (var unitOfWork = _context1.CreateUnitOfWork()) { var us = from u in unitOfWork.UserInfos select u; return us.ToList(); } }
/// <summary> /// Create a new UserAuth model unit of work. /// </summary> /// <param name="context">The context.</param> /// <returns>The <see cref="IUnitOfWork"/>.</returns> public IUnitOfWork Create(LightSpeedContext context) { return (new UserAuthModelUnitOfWork { Context = context, Serializer = serializer }); }
public void should_import_all_pages_categories_and_usernames() { // Arrange ApplicationSettings applicationSettings = new ApplicationSettings(); applicationSettings.AttachmentsFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ScrewturnImport"); if (Directory.Exists(applicationSettings.AttachmentsFolder)) Directory.Delete(applicationSettings.AttachmentsFolder, true); Directory.CreateDirectory(applicationSettings.AttachmentsFolder); applicationSettings.ConnectionString = _connectionString; applicationSettings.DatabaseName = "SqlServer2008"; var context = new LightSpeedContext(); context.ConnectionString = _connectionString; context.DataProvider = DataProvider.SqlServer2008; context.IdentityMethod = IdentityMethod.GuidComb; IUnitOfWork unitOfWork = context.CreateUnitOfWork(); IPageRepository pageRepository = new LightSpeedPageRepository(unitOfWork); IUserRepository userRepository = new LightSpeedUserRepository(unitOfWork); ScrewTurnImporter importer = new ScrewTurnImporter(applicationSettings, pageRepository, userRepository); // Act importer.ImportFromSqlServer(TestConstants.CONNECTION_STRING); // Assert User user = userRepository.GetUserByUsername("user2"); Assert.That(user.Id, Is.Not.EqualTo(Guid.Empty)); List<Page> pages = pageRepository.AllPages().ToList(); Assert.That(pages.Count, Is.EqualTo(3)); Page page1 = pages.FirstOrDefault(x => x.Title == "Screwturn page 1"); PageContent pageContent1 = pageRepository.GetLatestPageContent(page1.Id); Assert.That(page1.Tags, Is.EqualTo("Category1,")); AssertSameDateTimes(page1.CreatedOn, "2013-08-11 18:05"); AssertSameDateTimes(page1.ModifiedOn, "2013-08-11 18:05"); Assert.That(page1.CreatedBy, Is.EqualTo("admin")); Assert.That(page1.ModifiedBy, Is.EqualTo("admin")); Assert.That(pageContent1.Text, Is.EqualTo("This is an amazing Screwturn page.")); Page page2 = pages.FirstOrDefault(x => x.Title == "Screwturn page 2"); PageContent pageContent2 = pageRepository.GetLatestPageContent(page2.Id); Assert.That(page2.Tags, Is.EqualTo("Category1,Category2,")); AssertSameDateTimes(page2.CreatedOn, "2013-08-11 18:06"); AssertSameDateTimes(page2.ModifiedOn, "2013-08-11 18:06"); Assert.That(page2.CreatedBy, Is.EqualTo("user2")); Assert.That(page2.ModifiedBy, Is.EqualTo("user2")); Assert.That(pageContent2.Text, Is.EqualTo("Amazing screwturn page 2")); }
private IUnitOfWork CreateUnitOfWork() { var context = new LightSpeedContext(); context.ConnectionString = ConnectionString; context.DataProvider = DataProvider.SqlServer2008; context.IdentityMethod = IdentityMethod.GuidComb; IUnitOfWork unitOfWork = context.CreateUnitOfWork(); return unitOfWork; }
protected override void Setup() { context = new LightSpeedContext<NorthwindUnitOfWork>("LSNorthwind"); db = context.CreateUnitOfWork(); Customers = db.Customers.ToList(); Employees = db.Employees.ToList(); Orders = db.Orders.ToList(); Products = db.Products.ToList(); }
public ActionResult OrganisationSelect() { _context = new LightSpeedContext<TortugaModelUnitOfWork>("default"); List<Organisation> organisation; using (var data = _context.CreateUnitOfWork()) { var userProfile = data.UserProfiles.Single(n => n.UserName == User.Identity.Name); organisation = userProfile.Organisations.ToList(); } return PartialView("~/Views/Partial/Dashboard/OrganisationSelection.cshtml", organisation); }
public ActionResult LeftPane() { _context = new LightSpeedContext<TortugaModelUnitOfWork>("default"); Data.UserProfile profile; using (var data = _context.CreateUnitOfWork()) { profile = data.UserProfiles.Single(n => n.UserName == User.Identity.Name); } return PartialView("~/Views/Partial/Dashboard/LeftPane.cshtml", profile); }
protected override void Setup() { context = new LightSpeedContext<PerformanceTestUnitOfWork>("PerformanceTest"); using (var db = context.CreateUnitOfWork()) using (var transaction = db.BeginTransaction()) { foreach (var s in db.Simplests) db.Remove(s); db.SaveChanges(); transaction.Commit(); } }
private IUnitOfWork CreateUnitOfWork() { var context = new LightSpeedContext(); context.ConnectionString = ConnectionString; context.DataProvider = DataProvider.SqlServer2008; context.IdentityMethod = IdentityMethod.GuidComb; IUnitOfWork unitOfWork = context.CreateUnitOfWork(); return(unitOfWork); }
static void Main(string[] args) { Test = 0; Context = new LightSpeedContext<LightSpeedStoreModelUnitOfWork>("default") { IdentityMethod = IdentityMethod.Guid }; var meetings = Objectify("2012-12-22"); UpdateDataBase(meetings); /*GetSchedule("2012-12-09");*/ }
public Repository() { var context = new LightSpeedContext <SharpTwitUnitOfWork> { ConnectionString = @"server=.\sqlexpress;database=Flutter;Trusted_Connection=True;", IdentityMethod = IdentityMethod.IdentityColumn, QuoteIdentifiers = true }; context.Logger = new ConsoleLogger(); _unitOfWork = context.CreateUnitOfWork(); }
public static LightSpeedContext <NorthwindLightSpeedModelUnitOfWork> GetNewContext() { var connString = "Data Source=Northwind.sdf"; LightSpeedContext <NorthwindLightSpeedModelUnitOfWork> lsCtx = new LightSpeedContext <NorthwindLightSpeedModelUnitOfWork>(); lsCtx.ConnectionString = connString; lsCtx.DataProvider = DataProvider.SqlServerCE; lsCtx.IdentityMethod = IdentityMethod.IdentityColumn; lsCtx.QuoteIdentifiers = true; //lsCtx.VerboseLogging = true; //lsCtx.Logger = new Mindscape.LightSpeed.Logging.TraceLogger(); return(lsCtx); }
protected override void Setup() { context = new LightSpeedContext <PerformanceTestUnitOfWork>("PerformanceTest"); using (var db = context.CreateUnitOfWork()) using (var transaction = db.BeginTransaction()) { foreach (var s in db.Simplests) { db.Remove(s); } db.SaveChanges(); transaction.Commit(); } }
protected IPageRepository GetRepository() { ApplicationSettings appSettings = new ApplicationSettings(); appSettings.DatabaseName = "SqlServer2008"; appSettings.ConnectionString = TestConstants.CONNECTION_STRING; appSettings.UseBrowserCache = false; var context = new LightSpeedContext(); context.ConnectionString = TestConstants.CONNECTION_STRING; context.DataProvider = DataProvider.SqlServer2008; LightSpeedPageRepository repository = new LightSpeedPageRepository(context.CreateUnitOfWork()); return repository; }
public void TestConnection(DataStoreType dataStoreType, string connectionString) { LightSpeedContext context = ObjectFactory.GetInstance <LightSpeedContext>(); if (context == null) { throw new InvalidOperationException("Repository.Test failed - LightSpeedContext was null from the ObjectFactory"); } using (IDbConnection connection = context.DataProviderObjectFactory.CreateConnection()) { connection.ConnectionString = connectionString; connection.Open(); } }
private LightSpeedContext CreateLightSpeedContext(DataProvider dataProvider, string connectionString) { LightSpeedContext context = new LightSpeedContext(); context.ConnectionString = connectionString; context.DataProvider = dataProvider; context.IdentityMethod = IdentityMethod.GuidComb; context.CascadeDeletes = true; #if DEBUG context.VerboseLogging = true; context.Logger = new DatabaseLogger(); #endif return context; }
/// <summary> /// Create the database connection context. /// </summary> private static void CreateDbContext() { DbConnStr = string.Format( "Data Source={0};Version=3;", Path.GetFullPath(string.Format("{0}/Data/ss_auth.sqlite", TestContext.CurrentContext.WorkDirectory))); AuthContext = new LightSpeedContext <UserAuthModelUnitOfWork> { ConnectionString = DbConnStr, DataProvider = DataProvider.SQLite3, UnitOfWorkFactory = new UserAuthModelUnitOfWorkFactory(new JsvStringSerializer()), IdentityMethod = IdentityMethod.IdentityColumn }; }
private LightSpeedContext CreateLightSpeedContext(DataProvider dataProvider, string connectionString) { LightSpeedContext context = new LightSpeedContext(); context.ConnectionString = connectionString; context.DataProvider = dataProvider; context.IdentityMethod = IdentityMethod.GuidComb; context.CascadeDeletes = true; #if DEBUG context.VerboseLogging = true; context.Logger = new DatabaseLogger(); #endif return(context); }
protected IPageRepository GetRepository() { ApplicationSettings appSettings = new ApplicationSettings(); appSettings.DatabaseName = "SqlServer2008"; appSettings.ConnectionString = TestConstants.CONNECTION_STRING; appSettings.UseBrowserCache = false; var context = new LightSpeedContext(); context.ConnectionString = TestConstants.CONNECTION_STRING; context.DataProvider = DataProvider.SqlServer2008; LightSpeedPageRepository repository = new LightSpeedPageRepository(context.CreateUnitOfWork()); return(repository); }
public override string[] GetRolesForUser(string username) { _context = new LightSpeedContext <FairlieAuthenticUnitOfWork>("FA"); using (var uow = _context.CreateUnitOfWork()) { var user = uow.Customers.FirstOrDefault(x => x.Name == username); if (user == null) { return(null); } else { string[] roles = user.Roles.Select(x => x.RoleName).ToArray(); return(roles); } } }
public void should_import_files_in_attachments_folder() { // Arrange ApplicationSettings applicationSettings = new ApplicationSettings(); applicationSettings.AttachmentsFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ScrewturnImport"); if (Directory.Exists(applicationSettings.AttachmentsFolder)) { Directory.Delete(applicationSettings.AttachmentsFolder, true); } Directory.CreateDirectory(applicationSettings.AttachmentsFolder); applicationSettings.ConnectionString = _connectionString; applicationSettings.DatabaseName = "SqlServer2008"; var context = new LightSpeedContext(); context.ConnectionString = _connectionString; context.DataProvider = DataProvider.SqlServer2008; context.IdentityMethod = IdentityMethod.GuidComb; IUnitOfWork unitOfWork = context.CreateUnitOfWork(); IPageRepository pageRepository = new LightSpeedPageRepository(unitOfWork); IUserRepository userRepository = new LightSpeedUserRepository(unitOfWork); ScrewTurnImporter importer = new ScrewTurnImporter(applicationSettings, pageRepository, userRepository); // Act importer.ImportFromSqlServer(_connectionString); // Assert string file1 = Path.Combine(applicationSettings.AttachmentsFolder, "atextfile.txt"); string file2 = Path.Combine(applicationSettings.AttachmentsFolder, "screwdriver1.jpg"); FileInfo fileInfo1 = new FileInfo(file1); FileInfo fileInfo2 = new FileInfo(file2); Assert.True(fileInfo1.Exists); Assert.True(fileInfo2.Exists); Assert.That(fileInfo1.Length, Is.GreaterThan(0)); Assert.That(fileInfo2.Length, Is.GreaterThan(0)); }
public static CommerceModelUnitOfWork UnitOfWork() { if (context == null) { lock (lockObject) { if (context == null) { context = new LightSpeedContext<CommerceModelUnitOfWork>(); context.CascadeDeletes = false; context.ConnectionString = ConfigurationManager.AppSettings["sqlConnection"]; context.DataProvider = DataProvider.SqlServer2012; context.IdentityMethod = IdentityMethod.IdentityColumn; context.UpdateBatchSize = 20; //context.QuoteIdentifiers = true; //context.Logger = null; //context.Logger = new MindscapeLogger(); //context.VerboseLogging = true; } } } return context.CreateUnitOfWork(); }
public void Install(DataStoreType dataStoreType, string connectionString, bool enableCache) { LightSpeedContext context = ObjectFactory.GetInstance <LightSpeedContext>(); if (context == null) { throw new InvalidOperationException("Repository.Install failed - LightSpeedContext was null from the ObjectFactory"); } using (IDbConnection connection = context.DataProviderObjectFactory.CreateConnection()) { connection.ConnectionString = connectionString; connection.Open(); IDbCommand command = context.DataProviderObjectFactory.CreateCommand(); command.Connection = connection; dataStoreType.Schema.Drop(command); dataStoreType.Schema.Create(command); } }
public void TestConnection(string databaseProvider, string connectionString) { try { if (databaseProvider == SupportedDatabases.MongoDB) { string databaseName = MongoUrl.Create(connectionString).DatabaseName; MongoClient client = new MongoClient(connectionString); MongoServer server = client.GetServer(); MongoDatabase database = server.GetDatabase(databaseName); database.GetCollectionNames(); } else { var dataProvider = DataProvider.SqlServer2008; if (databaseProvider == SupportedDatabases.MySQL) { dataProvider = DataProvider.MySql5; } else if (databaseProvider == SupportedDatabases.Postgres) { dataProvider = DataProvider.PostgreSql9; } LightSpeedContext context = CreateLightSpeedContext(dataProvider, connectionString); using (IDbConnection connection = context.DataProviderObjectFactory.CreateConnection()) { connection.ConnectionString = connectionString; connection.Open(); } } } catch (Exception e) { throw new DatabaseException(e, "Unable to connect to the database using '{0}' - {1}", connectionString, e.Message); } }
private void SetupLightSpeed(string databaseProviderName, string connectionString) { DataProvider provider = DataProvider.SqlServer2008; if (databaseProviderName == SupportedDatabases.MySQL) { provider = DataProvider.MySql5; } else if (databaseProviderName == SupportedDatabases.Postgres) { provider = DataProvider.PostgreSql9; } Context = new LightSpeedContext(); Context.Cache = new CacheBroker(new DefaultCache()); Context.ConnectionString = connectionString; Context.DataProvider = provider; Context.IdentityMethod = IdentityMethod.GuidComb; Context.CascadeDeletes = true; UnitOfWorkFunc = context => LocatorStartup.Locator.GetInstance <IUnitOfWork>(); }
private void SetupLightSpeed(string databaseProviderName, string connectionString) { DataProvider provider = DataProvider.SqlServer2008; if (databaseProviderName == SupportedDatabases.MySQL) { provider = DataProvider.MySql5; } else if (databaseProviderName == SupportedDatabases.Postgres) { provider = DataProvider.PostgreSql9; } Context = new LightSpeedContext(); Context.Cache = new CacheBroker(new DefaultCache()); Context.ConnectionString = connectionString; Context.DataProvider = provider; Context.IdentityMethod = IdentityMethod.GuidComb; Context.CascadeDeletes = true; UnitOfWorkFunc = context => LocatorStartup.Locator.GetInstance<IUnitOfWork>(); }
public static CommerceModelUnitOfWork UnitOfWork() { if (context == null) { lock (lockObject) { if (context == null) { context = new LightSpeedContext <CommerceModelUnitOfWork>(); context.CascadeDeletes = false; context.ConnectionString = ConfigurationManager.AppSettings["sqlConnection"]; context.DataProvider = DataProvider.SqlServer2012; context.IdentityMethod = IdentityMethod.IdentityColumn; context.UpdateBatchSize = 20; //context.QuoteIdentifiers = true; //context.Logger = null; //context.Logger = new MindscapeLogger(); //context.VerboseLogging = true; } } } return(context.CreateUnitOfWork()); }
public void SetUp() { _ctx = new LightSpeedContext<ModelUnitOfWork>("Testing"); using (var uow = _ctx.CreateUnitOfWork()) { //clean-up uow.Remove(uow.FruitMetas); uow.Remove(uow.Fruits); //creating test data var fruitWithNoMeta = new Fruit { Description = "Apple" }; uow.Add(fruitWithNoMeta); var fruitWithMeta = new Fruit { Description = "Banana" }; fruitWithMeta.FruitMeta = new FruitMeta { Bitten = true }; uow.Add(fruitWithMeta); uow.SaveChanges(); } }
public Form1() { InitializeComponent(); _context = new LightSpeedContext<ChargeModalUnitOfWork>("default"); LightSpeedContext.UseMediumTrustCompatibility = true; }
public SimpleUnitOfWorkScope(LightSpeedContext <T> userUnitOfWork) { }
public void should_import_files_in_attachments_folder() { // Arrange ApplicationSettings applicationSettings = new ApplicationSettings(); applicationSettings.AttachmentsFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ScrewturnImport"); if (Directory.Exists(applicationSettings.AttachmentsFolder)) Directory.Delete(applicationSettings.AttachmentsFolder, true); Directory.CreateDirectory(applicationSettings.AttachmentsFolder); applicationSettings.ConnectionString = _connectionString; applicationSettings.DatabaseName = "SqlServer2008"; var context = new LightSpeedContext(); context.ConnectionString = _connectionString; context.DataProvider = DataProvider.SqlServer2008; context.IdentityMethod = IdentityMethod.GuidComb; IUnitOfWork unitOfWork = context.CreateUnitOfWork(); IPageRepository pageRepository = new LightSpeedPageRepository(unitOfWork); IUserRepository userRepository = new LightSpeedUserRepository(unitOfWork); ScrewTurnImporter importer = new ScrewTurnImporter(applicationSettings, pageRepository, userRepository); // Act importer.ImportFromSqlServer(_connectionString); // Assert string file1 = Path.Combine(applicationSettings.AttachmentsFolder, "atextfile.txt"); string file2 = Path.Combine(applicationSettings.AttachmentsFolder, "screwdriver1.jpg"); FileInfo fileInfo1 = new FileInfo(file1); FileInfo fileInfo2 = new FileInfo(file2); Assert.True(fileInfo1.Exists); Assert.True(fileInfo2.Exists); Assert.That(fileInfo1.Length, Is.GreaterThan(0)); Assert.That(fileInfo2.Length, Is.GreaterThan(0)); }
public void should_import_all_pages_categories_and_usernames() { // Arrange ApplicationSettings applicationSettings = new ApplicationSettings(); applicationSettings.AttachmentsFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ScrewturnImport"); if (Directory.Exists(applicationSettings.AttachmentsFolder)) { Directory.Delete(applicationSettings.AttachmentsFolder, true); } Directory.CreateDirectory(applicationSettings.AttachmentsFolder); applicationSettings.ConnectionString = _connectionString; applicationSettings.DatabaseName = "SqlServer2008"; var context = new LightSpeedContext(); context.ConnectionString = _connectionString; context.DataProvider = DataProvider.SqlServer2008; context.IdentityMethod = IdentityMethod.GuidComb; IUnitOfWork unitOfWork = context.CreateUnitOfWork(); IPageRepository pageRepository = new LightSpeedPageRepository(unitOfWork); IUserRepository userRepository = new LightSpeedUserRepository(unitOfWork); ScrewTurnImporter importer = new ScrewTurnImporter(applicationSettings, pageRepository, userRepository); // Act importer.ImportFromSqlServer(TestConstants.CONNECTION_STRING); // Assert User user = userRepository.GetUserByUsername("user2"); Assert.That(user.Id, Is.Not.EqualTo(Guid.Empty)); List <Page> pages = pageRepository.AllPages().ToList(); Assert.That(pages.Count, Is.EqualTo(3)); Page page1 = pages.FirstOrDefault(x => x.Title == "Screwturn page 1"); PageContent pageContent1 = pageRepository.GetLatestPageContent(page1.Id); Assert.That(page1.Tags, Is.EqualTo("Category1,")); AssertSameDateTimes(page1.CreatedOn, "2013-08-11 18:05"); AssertSameDateTimes(page1.ModifiedOn, "2013-08-11 18:05"); Assert.That(page1.CreatedBy, Is.EqualTo("admin")); Assert.That(page1.ModifiedBy, Is.EqualTo("admin")); Assert.That(pageContent1.Text, Is.EqualTo("This is an amazing Screwturn page.")); Page page2 = pages.FirstOrDefault(x => x.Title == "Screwturn page 2"); PageContent pageContent2 = pageRepository.GetLatestPageContent(page2.Id); Assert.That(page2.Tags, Is.EqualTo("Category1,Category2,")); AssertSameDateTimes(page2.CreatedOn, "2013-08-11 18:06"); AssertSameDateTimes(page2.ModifiedOn, "2013-08-11 18:06"); Assert.That(page2.CreatedBy, Is.EqualTo("user2")); Assert.That(page2.ModifiedBy, Is.EqualTo("user2")); Assert.That(pageContent2.Text, Is.EqualTo("Amazing screwturn page 2")); }
/// <summary> /// Create the database connection context. /// </summary> private static void CreateDbContext() { DbConnStr = string.Format( "Data Source={0};Version=3;", Path.GetFullPath(string.Format("{0}/Data/ss_auth.sqlite", TestContext.CurrentContext.WorkDirectory))); AuthContext = new LightSpeedContext<UserAuthModelUnitOfWork> { ConnectionString = DbConnStr, DataProvider = DataProvider.SQLite3, UnitOfWorkFactory = new UserAuthModelUnitOfWorkFactory(new JsvStringSerializer()), IdentityMethod = IdentityMethod.IdentityColumn }; }