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")); }
protected override bool HasEmptyTables() { IUnitOfWork unitOfWork = CreateUnitOfWork(); var settingsRepository = new LightSpeedSettingsRepository(unitOfWork); var userRepository = new LightSpeedUserRepository(unitOfWork); var pageRepository = new LightSpeedPageRepository(unitOfWork); return pageRepository.AllPages().Count() == 0 && pageRepository.AllPageContents().Count() == 0 && userRepository.FindAllAdmins().Count() == 0 && userRepository.FindAllEditors().Count() == 0 && settingsRepository.GetSiteSettings() != null; }
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 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)); }