Пример #1
0
		public void ZipDirectory_ReleasesLockOnZipFile()
		{
			var fixture = new Fixture();
			string sourceDirectory = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
			Directory.CreateDirectory(sourceDirectory);
			string sourceFile1 = Path.Combine(sourceDirectory, Guid.NewGuid().ToString() + ".tmp");
			File.WriteAllText(sourceFile1, fixture.Create<string>());
			string sourceFile2 = Path.Combine(sourceDirectory, Guid.NewGuid().ToString() + ".tmp");
			File.WriteAllText(sourceFile2, fixture.Create<string>());

			string zipFilePath = Path.Combine(sourceDirectory, Guid.NewGuid().ToString() + ".zip");
			try
			{

				var sut = new Zipper(new Mock<ILog>().Object);
				sut.ZipDirectory(sourceDirectory, zipFilePath);
				File.Delete(zipFilePath);
			}
			finally
			{
				try 
				{
					Directory.Delete(sourceDirectory, true);
				}
				catch {}

				try
				{
					File.Delete(zipFilePath);
				}
				catch { }
			}
		}