@@ -7,6 +7,7 @@ namespace lg2de.SimpleAccounting.UnitTests.Presentation;
77using System ;
88using System . Globalization ;
99using System . Linq ;
10+ using System . Text ;
1011using System . Threading . Tasks ;
1112using System . Windows . Forms ;
1213using lg2de . SimpleAccounting . Abstractions ;
@@ -32,6 +33,32 @@ public void Ctor_SampleData_AccountsFiltered()
3233 sut . ImportAccounts . Should ( ) . BeEquivalentTo ( [ new { Name = "Bank account" } ] ) ;
3334 }
3435
36+ [ Fact ]
37+ public void Ctor_InactiveAccountWithMapping_Excluded ( )
38+ {
39+ var clock = Substitute . For < IClock > ( ) ;
40+ var projectData = new ProjectData ( new Settings ( ) , null ! , null ! , null ! , clock , null ! ) ;
41+ var activeAccount = new AccountDefinition
42+ {
43+ ID = 101 , Name = "Bank (Active)" , Active = true , ImportMapping = Samples . SimpleImportConfiguration
44+ } ;
45+ var inactiveAccount = new AccountDefinition
46+ {
47+ ID = 102 ,
48+ Name = "Old Bank (Inactive)" ,
49+ Active = false ,
50+ ImportMapping = Samples . SimpleImportConfiguration
51+ } ;
52+ projectData . Storage . Accounts =
53+ [
54+ new AccountingDataAccountGroup { Account = [ activeAccount , inactiveAccount ] }
55+ ] ;
56+
57+ var sut = new ImportBookingsViewModel ( null ! , null ! , projectData ) ;
58+
59+ sut . ImportAccounts . Should ( ) . BeEquivalentTo ( [ new { Name = "Bank (Active)" } ] ) ;
60+ }
61+
3562 [ Fact ]
3663 public void ImportStatus_NoImportAccount ( )
3764 {
@@ -194,6 +221,49 @@ public void LoadDataCommand_LastImportFolder_LastUsedAndNewStored()
194221 dialogs . Received ( 1 ) . ShowOpenFileDialog ( Arg . Any < string > ( ) , Arg . Is < string > ( x => x == "E:\\ MySelectedFolder" ) ) ;
195222 }
196223
224+ [ CulturedFact ( [ "de" ] ) ]
225+ public void LoadDataCommand_RemoteAccountList_ContainsOnlyActiveAccounts ( )
226+ {
227+ var clock = Substitute . For < IClock > ( ) ;
228+ var projectData = new ProjectData ( new Settings ( ) , null ! , null ! , null ! , clock , null ! ) ;
229+ var bankAccount = new AccountDefinition
230+ {
231+ ID = 100 , Name = "My Bank" , Active = true , ImportMapping = Samples . SimpleImportConfiguration
232+ } ;
233+ var activeRemote = new AccountDefinition
234+ {
235+ ID = 601 , Name = "New Shoes (Active)" , Active = true , ImportMapping = Samples . SimpleImportConfiguration
236+ } ;
237+ var inactiveRemote = new AccountDefinition
238+ {
239+ ID = 600 ,
240+ Name = "Old Shoes (Inactive)" ,
241+ Active = false ,
242+ ImportMapping = Samples . SimpleImportConfiguration
243+ } ;
244+ projectData . Storage . Accounts =
245+ [
246+ new AccountingDataAccountGroup { Account = [ bankAccount , activeRemote , inactiveRemote ] }
247+ ] ;
248+ var dialogs = Substitute . For < IDialogs > ( ) ;
249+ dialogs . ShowOpenFileDialog ( Arg . Any < string > ( ) , Arg . Any < string > ( ) )
250+ . Returns ( ( DialogResult . OK , "test.csv" ) ) ;
251+ var fileSystem = Substitute . For < IFileSystem > ( ) ;
252+ var sut = new ImportBookingsViewModel ( dialogs , fileSystem , projectData )
253+ {
254+ SelectedAccount = bankAccount , SelectedAccountNumber = bankAccount . ID
255+ } ;
256+ var validDate = sut . RangeMin . AddDays ( 5 ) . ToString ( "dd.MM.yyyy" , CultureInfo . CurrentUICulture ) ;
257+ var csvContent = $ "Datum;Text;Betrag\n { validDate } ;Test Booking;-100,00";
258+ fileSystem . ReadAllBytesFromFile ( Arg . Any < string > ( ) )
259+ . Returns ( Encoding . UTF8 . GetBytes ( csvContent ) ) ;
260+
261+ sut . LoadDataCommand . Execute ( null ) ;
262+
263+ sut . LoadedData . Should ( ) . ContainSingle ( )
264+ . Which . Accounts . Should ( ) . BeEquivalentTo ( [ new { ID = 601 , Name = "New Shoes (Active)" } ] ) ;
265+ }
266+
197267 [ Fact ]
198268 public void SetRemoteAccountsCommand_EntryNotMapped_CanExecute ( )
199269 {
@@ -264,8 +334,7 @@ public void SetRemoteAccountsCommand_EntryNotMapped_AccountsSelected()
264334 . BeEquivalentTo (
265335 new object [ ]
266336 {
267- new { RemoteAccount = new { Name = "Bank account" } } ,
268- new { RemoteAccount = ( object ) null } ,
337+ new { RemoteAccount = new { Name = "Bank account" } } , new { RemoteAccount = ( object ) null } ,
269338 new { RemoteAccount = new { Name = "Shoes" } } ,
270339 new { RemoteAccount = new { Name = "Friends debit" } }
271340 } ) ;
0 commit comments