Changed test project type to WIndows 8.1

Changed test project framework from Nunit to MSTest
Changed HashAlgorithm from BouncyCastle to WinRT crypto
WIP progress bar in opendatabaseusercontrol
TextBox with button made generic
WIP implement copy on button click in Entry Page
This commit is contained in:
2017-11-06 19:01:01 +01:00
committed by BONNEVILLE Geoffroy
parent 53a54252e3
commit 8e690747e2
85 changed files with 2836 additions and 672 deletions

View File

@@ -1,76 +1,84 @@
using NUnit.Framework;
using System;
using System;
using System.IO;
#if KeePassLib
using KeePassLib.Keys;
#else
using Windows.Storage;
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
using ModernKeePassLib.Keys;
#endif
using ModernKeePassLib.Utility;
namespace ModernKeePassLib.Test.Keys
{
[TestFixture ()]
public class KcpKeyFileTests
{
const string testCreateFile = "TestCreate.xml";
const string testKey = "0123456789";
const string expectedFileStart =
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" +
"<KeyFile>\r\n" +
"\t<Meta>\r\n" +
"\t\t<Version>1.00</Version>\r\n" +
"\t</Meta>\r\n" +
"\t<Key>\r\n" +
"\t\t<Data>";
const string expectedFileEnd = "\t</Key>\r\n" +
"</KeyFile>\r\n";
[Test ()]
public void TestConstruct ()
[TestClass]
public class KcpKeyFileTests
{
var expectedKeyData = new byte[32] {
0xC1, 0xB1, 0x12, 0x77, 0x23, 0xB8, 0x99, 0xB8,
0xB9, 0x3B, 0x1B, 0xFF, 0x6C, 0xBE, 0xA1, 0x5B,
0x8B, 0x99, 0xAC, 0xBD, 0x99, 0x51, 0x85, 0x95,
0x31, 0xAA, 0x14, 0x3D, 0x95, 0xBF, 0x63, 0xFF
};
private const string TestCreateFile = "TestCreate.xml";
private const string TestKey = "0123456789";
var fullPath = Path.Combine(Path.GetTempPath(), testCreateFile);
using (var fs = new FileStream(fullPath, FileMode.Create)) {
using (var sw = new StreamWriter(fs)) {
sw.Write (expectedFileStart);
sw.Write (testKey);
sw.Write (expectedFileEnd);
private const string ExpectedFileStart =
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" +
"<KeyFile>\r\n" +
"\t<Meta>\r\n" +
"\t\t<Version>1.00</Version>\r\n" +
"\t</Meta>\r\n" +
"\t<Key>\r\n" +
"\t\t<Data>";
private const string ExpectedFileEnd = "\t</Key>\r\n" +
"</KeyFile>\r\n";
[TestMethod]
public void TestConstruct()
{
var expectedKeyData = new byte[32]
{
0xC1, 0xB1, 0x12, 0x77, 0x23, 0xB8, 0x99, 0xB8,
0xB9, 0x3B, 0x1B, 0xFF, 0x6C, 0xBE, 0xA1, 0x5B,
0x8B, 0x99, 0xAC, 0xBD, 0x99, 0x51, 0x85, 0x95,
0x31, 0xAA, 0x14, 0x3D, 0x95, 0xBF, 0x63, 0xFF
};
var fullPath = Path.Combine(ApplicationData.Current.TemporaryFolder.Path, TestCreateFile);
var file = ApplicationData.Current.TemporaryFolder.CreateFileAsync(TestCreateFile).GetAwaiter().GetResult();
using (var fs = file.OpenStreamForWriteAsync().GetAwaiter().GetResult())
{
using (var sw = new StreamWriter(fs))
{
sw.Write(ExpectedFileStart);
sw.Write(TestKey);
sw.Write(ExpectedFileEnd);
}
}
try
{
var keyFile = new KcpKeyFile(fullPath);
var keyData = keyFile.KeyData.ReadData();
Assert.IsTrue(MemUtil.ArraysEqual(keyData, expectedKeyData));
}
finally
{
file.DeleteAsync().GetAwaiter().GetResult();
}
}
}
try {
var keyFile = new KcpKeyFile (fullPath);
var keyData = keyFile.KeyData.ReadData ();
Assert.That (keyData, Is.EqualTo (expectedKeyData));
} finally {
File.Delete (fullPath);
}
}
[TestMethod]
public void TestCreate()
{
var fullPath = Path.Combine(ApplicationData.Current.TemporaryFolder.Path, TestCreateFile);
var file = ApplicationData.Current.TemporaryFolder.CreateFileAsync(TestCreateFile).GetAwaiter().GetResult();
KcpKeyFile.Create(fullPath, null);
try
{
var fileContents = FileIO.ReadTextAsync(file).GetAwaiter().GetResult();
[Test ()]
public void TestCreate ()
{
var fullPath = Path.Combine(Path.GetTempPath(), testCreateFile);
File.Create(fullPath).Close();
KcpKeyFile.Create (fullPath, null);
try {
var fileContents = File.ReadAllText (fullPath);
Assert.That (fileContents.Length, Is.EqualTo (187));
Assert.That (fileContents, Does.StartWith (expectedFileStart));
Assert.That (fileContents, Does.EndWith (expectedFileEnd));
} finally {
File.Delete (fullPath);
}
Assert.AreEqual(fileContents.Length, 187);
Assert.IsTrue(fileContents.StartsWith(ExpectedFileStart));
Assert.IsTrue(fileContents.EndsWith(ExpectedFileEnd));
}
finally
{
file.DeleteAsync().GetAwaiter().GetResult();
}
}
}
}
}