|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Diagnostics; |
| 4 | +using System.Linq; |
| 5 | +using System.Text; |
| 6 | +using System.Threading.Tasks; |
| 7 | + |
| 8 | +using Xunit; |
| 9 | +using KeePassLib; |
| 10 | +using KeePassLib.Keys; |
| 11 | +using KeePassLib.Serialization; |
| 12 | +using KeePassLib.Utility; |
| 13 | +using PassXYZLib; |
| 14 | + |
| 15 | +namespace KPCLib.xunit |
| 16 | +{ |
| 17 | + public class PasswordDBFixture : IDisposable |
| 18 | + { |
| 19 | + const string TEST_DB = "pass_d_E8f4pEk.xyz"; |
| 20 | + const string TEST_DB_KEY = "12345"; |
| 21 | + |
| 22 | + public PasswordDBFixture() |
| 23 | + { |
| 24 | + PxDb = PasswordDb.Instance; |
| 25 | + PxDb.Open(TEST_DB, TEST_DB_KEY); |
| 26 | + } |
| 27 | + |
| 28 | + public void Dispose() |
| 29 | + { |
| 30 | + PxDb.Close(); |
| 31 | + } |
| 32 | + |
| 33 | + public PasswordDb PxDb { get; private set; } |
| 34 | + public KPCLibLogger Logger { get; private set; } |
| 35 | + } |
| 36 | + |
| 37 | + [CollectionDefinition("PasswordDB collection")] |
| 38 | + public class PasswordDBCollection : ICollectionFixture<PasswordDBFixture> |
| 39 | + { |
| 40 | + // This class has no code, and is never created. Its purpose is simply |
| 41 | + // to be the place to apply [CollectionDefinition] and all the |
| 42 | + // ICollectionFixture<> interfaces. |
| 43 | + } |
| 44 | + |
| 45 | + [Collection("PasswordDB collection")] |
| 46 | + public class PasswordDBTests |
| 47 | + { |
| 48 | + PasswordDBFixture passxyz; |
| 49 | + |
| 50 | + public PasswordDBTests(PasswordDBFixture passXYZFixture) |
| 51 | + { |
| 52 | + this.passxyz = passXYZFixture; |
| 53 | + } |
| 54 | + |
| 55 | + [Fact] |
| 56 | + public void IsOpenDbTest() |
| 57 | + { |
| 58 | + Debug.WriteLine($"{passxyz.PxDb}"); |
| 59 | + Assert.True((passxyz.PxDb.IsOpen)); |
| 60 | + } |
| 61 | + |
| 62 | + [Fact] |
| 63 | + public void ListItemsTests() |
| 64 | + { |
| 65 | + PwGroup pg = passxyz.PxDb.RootGroup; |
| 66 | + |
| 67 | + List<Item> itemList = pg.GetItems(); |
| 68 | + foreach (var item in itemList) |
| 69 | + { |
| 70 | + Debug.WriteLine($"\t{item.Name} : {item.ImgSource}"); |
| 71 | + } |
| 72 | + Assert.NotNull(itemList); |
| 73 | + } |
| 74 | + |
| 75 | + [Theory] |
| 76 | + [InlineData("http://github.com")] |
| 77 | + [InlineData("http://www.baidu.com")] |
| 78 | + [InlineData("http://www.youdao.com")] |
| 79 | + [InlineData("http://www.qq.com")] |
| 80 | + [InlineData("http://www.hp.com")] |
| 81 | + [InlineData("http://www.163.com")] |
| 82 | + [InlineData("http://www.bing.com")] |
| 83 | + public void CustomIconTests(string url) |
| 84 | + { |
| 85 | + var entry = new PwEntry(); |
| 86 | + entry.AddNewIcon(url); |
| 87 | + PwCustomIcon icon = passxyz.PxDb.GetPwCustomIcon(entry.CustomIconUuid); |
| 88 | + entry.Name = icon.Name; |
| 89 | + Debug.WriteLine($"{icon.Name} is stored at {passxyz.PxDb.CurrentPath}"); |
| 90 | + passxyz.PxDb.CurrentGroup.AddEntry(entry, true); |
| 91 | + passxyz.PxDb.Save(null); |
| 92 | + Assert.False(entry.CustomIconUuid.Equals(PwUuid.Zero)); |
| 93 | + } |
| 94 | + |
| 95 | + } |
| 96 | +} |
0 commit comments