public void DirectoryExists_DirectoryDoesNotExist_ReturnsFalse()
        {
            // arrange
            var helper = new FileSystemHelper();

            // act
            var result = helper.DirectoryExists("x:\\bluttanbla");

            // assert
            Assert.That(result, Is.False);
        }
		public void GetCurrentDirectory_ReturnsTheCurrentDirectory()
		{
			// arrange
			var helper = new FileSystemHelper();

			// act
			var result = helper.GetCurrentDirectory();

			// assert
			Assert.That(result, Is.EqualTo(Directory.GetCurrentDirectory()));
		}
        public void DirectoryExists_DirectoryDoesExist_ReturnsTrue()
        {
            // arrange
            var helper = new FileSystemHelper();

            // act
            var result = helper.DirectoryExists(Directory.GetCurrentDirectory());

            // assert
            Assert.That(result, Is.True);
        }
		public void GetFilesFromDirectory_ReturnsAllFilenamesThatMatchesPattern()
		{
			// arrange
			var helper = new FileSystemHelper();

			// act
			var result = helper.GetFilesFromDirectory(TestFilesDirectory, "error-*.xml");

			// assert
			Assert.That(result.Length, Is.EqualTo(20));
		}
        public void FileExists_FileDoesNotExist_ReturnsFalse()
        {
            // arrange
            var helper = new FileSystemHelper();
            var file = Path.Combine(TestFilesDirectory, "nonexistantfile.xml");

            // act
            var result = helper.FileExists(file);

            // assert
            Assert.That(result, Is.False);
        }
        public void CreateDirectory_CreatesDirectory()
        {
            // arrange
            var helper = new FileSystemHelper();
            var path = Path.Combine(TestArea, "a_new_directory");

            // act
            helper.CreateDirectory(path);

            // assert
            Assert.That(Directory.Exists(path), Is.True);
        }
		public void GetFileContent_FileExists_ReturnsContent()
		{
			// arrange
			var helper = new FileSystemHelper();
			var file = Path.Combine(TestFilesDirectory, "error-2011-04-10142706Z-d0da432d-fd3c-45b6-baf1-2cf49a5724e8.xml");

			// act
			var result = helper.GetFileContent(file);

			// assert
			Assert.That(result.Length, Is.GreaterThanOrEqualTo(1));
		}
		protected ErrorLogRepository CreateRepository(int maxNumberOfLogs = -1)
		{
			var fileSystemHelper = new FileSystemHelper();
			var log = new FakeLog();
			var settings = new FakeSettingsManager();
			settings.SetMaxNumberOfLogs(maxNumberOfLogs);

			var parser = new ErrorLogFileParser(log, new ClientInformationResolver());
			var datasource = new FileErrorLogSource(TestFilesDirectory, fileSystemHelper, parser, settings, log);

			var repository = new ErrorLogRepository(datasource);
			return repository;
		}
        public void CreateTextFile_CreatesTextFileContent()
        {
            // arrange
            var helper = new FileSystemHelper();
            var file = Path.Combine(TestArea, "a_new_file.txt");
            const string content = "hello world!";

            // act
            helper.CreateTextFile(file, content);

            // assert
            var contentInFile = File.ReadAllText(file);

            Assert.That(contentInFile, Is.EqualTo(content));
        }
		public void Export_Completed_RaisesCompletedEventArgs()
		{
			// arrange
			var repository = CreateRepository(maxNumberOfLogs: 1);
			var fileSystemHelper = new FileSystemHelper();
			var databaseCreator = new SqlCeDatabaseCreator(fileSystemHelper, new FakeLog());
			var exporter = new ErrorLogExporter(repository, databaseCreator);

			repository.Initialize();

			// act
			var eventWasRaised = false;
			exporter.OnCompleted += delegate { eventWasRaised = true; };

			exporter.Export(_databaseFilename);

			// assert
			Assert.That(eventWasRaised, Is.True);
		}
		public void Export_ProgessChanged_RaisesProgressChangedEventArgs()
		{
			// arrange
			var repository = CreateRepository(maxNumberOfLogs: 1);
			var fileSystemHelper = new FileSystemHelper();
			var databaseCreator = new SqlCeDatabaseCreator(fileSystemHelper, new FakeLog());
			var exporter = new ErrorLogExporter(repository, databaseCreator);

			repository.Initialize();

			// act
			var eventWasRaised = false;
			exporter.OnProgressChanged += delegate(object sender, ErrorLogExporterProgressEventArgs args)
			                              	{
			                              		eventWasRaised = true;
												Assert.That(args.Progress, Is.EqualTo("Exporting error log 1 of 1"));
			                              	};

			exporter.Export(_databaseFilename);

			// assert
			Assert.That(eventWasRaised, Is.True);
		}
        public void FileExists_FileExists_ReturnsTrue()
        {
            // arrange
            var helper = new FileSystemHelper();
            var file = Path.Combine(TestFilesDirectory, "error-2011-04-10142706Z-d0da432d-fd3c-45b6-baf1-2cf49a5724e8.xml");

            // act
            var result = helper.FileExists(file);

            // assert
            Assert.That(result, Is.True);
        }