-
Notifications
You must be signed in to change notification settings - Fork 10
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
Showing
86 changed files
with
5,657 additions
and
837 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 |
---|---|---|
|
@@ -22,3 +22,4 @@ build/ | |
lib/ | ||
source.zip | ||
7za.exe | ||
.backup/ |
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,99 @@ | ||
/* BackupFileTest.cs | ||
* part of Daniel's XL Toolbox NG | ||
* | ||
* Copyright 2014-2016 Daniel Kraus | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.IO; | ||
using NUnit.Framework; | ||
using XLToolbox.Backup; | ||
|
||
namespace XLToolbox.Test.Backup | ||
{ | ||
[TestFixture] | ||
class BackupFileTest | ||
{ | ||
[TestFixtureSetUp] | ||
public void TestFixtureSetup() | ||
{ | ||
Bovender.Logging.LogFile.Default.EnableDebugLogging(); | ||
} | ||
|
||
[Test] | ||
[TestCase("Auswertung_20151201_225513.xlsx", 2015, 12, 01, 22, 55, 13)] | ||
[TestCase("c:\\with\\dirs\\Auswertung_20141101_225513.xlsx", 2014, 11, 01, 22, 55, 13)] | ||
public void PathWithTimeStamp(string fileName, int yr, int mo, int dy, int hr, int mi, int se) | ||
{ | ||
BackupFile bf = new BackupFile(fileName); | ||
Assert.AreEqual(yr, bf.Year, "Year"); | ||
Assert.AreEqual(mo, bf.Month, "Month"); | ||
Assert.AreEqual(dy, bf.Day, "Day"); | ||
} | ||
|
||
[Test] | ||
public void BackupOfToday() | ||
{ | ||
string s = DateTime.Today.ToString(TimeStamp.FormatPattern); | ||
BackupFile bf = new BackupFile(String.Format("c:\testfile{0}.xlsx", s)); | ||
Assert.IsTrue(bf.IsOfToday); | ||
} | ||
|
||
[Test] | ||
public void BackupOfOtherDay() | ||
{ | ||
DateTime dt = new DateTime(2011, 10, 8, 9, 12, 15); | ||
string s = dt.ToString(TimeStamp.FormatPattern); | ||
BackupFile bf = new BackupFile(String.Format("c:\testfile{0}.xlsx", s)); | ||
Assert.IsFalse(bf.IsOfToday); | ||
} | ||
|
||
[Test] | ||
public void DeleteFile() | ||
{ | ||
string fn = Path.GetTempFileName(); | ||
Assert.IsTrue(File.Exists(fn)); | ||
BackupFile bf = new BackupFile(fn); | ||
Assert.IsTrue(bf.Delete(), "BackupFile.Delete() should return true"); | ||
Assert.IsFalse(File.Exists(fn)); | ||
} | ||
|
||
[Test] | ||
public void FailToDeleteFile() | ||
{ | ||
string fn = @"i:\do\not\exist\asdfasdfasdf.asdf"; | ||
Assert.IsFalse(File.Exists(fn), "Dummy file should not exist!"); | ||
BackupFile bf = new BackupFile(fn); | ||
Assert.IsFalse(bf.Delete(), "BackupFile.Delete() should return false"); | ||
} | ||
|
||
[Test] | ||
public void CreateBackup() | ||
{ | ||
string fn = Path.GetTempFileName(); | ||
string backupDir = Path.GetRandomFileName(); | ||
Directory.CreateDirectory(backupDir); | ||
DateTime dt = new DateTime(2015, 11, 23, 9, 31, 00); | ||
File.SetLastWriteTime(fn, dt); | ||
BackupFile bf = BackupFile.CreateBackup(fn, backupDir); | ||
Assert.IsNotNull(bf); | ||
Assert.AreEqual(dt, bf.TimeStamp.DateTime); | ||
Directory.Delete(backupDir, true); | ||
File.Delete(fn); | ||
} | ||
} | ||
} |
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,136 @@ | ||
/* BackupFilesTest.cs | ||
* part of Daniel's XL Toolbox NG | ||
* | ||
* Copyright 2014-2016 Daniel Kraus | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.IO; | ||
using NUnit.Framework; | ||
using XLToolbox.Backup; | ||
|
||
namespace XLToolbox.Test.Backup | ||
{ | ||
[TestFixture] | ||
class BackupsTest | ||
{ | ||
[TestFixtureSetUp] | ||
public void TestFixtureSetup() | ||
{ | ||
Bovender.Logging.LogFile.Default.EnableDebugLogging(); | ||
} | ||
|
||
[Test] | ||
public void BackupDir() | ||
{ | ||
string dir = ".backup"; | ||
Backups bf = new Backups(@"c:\test.xlsx", dir); | ||
Assert.AreEqual(dir, bf.BackupDir); | ||
} | ||
|
||
[Test] | ||
public void BackupPath() | ||
{ | ||
string baseDir = @"c:\my\fancy\folder"; | ||
Backups bf = new Backups(baseDir + @"\test.xlsx", ".backup"); | ||
Assert.AreEqual(baseDir + @"\.backup", bf.BackupPath); | ||
} | ||
|
||
[Test] | ||
public void InvalidBackupPath() | ||
{ | ||
string baseDir = @"c:\my\fancy\folder"; | ||
Assert.Throws<ArgumentException>(() => { | ||
Backups bf = new Backups(baseDir + @"\test.xlsx", @"c:\.backup"); | ||
}); | ||
} | ||
|
||
[Test] | ||
public void EnumerateBackups() | ||
{ | ||
string tmpPath = Path.GetTempPath(); | ||
string backupDir = Path.GetRandomFileName(); | ||
string basename = "myfile"; | ||
string file = basename + ".xlsx"; | ||
string backupsStub = Path.Combine(tmpPath, backupDir, basename); | ||
Directory.CreateDirectory(Path.Combine(tmpPath, backupDir)); | ||
File.Create(backupsStub + "_20151008_133212.xlsx").Dispose(); | ||
File.Create(backupsStub + "_20141008_133212.xlsx").Dispose(); | ||
File.Create(backupsStub + "_20151123_160000.xlsx").Dispose(); | ||
File.Create(backupsStub + "_notaback_up0000.xlsx").Dispose(); | ||
Backups b = new Backups(Path.Combine(tmpPath, basename) + ".xlsx", backupDir); | ||
Assert.AreEqual(3, b.Count); | ||
Directory.Delete(Path.Combine(tmpPath, backupDir), true); | ||
} | ||
|
||
[Test] | ||
public void Purge() | ||
{ | ||
string tmpPath = Path.GetTempPath(); | ||
string backupDir = Path.GetRandomFileName(); | ||
string basename = "myfile"; | ||
string file = basename + ".xlsx"; | ||
string backupsStub = Path.Combine(tmpPath, backupDir, basename); | ||
DateTime dt = DateTime.Today; | ||
string today = dt.ToString("yyyyMMdd"); | ||
string yesterday = dt.AddDays(-1).ToString("yyyyMMdd"); | ||
Directory.CreateDirectory(Path.Combine(tmpPath, backupDir)); | ||
|
||
List<string> expected = new List<string>(); | ||
TouchFile(String.Format("{0}_{1}_090000.xlsx", backupsStub, yesterday)); | ||
TouchFile(String.Format("{0}_{1}_100000.xlsx", backupsStub, yesterday), expected); | ||
TouchFile(String.Format("{0}_{1}_080000.xlsx", backupsStub, today), expected); | ||
TouchFile(String.Format("{0}_{1}_090000.xlsx", backupsStub, today), expected); | ||
TouchFile(String.Format("{0}_{1}_100000.xlsx", backupsStub, today), expected); | ||
TouchFile(String.Format("{0}_{1}_110000.xlsx", backupsStub, today), expected); | ||
TouchFile(String.Format("{0}_{1}_120000.xlsx", backupsStub, today), expected); | ||
TouchFile(String.Format("{0}_{1}_100000.xlsx", backupsStub, dt.AddDays(-2).ToString("yyyyMMdd")), expected); | ||
TouchFile(String.Format("{0}_{1}_100000.xlsx", backupsStub, dt.AddDays(-4).ToString("yyyyMMdd")), expected); | ||
TouchFile(String.Format("{0}_{1}_090000.xlsx", backupsStub, dt.AddDays(-4).ToString("yyyyMMdd"))); | ||
TouchFile(String.Format("{0}_{1}_100000.xlsx", backupsStub, dt.AddDays(-5).ToString("yyyyMMdd")), expected); | ||
TouchFile(String.Format("{0}_{1}_100000.xlsx", backupsStub, dt.AddDays(-6).ToString("yyyyMMdd")), expected); | ||
TouchFile(String.Format("{0}_{1}_100000.xlsx", backupsStub, dt.AddDays(-7).ToString("yyyyMMdd")), expected); | ||
TouchFile(String.Format("{0}_{1}_100000.xlsx", backupsStub, dt.AddDays(-8).ToString("yyyyMMdd")), expected); | ||
TouchFile(backupsStub + "_20151008_133212.xlsx", expected); | ||
TouchFile(backupsStub + "_20151007_120000.xlsx"); | ||
TouchFile(backupsStub + "_20141008_133212.xlsx", expected); | ||
TouchFile(backupsStub + "_20140515_120000.xlsx", expected); | ||
TouchFile(backupsStub + "_20140102_073212.xlsx", expected); | ||
TouchFile(backupsStub + "_20151123_160000.xlsx", expected); | ||
|
||
Backups b = new Backups(Path.Combine(tmpPath, basename) + ".xlsx", backupDir); | ||
b.Purge(); | ||
|
||
List<string> actual = b.Files.Select(f => f.Path).ToList(); | ||
expected.Sort(); | ||
actual.Sort(); | ||
Assert.AreEqual(expected, actual); | ||
Directory.Delete(Path.Combine(tmpPath, backupDir), true); | ||
} | ||
|
||
private void TouchFile(string fn) | ||
{ | ||
File.Create(fn).Dispose(); | ||
} | ||
|
||
private void TouchFile(string fn, List<string> rememberList) | ||
{ | ||
TouchFile(fn); | ||
rememberList.Add(fn); | ||
} | ||
} | ||
} |
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 @@ | ||
/* TimeStampTest.cs | ||
* part of Daniel's XL Toolbox NG | ||
* | ||
* Copyright 2014-2016 Daniel Kraus | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using NUnit.Framework; | ||
using XLToolbox.Backup; | ||
|
||
namespace XLToolbox.Test.Backup | ||
{ | ||
[TestFixture] | ||
class TimeStampTest | ||
{ | ||
[Test] | ||
[TestCase("Auswertung_20151201_225513.xlsx", 2015, 12, 01, 22, 55, 13)] | ||
[TestCase("c:\\with\\dirs\\Auswertung_20141101_225513.xlsx", 2014, 11, 01, 22, 55, 13)] | ||
public void ParseFileName(string fileName, int yr, int mo, int dy, int hr, int mi, int se) | ||
{ | ||
TimeStamp ts = new TimeStamp(fileName); | ||
Assert.AreEqual(new DateTime(yr, mo, dy, hr, mi, se), ts.DateTime); | ||
} | ||
|
||
[Test] | ||
public void FormatTimeStamp() | ||
{ | ||
TimeStamp ts = new TimeStamp(); | ||
ts.DateTime = new DateTime(2015, 11, 23, 10, 30, 00); | ||
Assert.AreEqual("_20151123_103000", ts.ToString()); | ||
} | ||
|
||
[Test] | ||
public void FileNameWithTimeStamp() | ||
{ | ||
TimeStamp ts = new TimeStamp("Auswertung_20151201_225513.xlsx"); | ||
Assert.IsTrue(ts.HasValue); | ||
} | ||
|
||
[Test] | ||
public void FileNameWithoutTimeStamp() | ||
{ | ||
TimeStamp ts = new TimeStamp("Auswertung.xlsx"); | ||
Assert.IsFalse(ts.HasValue); | ||
} | ||
} | ||
} |
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 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,51 @@ | ||
/* ColumnHelperTest.cs | ||
* part of Daniel's XL Toolbox NG | ||
* | ||
* Copyright 2014-2016 Daniel Kraus | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using NUnit.Framework; | ||
using XLToolbox.Excel.Models; | ||
|
||
namespace XLToolbox.Test.Excel | ||
{ | ||
[TestFixture] | ||
class ColumnHelperTest | ||
{ | ||
[Test] | ||
[TestCase("A", 1, false)] | ||
[TestCase("$AA", 27, true)] | ||
[TestCase("XFD", 16384, false)] | ||
public void ParseReference(string reference, long number, bool isFixed) | ||
{ | ||
ColumnHelper c = new ColumnHelper(reference); | ||
Assert.AreEqual(number, c.Number); | ||
Assert.AreEqual(isFixed, c.IsFixed); | ||
} | ||
|
||
[Test] | ||
[TestCase(1, false, "A")] | ||
[TestCase(28, true, "$AB")] | ||
[TestCase(16384, false, "XFD")] | ||
public void BuildReference(long number, bool isFixed, string reference) | ||
{ | ||
ColumnHelper c = new ColumnHelper(number, isFixed); | ||
Assert.AreEqual(reference, c.Reference); | ||
} | ||
} | ||
} |
Oops, something went wrong.