This repository has been archived by the owner on Oct 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
caa0dec
commit 8e3db5a
Showing
23 changed files
with
483 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -403,7 +403,3 @@ tools | |
|
||
# MacOS | ||
.DS_Store | ||
|
||
# Jetbrain Rider | ||
.idea | ||
*.DotSettings.user |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/FileOperationScheduler.Test/FileOperationScheduler.Test/Helpers/ZipHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System.IO.Compression; | ||
|
||
namespace FileOperationScheduler.Test.Helpers; | ||
|
||
public class ZipHelper | ||
{ | ||
/// <summary> | ||
/// Zip the specified text file into the specified zip file | ||
/// </summary> | ||
/// <param name="textFile">A random text file to create in the zip</param> | ||
/// <param name="zipFile">The resulting zip file</param> | ||
public static void Zip(string textFile, string zipFile) | ||
{ | ||
var sourceDir = new FileInfo(textFile).Directory?.FullName; | ||
|
||
if (sourceDir is null) throw new FileNotFoundException($"The file '{textFile}' does not exist."); | ||
|
||
using var fileStream = File.Create(textFile); | ||
using var writer = new StreamWriter(fileStream); | ||
{ | ||
writer.WriteLine("some random text"); | ||
writer.Flush(); | ||
writer.Close(); | ||
} | ||
|
||
ZipFile.CreateFromDirectory(sourceDir, zipFile); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
...r.Test/FileOperationScheduler.Test/SystemTests/Operations/MoveDirectoryOperationShould.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using FileOperationScheduler.Infrastructure.Operations; | ||
using FluentAssertions; | ||
|
||
namespace FileOperationScheduler.Test.SystemTests.Operations; | ||
|
||
public class MoveDirectoryOperationShould : IDisposable | ||
{ | ||
private const string SourceName = "RandomDirectory_src_MVDIR"; | ||
private const string DestinationName = "RandomDirectory_dst_MVDIR"; | ||
|
||
public MoveDirectoryOperationShould() | ||
{ | ||
Source = Path.Combine(Path.GetTempPath(), SourceName); | ||
|
||
Cleanup(); | ||
Directory.CreateDirectory(Source); | ||
|
||
using (var fileStream = File.Create(Path.Combine(Source, "output.txt"))) | ||
using (var writer = new StreamWriter(fileStream)) | ||
{ | ||
writer.WriteLine("some random text"); | ||
} | ||
|
||
Destination = Path.Combine(Path.GetTempPath(), DestinationName); | ||
} | ||
|
||
private string Source { get; } | ||
|
||
private string Destination { get; } | ||
|
||
[Fact] | ||
public async Task BeProcessed() | ||
{ | ||
// ACT | ||
var moveDirectory = OperationFactory.MoveDirectory(Source, Destination); | ||
await moveDirectory.ProcessAsync(); | ||
|
||
// ASSERT | ||
Directory.Exists(Destination) | ||
.Should().BeTrue($"'{Destination}' should be created"); | ||
|
||
Directory.EnumerateFiles(Destination) | ||
.Count() | ||
.Should().BeGreaterThan(0); | ||
} | ||
|
||
public void Dispose() => Cleanup(); | ||
|
||
private void Cleanup() | ||
{ | ||
if (Directory.Exists(Source)) Directory.Delete(Source, true); | ||
if (Directory.Exists(Destination)) Directory.Delete(Destination, true); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...Test/FileOperationScheduler.Test/SystemTests/Operations/RemoveDirectoryOperationShould.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using FileOperationScheduler.Infrastructure.Operations; | ||
using FluentAssertions; | ||
|
||
namespace FileOperationScheduler.Test.SystemTests.Operations; | ||
|
||
public class RemoveDirectoryOperationShould | ||
{ | ||
[Fact] | ||
public async Task BeProcessed() | ||
{ | ||
// ARRANGE | ||
var directory = Path.Combine(Path.GetTempPath(), "RandomDirectory"); | ||
Directory.CreateDirectory(directory); | ||
|
||
|
||
// ACT | ||
var rmdir = OperationFactory.RemoveDirectory(directory); | ||
Directory.Exists(directory).Should().BeTrue(); | ||
|
||
await rmdir.ProcessAsync(); | ||
|
||
// ASSERT | ||
Directory.Exists(directory).Should().BeFalse(); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
....Test/FileOperationScheduler.Test/SystemTests/Operations/UnzipDirectoryOperationShould.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using FileOperationScheduler.Infrastructure.Operations; | ||
using FileOperationScheduler.Test.Helpers; | ||
using FluentAssertions; | ||
using Xunit.Abstractions; | ||
|
||
namespace FileOperationScheduler.Test.SystemTests.Operations; | ||
|
||
public class UnzipDirectoryOperationShould : IDisposable | ||
{ | ||
private const string ArchiveFileName = "Package.zip"; | ||
private const string SourceDirectoryName = "RandomDirectory_src_ZIP"; | ||
private const string DestinationDirectoryName = "RandomDirectory_dst_ZIP"; | ||
private const string TextFileName = "random_text_file.txt"; | ||
|
||
public UnzipDirectoryOperationShould(ITestOutputHelper output) | ||
{ | ||
Source = Path.Combine(Path.GetTempPath(), SourceDirectoryName); | ||
Destination = Path.Combine(Path.GetTempPath(), DestinationDirectoryName); | ||
ArchiveFile = Path.Combine(Path.GetTempPath(), Destination, ArchiveFileName); | ||
|
||
Cleanup(); | ||
|
||
Directory.CreateDirectory(Source); | ||
Directory.CreateDirectory(Destination); | ||
|
||
var outfile = Path.Combine(Source, TextFileName); | ||
|
||
output.WriteLine($"Source dir : '{Source}'"); | ||
output.WriteLine($"Destination dir: '{Destination}'"); | ||
output.WriteLine($"Archive dir : '{ArchiveFile}'"); | ||
|
||
ZipHelper.Zip(outfile, ArchiveFile); | ||
} | ||
|
||
[Fact] | ||
public async Task BeProcessed() | ||
{ | ||
// ACT | ||
var unzipDir = OperationFactory.UnzipDirectory(ArchiveFile, Destination); | ||
await unzipDir.ProcessAsync(); | ||
|
||
// ASSERT | ||
var path = Path.Combine(Destination, TextFileName); | ||
Directory.EnumerateFiles(Destination) | ||
.Count(f => f == path) | ||
.Should().BeGreaterThan(0); | ||
} | ||
|
||
private string Source { get; } | ||
private string ArchiveFile { get; } | ||
private string Destination { get; } | ||
|
||
private void Cleanup() | ||
{ | ||
if (Directory.Exists(Source)) Directory.Delete(Source, true); | ||
if (Directory.Exists(Destination)) Directory.Delete(Destination, true); | ||
if (File.Exists(ArchiveFile)) File.Delete(ArchiveFile); | ||
} | ||
|
||
public void Dispose() => Cleanup(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
src/FileOperationScheduler.Test/FileOperationScheduler.Test/SystemTests/SerialiserShould.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
using FileOperationScheduler.Infrastructure; | ||
using FileOperationScheduler.Infrastructure.Operations; | ||
using FileOperationScheduler.Test.Helpers; | ||
using FluentAssertions; | ||
using Newtonsoft.Json; | ||
using Xunit.Abstractions; | ||
using Newtonsoft; | ||
|
||
namespace FileOperationScheduler.Test.SystemTests; | ||
|
||
public class SerialiserShould : IDisposable | ||
{ | ||
private readonly string _destinationDir = Path.Combine(Path.GetTempPath(), "destination"); | ||
private readonly string _directory = Path.Combine(Path.GetTempPath(), "toRemove"); | ||
|
||
private readonly string _jsonFile = Path.Combine(Path.GetTempPath(), $"{Path.GetRandomFileName()}.json"); | ||
private readonly string _zipFile = Path.Combine(Path.GetTempPath(), $"{Path.GetRandomFileName()}.zip"); | ||
|
||
private readonly ITestOutputHelper _output; | ||
|
||
public SerialiserShould(ITestOutputHelper output) | ||
{ | ||
_output = output; | ||
|
||
_output.WriteLine($"Zip file : {_zipFile}"); | ||
_output.WriteLine($"Destination dir: {_destinationDir}"); | ||
_output.WriteLine($"Directory : {_directory}"); | ||
} | ||
|
||
|
||
[Fact] | ||
public async Task Serialize() | ||
{ | ||
// ARRANGE | ||
if (!Directory.Exists(_destinationDir)) Directory.CreateDirectory(_destinationDir); | ||
if (!Directory.Exists(_directory)) Directory.CreateDirectory(_directory); | ||
|
||
var textFile = Path.Combine(_directory, "some.txt"); | ||
await File.WriteAllTextAsync(textFile, "Some random text"); | ||
ZipHelper.Zip(textFile, _zipFile); | ||
File.Delete(textFile); | ||
|
||
var scheduler = await OperationSchedulerFactory.RetrieveFromFileAsync(_jsonFile); | ||
await scheduler.AddOperation(OperationFactory.RemoveDirectory(_directory)) | ||
.AddOperation(OperationFactory.UnzipDirectory(_zipFile, _destinationDir)) | ||
.SavePlanAsync(); | ||
|
||
OutputJsonFile(); | ||
|
||
// ACT | ||
var sut = await OperationSchedulerFactory.RetrieveFromFileAsync(_jsonFile); | ||
await sut.ExecutePlanAsync(); | ||
|
||
// ASSERT | ||
Directory.Exists(_directory) | ||
.Should().BeFalse(); | ||
|
||
File.Exists(_jsonFile) | ||
.Should().BeTrue($"'{_jsonFile}' should exist"); | ||
|
||
Directory.GetFiles(_destinationDir) | ||
.Length | ||
.Should().BeGreaterThan(0); | ||
} | ||
|
||
[Fact] | ||
public async Task Deserialize() | ||
{ | ||
var scheduler = await OperationSchedulerFactory.RetrieveFromFileAsync(_jsonFile); | ||
|
||
Directory.CreateDirectory(_destinationDir); | ||
|
||
await scheduler.AddOperation(OperationFactory.RemoveDirectory(_destinationDir)) | ||
.AddOperation(OperationFactory.UnzipDirectory(_zipFile, _destinationDir)) | ||
.SavePlanAsync(); | ||
|
||
var deserializedScheduler = await OperationSchedulerFactory.RetrieveFromFileAsync(_jsonFile); | ||
deserializedScheduler.GetState() | ||
.OperationCount | ||
.Should().Be(2); | ||
} | ||
|
||
private void OutputJsonFile() | ||
{ | ||
if (!File.Exists(_jsonFile)) | ||
{ | ||
_output.WriteLine($"File '{_jsonFile}' does not exist."); | ||
return; | ||
} | ||
|
||
var json = File.ReadAllText(_jsonFile); | ||
json = JsonConvert.SerializeObject(JsonConvert.DeserializeObject(json), Formatting.Indented); | ||
_output.WriteLine("Json configuration file contains:"); | ||
_output.WriteLine(json); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
if (File.Exists(_jsonFile)) File.Delete(_jsonFile); | ||
if (File.Exists(_zipFile)) File.Delete(_zipFile); | ||
|
||
if (Directory.Exists(_destinationDir)) Directory.Delete(_destinationDir, true); | ||
if (Directory.Exists(_directory)) Directory.Delete(_directory, true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
namespace FileOperationScheduler.Core; | ||
|
||
public interface IOperation | ||
public interface IOperation : IOperationConfiguration | ||
{ | ||
string? Name { get; set; } | ||
string? Parameters { get; set; } | ||
Task ProcessAsync(); | ||
} |
Oops, something went wrong.