Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/duplicati/duplicati.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenneth Hsu <kennethhsu@gmail.com>2020-08-24 00:24:27 +0300
committerKenneth Hsu <kennethhsu@gmail.com>2020-08-24 17:41:00 +0300
commitacba6351dc1fad105aeaa908e596327558bfdeb5 (patch)
tree4966d012033737b9003bf6122700c2e88c2f28f1 /Duplicati/UnitTest
parentd4d7874aaf873075e73939a824d4a5559030eda3 (diff)
Extract local function to method.
Diffstat (limited to 'Duplicati/UnitTest')
-rw-r--r--Duplicati/UnitTest/ImportExportTests.cs42
1 files changed, 21 insertions, 21 deletions
diff --git a/Duplicati/UnitTest/ImportExportTests.cs b/Duplicati/UnitTest/ImportExportTests.cs
index 5d92f2e16..9406cc43a 100644
--- a/Duplicati/UnitTest/ImportExportTests.cs
+++ b/Duplicati/UnitTest/ImportExportTests.cs
@@ -16,7 +16,7 @@
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
using Duplicati.Server.Database;
using Duplicati.Server.Serialization.Interface;
-using NUnit.Framework;
+using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.IO;
@@ -47,40 +47,40 @@ namespace Duplicati.UnitTest
}
}
+ IBackup CreateBackup(string name, string username, string password, Dictionary<string, string> metadata)
+ {
+ return new Backup
+ {
+ Description = "Mock Backup Description",
+ Filters = new IFilter[0],
+ ID = "1",
+ Metadata = metadata,
+ Name = name,
+ Settings = new[] { new Setting { Name = "passphrase", Value = "12345" } },
+ Sources = new[] { "Mock Backup Source" },
+ Tags = new[] { "Tags" },
+ TargetURL = $"file:///mock_backup_target?auth-username={username}&auth-password={password}"
+ };
+ }
+
[Test]
[Category("ImportExport")]
public void RoundTrip()
{
Dictionary<string, string> metadata = new Dictionary<string, string> { { "SourceFilesCount", "1" } };
- IBackup CreateBackup(string name)
- {
- return new Backup
- {
- Description = "Mock Backup Description",
- Filters = new IFilter[0],
- ID = "1",
- Metadata = metadata,
- Name = name,
- Settings = new[] { new Setting { Name = "passphrase", Value = "12345" } },
- Sources = new[] { "Mock Backup Source" },
- Tags = new[] { "Tags" },
- TargetURL = "file:///mock_backup_target"
- };
- }
-
Dictionary<string, string> advancedOptions = new Dictionary<string, string> { { "server-datafolder", this.serverDatafolder } };
using (Duplicati.Server.Program.DataConnection = Duplicati.Server.Program.GetDatabaseConnection(advancedOptions))
{
// Unencrypted file, don't import metadata.
string unencryptedWithoutMetadata = Path.Combine(this.serverDatafolder, Path.GetRandomFileName());
- File.WriteAllBytes(unencryptedWithoutMetadata, Server.WebServer.RESTMethods.Backup.ExportToJSON(CreateBackup("unencrypted without metadata"), null));
+ File.WriteAllBytes(unencryptedWithoutMetadata, Server.WebServer.RESTMethods.Backup.ExportToJSON(this.CreateBackup("unencrypted without metadata", "user", "password", metadata), null));
Duplicati.Server.WebServer.RESTMethods.Backups.ImportBackup(unencryptedWithoutMetadata, false, () => null, advancedOptions);
Assert.AreEqual(1, Duplicati.Server.Program.DataConnection.Backups.Length);
Assert.AreEqual(0, Duplicati.Server.Program.DataConnection.Backups[0].Metadata.Count);
// Unencrypted file, import metadata.
string unencryptedWithMetadata = Path.Combine(this.serverDatafolder, Path.GetRandomFileName());
- File.WriteAllBytes(unencryptedWithMetadata, Server.WebServer.RESTMethods.Backup.ExportToJSON(CreateBackup("unencrypted with metadata"), null));
+ File.WriteAllBytes(unencryptedWithMetadata, Server.WebServer.RESTMethods.Backup.ExportToJSON(this.CreateBackup("unencrypted with metadata", "user", "password", metadata), null));
Duplicati.Server.WebServer.RESTMethods.Backups.ImportBackup(unencryptedWithMetadata, true, () => null, advancedOptions);
Assert.AreEqual(2, Duplicati.Server.Program.DataConnection.Backups.Length);
Assert.AreEqual(metadata.Count, Duplicati.Server.Program.DataConnection.Backups[1].Metadata.Count);
@@ -88,14 +88,14 @@ namespace Duplicati.UnitTest
// Encrypted file, don't import metadata.
string encryptedWithoutMetadata = Path.Combine(this.serverDatafolder, Path.GetRandomFileName());
string passphrase = "abcde";
- File.WriteAllBytes(encryptedWithoutMetadata, Server.WebServer.RESTMethods.Backup.ExportToJSON(CreateBackup("encrypted without metadata"), passphrase));
+ File.WriteAllBytes(encryptedWithoutMetadata, Server.WebServer.RESTMethods.Backup.ExportToJSON(this.CreateBackup("encrypted without metadata", "user", "password", metadata), passphrase));
Duplicati.Server.WebServer.RESTMethods.Backups.ImportBackup(encryptedWithoutMetadata, false, () => passphrase, advancedOptions);
Assert.AreEqual(3, Duplicati.Server.Program.DataConnection.Backups.Length);
Assert.AreEqual(0, Duplicati.Server.Program.DataConnection.Backups[2].Metadata.Count);
// Encrypted file, import metadata.
string encryptedWithMetadata = Path.Combine(this.serverDatafolder, Path.GetRandomFileName());
- File.WriteAllBytes(encryptedWithMetadata, Server.WebServer.RESTMethods.Backup.ExportToJSON(CreateBackup("encrypted with metadata"), passphrase));
+ File.WriteAllBytes(encryptedWithMetadata, Server.WebServer.RESTMethods.Backup.ExportToJSON(this.CreateBackup("encrypted with metadata", "user", "password", metadata), passphrase));
Duplicati.Server.WebServer.RESTMethods.Backups.ImportBackup(encryptedWithMetadata, true, () => passphrase, advancedOptions);
Assert.AreEqual(4, Duplicati.Server.Program.DataConnection.Backups.Length);
Assert.AreEqual(metadata.Count, Duplicati.Server.Program.DataConnection.Backups[3].Metadata.Count);