mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 15:40:18 -04:00
Added some tests
Removed false first group, replaced it a button in the header Code refactor
This commit is contained in:
57
ModernKeePassApp.Test/Data/WindowsStoreProxy.xml
Normal file
57
ModernKeePassApp.Test/Data/WindowsStoreProxy.xml
Normal file
@@ -0,0 +1,57 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<CurrentApp>
|
||||
<ListingInformation>
|
||||
<App>
|
||||
<AppId>0719A91A-C322-4EE0-A257-E60733EECF06</AppId>
|
||||
<LinkUri>https://www.microsoft.com/store/apps/9mwq48zk8nhv</LinkUri>
|
||||
<CurrentMarket>en-us</CurrentMarket>
|
||||
<AgeRating>3</AgeRating>
|
||||
<MarketData xml:lang="en-us">
|
||||
<Name>App with several in-app products</Name>
|
||||
<Description>Sample app for demonstrating an expiring in-app product and a consumable in-app product</Description>
|
||||
<Price>5.99</Price>
|
||||
<CurrencySymbol>$</CurrencySymbol>
|
||||
</MarketData>
|
||||
</App>
|
||||
<Product ProductId="donate1" LicenseDuration="0" ProductType="Consumable">
|
||||
<MarketData xml:lang="en-us">
|
||||
<Name>Small Donation</Name>
|
||||
<Price>0.99</Price>
|
||||
<CurrencySymbol>$</CurrencySymbol>
|
||||
</MarketData>
|
||||
</Product>
|
||||
<Product ProductId="donate5" LicenseDuration="0" ProductType="Consumable">
|
||||
<MarketData xml:lang="en-us">
|
||||
<Name>Medium Donation</Name>
|
||||
<Price>4.99</Price>
|
||||
<CurrencySymbol>$</CurrencySymbol>
|
||||
</MarketData>
|
||||
</Product>
|
||||
<Product ProductId="donate10" LicenseDuration="0" ProductType="Consumable">
|
||||
<MarketData xml:lang="en-us">
|
||||
<Name>Large Donation</Name>
|
||||
<Price>9.99</Price>
|
||||
<CurrencySymbol>$</CurrencySymbol>
|
||||
</MarketData>
|
||||
</Product>
|
||||
<Product ProductId="donate20" LicenseDuration="0" ProductType="Consumable">
|
||||
<MarketData xml:lang="en-us">
|
||||
<Name>Generous Donation</Name>
|
||||
<Price>19.99</Price>
|
||||
<CurrencySymbol>$</CurrencySymbol>
|
||||
</MarketData>
|
||||
</Product>
|
||||
</ListingInformation>
|
||||
<LicenseInformation>
|
||||
<App>
|
||||
<IsActive>true</IsActive>
|
||||
<IsTrial>false</IsTrial>
|
||||
</App>
|
||||
</LicenseInformation>
|
||||
<ConsumableInformation>
|
||||
<Product ProductId="donate1" TransactionId="00000001-0000-0000-0000-000000000000" Status="Active"/>
|
||||
<Product ProductId="donate5" TransactionId="00000001-0000-0000-0000-000000000000" Status="Active"/>
|
||||
<Product ProductId="donate10" TransactionId="00000001-0000-0000-0000-000000000000" Status="Active"/>
|
||||
<Product ProductId="donate20" TransactionId="00000001-0000-0000-0000-000000000000" Status="Active"/>
|
||||
</ConsumableInformation>
|
||||
</CurrentApp>
|
@@ -28,7 +28,7 @@ namespace ModernKeePassApp.Test
|
||||
public void TestOpen()
|
||||
{
|
||||
Assert.AreEqual((int)DatabaseService.DatabaseStatus.Closed, _database.Status);
|
||||
_database.DatabaseFile = Package.Current.InstalledLocation.GetFileAsync(@"Databases\TestDatabase.kdbx").GetAwaiter().GetResult();
|
||||
_database.DatabaseFile = Package.Current.InstalledLocation.GetFileAsync(@"Data\TestDatabase.kdbx").GetAwaiter().GetResult();
|
||||
Assert.AreEqual((int)DatabaseService.DatabaseStatus.Opening, _database.Status);
|
||||
OpenOrCreateDatabase(false);
|
||||
}
|
||||
|
@@ -50,7 +50,7 @@ namespace ModernKeePassApp.Test.Mock
|
||||
|
||||
public void Save()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
// Do Nothing
|
||||
}
|
||||
|
||||
public void Save(StorageFile file)
|
||||
|
31
ModernKeePassApp.Test/Mock/LicenseServiceMock.cs
Normal file
31
ModernKeePassApp.Test/Mock/LicenseServiceMock.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.ApplicationModel;
|
||||
using Windows.ApplicationModel.Store;
|
||||
using ModernKeePass.Interfaces;
|
||||
|
||||
namespace ModernKeePassApp.Test.Mock
|
||||
{
|
||||
public class LicenseServiceMock: ILicenseService
|
||||
{
|
||||
public IReadOnlyDictionary<string, ProductListing> Products { get; }
|
||||
|
||||
public LicenseServiceMock()
|
||||
{
|
||||
try
|
||||
{
|
||||
var proxyFile = Package.Current.InstalledLocation.GetFileAsync("data\\WindowsStoreProxy.xml").GetAwaiter().GetResult();
|
||||
CurrentAppSimulator.ReloadSimulatorAsync(proxyFile).GetAwaiter().GetResult();
|
||||
}
|
||||
catch { }
|
||||
var listing = CurrentAppSimulator.LoadListingInformationAsync().GetAwaiter().GetResult();
|
||||
Products = listing.ProductListings;
|
||||
}
|
||||
|
||||
public Task<int> Purchase(string addOn)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
@@ -121,6 +121,7 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="DatabaseTests.cs" />
|
||||
<Compile Include="Mock\DatabaseServiceMock.cs" />
|
||||
<Compile Include="Mock\LicenseServiceMock.cs" />
|
||||
<Compile Include="Mock\RecentServiceMock.cs" />
|
||||
<Compile Include="Mock\ResourceServiceMock.cs" />
|
||||
<Compile Include="Mock\SettingsServiceMock.cs" />
|
||||
@@ -131,11 +132,14 @@
|
||||
<AppxManifest Include="Package.appxmanifest">
|
||||
<SubType>Designer</SubType>
|
||||
</AppxManifest>
|
||||
<Content Include="Databases\TestDatabase.kdbx" />
|
||||
<Content Include="Data\TestDatabase.kdbx" />
|
||||
<None Include="ModernKeePassApp.Test_TemporaryKey.pfx" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Data\WindowsStoreProxy.xml">
|
||||
<SubType>Designer</SubType>
|
||||
</Content>
|
||||
<Content Include="Images\UnitTestLogo.scale-100.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
|
@@ -6,6 +6,7 @@ using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
||||
using ModernKeePass.ViewModels;
|
||||
using ModernKeePass.Views;
|
||||
using ModernKeePassApp.Test.Mock;
|
||||
using ModernKeePassLib;
|
||||
|
||||
namespace ModernKeePassApp.Test
|
||||
{
|
||||
@@ -56,13 +57,20 @@ namespace ModernKeePassApp.Test
|
||||
Assert.AreEqual(15.0, compositeKeyVm.PasswordComplexityIndicator);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestDonateVm()
|
||||
{
|
||||
var donateVm = new DonateVm(new LicenseServiceMock());
|
||||
Assert.AreEqual(4, donateVm.Donations.Count);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestOpenVm()
|
||||
{
|
||||
var database = new DatabaseServiceMock
|
||||
{
|
||||
Status = 1,
|
||||
DatabaseFile = Package.Current.InstalledLocation.GetFileAsync(@"Databases\TestDatabase.kdbx")
|
||||
DatabaseFile = Package.Current.InstalledLocation.GetFileAsync(@"Data\TestDatabase.kdbx")
|
||||
.GetAwaiter().GetResult()
|
||||
};
|
||||
var openVm = new OpenVm(database);
|
||||
@@ -79,7 +87,7 @@ namespace ModernKeePassApp.Test
|
||||
public void TestRecentVm()
|
||||
{
|
||||
var mru = StorageApplicationPermissions.MostRecentlyUsedList;
|
||||
mru.Add(Package.Current.InstalledLocation.GetFileAsync(@"Databases\TestDatabase.kdbx")
|
||||
mru.Add(Package.Current.InstalledLocation.GetFileAsync(@"Data\TestDatabase.kdbx")
|
||||
.GetAwaiter().GetResult(), "MockDatabase");
|
||||
var recentVm = new RecentVm();
|
||||
Assert.IsTrue(recentVm.RecentItems.Count == 1);
|
||||
@@ -88,10 +96,19 @@ namespace ModernKeePassApp.Test
|
||||
mru.Clear();
|
||||
}
|
||||
|
||||
/*[TestMethod]
|
||||
[TestMethod]
|
||||
public void TestSaveVm()
|
||||
{
|
||||
}*/
|
||||
var database = new DatabaseServiceMock
|
||||
{
|
||||
Status = 2
|
||||
};
|
||||
var saveVm = new SaveVm(database);
|
||||
saveVm.Save(false);
|
||||
Assert.AreEqual(2, database.Status);
|
||||
saveVm.Save();
|
||||
Assert.AreEqual(0, database.Status);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestSettingsVm()
|
||||
@@ -105,5 +122,33 @@ namespace ModernKeePassApp.Test
|
||||
var selectedItem = (ListMenuItemVm) settingsVm.SelectedItem;
|
||||
Assert.AreEqual(typeof(SettingsNewDatabasePage), selectedItem.PageType);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestEntryVm()
|
||||
{
|
||||
var database = new DatabaseServiceMock
|
||||
{
|
||||
Status = 2
|
||||
};
|
||||
var entryVm = new EntryVm(new PwEntry(true, true), new GroupVm(), database)
|
||||
{
|
||||
Name = "Test",
|
||||
UserName = "login",
|
||||
Password = "password"
|
||||
};
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestGroupVm()
|
||||
{
|
||||
var database = new DatabaseServiceMock
|
||||
{
|
||||
Status = 2
|
||||
};
|
||||
var entryVm = new GroupVm(new PwGroup(true, true), new GroupVm(), database)
|
||||
{
|
||||
Name = "Test"
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user