public void LoadDataCommand_NoAccountSelected_CannotExecute() { var dialogs = Substitute.For <IDialogs>(); var projectData = new ProjectData(new Settings(), null !, dialogs, null !, null !); var sut = new ImportBookingsViewModel(dialogs, projectData); sut.LoadDataCommand.CanExecute(null).Should().BeFalse(); }
public void LoadDataCommand_NoLastImportFolder_DefaultUsedAndSelectedStored() { var dialogs = Substitute.For <IDialogs>(); var projectData = new ProjectData(new Settings(), null !, dialogs, null !, null !); var sut = new ImportBookingsViewModel(dialogs, projectData) { SelectedAccountNumber = 100 }; dialogs .ShowOpenFileDialog(Arg.Any <string>(), Arg.Any <string>()) .Returns((DialogResult.OK, "D:\\MySelectedFolder\\import.csv")); sut.LoadDataCommand.Execute(null); projectData.Storage.Setup.Behavior.LastBookingImportFolder.Should().Be("D:\\MySelectedFolder"); dialogs.Received(1).ShowOpenFileDialog(Arg.Any <string>(), Arg.Is <string>(x => x == null)); }
public void LoadDataCommand_LoadFileCancelled_IsBusyReset() { var dialogs = Substitute.For <IDialogs>(); var projectData = new ProjectData(new Settings(), null !, dialogs, null !, null !); var sut = new ImportBookingsViewModel(dialogs, projectData) { SelectedAccountNumber = 100 }; dialogs .ShowOpenFileDialog(Arg.Any <string>(), Arg.Any <string>()) .Returns((DialogResult.Cancel, string.Empty)); sut.LoadDataCommand.Execute(null); projectData.Storage.Setup.Behavior.LastBookingImportFolder.Should() .BeNullOrEmpty("last folder should remain unchanged"); sut.Busy.IsBusy.Should().BeFalse(); }
public void ImportBookings_SampleInput_DataImportedAndFiltered() { AccountingData project = GetProject(); var dialogs = Substitute.For <IDialogs>(); var accounts = project.AllAccounts.ToList(); var bankAccount = accounts.Single(x => x.Name == "Bank account"); var projectData = new ProjectData(new Settings(), null !, null !, null !, null !); projectData.Load(project); var sut = new ImportBookingsViewModel(dialogs, projectData) { SelectedAccount = bankAccount, SelectedAccountNumber = bankAccount.ID, IsForceEnglish = true }; var fileName = Path.GetTempFileName(); var stream = this.GetType().Assembly.GetManifestResourceStream( "lg2de.SimpleAccounting.IntegrationTests.Ressources.import.csv"); using var reader = new StreamReader(stream !); var script = reader.ReadToEnd(); File.WriteAllText(fileName, script); sut.LoadFromFile(fileName); File.Delete(fileName); dialogs.DidNotReceive().ShowMessageBox( Arg.Any <string>(), Arg.Any <string>(), Arg.Any <MessageBoxButton>(), Arg.Any <MessageBoxImage>(), Arg.Any <MessageBoxResult>(), Arg.Any <MessageBoxOptions>()); sut.LoadedData.Should().NotContain(x => x.Name == "Shopping Mall", "entry is already imported"); sut.LoadedData.Should().BeEquivalentTo( new[] { new { Date = new DateTime(2000, 1, 10), Name = "Name1", Text = "Text1", Value = 12.34 }, new { Date = new DateTime(2000, 12, 1), Name = "Name2", Text = "Text2", Value = 23.45 }, new { Date = new DateTime(2000, 12, 1), Name = "Name3", Text = "Text3", Value = 23.46 }, new { Date = new DateTime(2000, 12, 31), Name = "Name4", Text = "Text4", Value = -42.42 } }, o => o.WithStrictOrdering()); sut.ImportDataFiltered.Should().BeEquivalentTo( new[] { new { Identifier = 2, Date = new DateTime(2000, 12, 1), Name = "Name2", Text = "Text2", Value = 23.45 }, new { Identifier = 3, Date = new DateTime(2000, 12, 1), Name = "Name3", Text = "Text3", Value = 23.46 }, new { Identifier = 4, Date = new DateTime(2000, 12, 31), Name = "Name4", Text = "Text4", Value = -42.42 } }, o => o.WithStrictOrdering()); // set start date to year begin to import data skipped before sut.StartDate = new DateTime(2000, 1, 1); // note that all identifiers will be changed sut.ImportDataFiltered.Should().BeEquivalentTo( new object[] { new { Identifier = 2, Date = new DateTime(2000, 1, 10), Name = "Name1", Text = "Text1", Value = 12.34 }, new { Identifier = 1, Date = new DateTime(2000, 1, 15), Text = "Shopping Mall - Shoes", Value = -50 }, new { Identifier = 3, Date = new DateTime(2000, 12, 1), Name = "Name2", Text = "Text2", Value = 23.45 }, new { Identifier = 4, Date = new DateTime(2000, 12, 1), Name = "Name3", Text = "Text3", Value = 23.46 }, new { Identifier = 5, Date = new DateTime(2000, 12, 31), Name = "Name4", Text = "Text4", Value = -42.42 } }, o => o.WithStrictOrdering()); }