public void AdjustAccounting(Household house, string key, int delta) { if (delta == 0) { return; } AccountingData data = GetValue <AcountingOption, AccountingData>(house); if (data == null) { data = new AccountingData(); } if (Common.kDebugging) { if (GetValue <AccountingKeyOption, bool>()) { Common.DebugStackLog("Household: " + house.Name + Common.NewLine + "Key: " + key + Common.NewLine + "Delta: " + delta + Common.NewLine); } } data.Add(key, delta); SetValue <AcountingOption, AccountingData>(house, data); }
public void Migrate_Empty_Unchanged() { var sut = new AccountingData(); sut.Migrate().Should().BeFalse("no (relevant) changes made"); sut.Should().BeEquivalentTo(new AccountingData()); }
public void AddAccountingData(DateTime date, AccountingData ad, bool selectNewDate = true) { _DataHistory.AddData(date, ad); if (selectNewDate) { _CurrentDate = date; } UpdateComboBoxDates(); }
public void Migrate_EmptyYears_YearsNodeRemoved() { var sut = new AccountingData { Years = new List <AccountingDataYear>() }; sut.Migrate().Should().BeFalse("just removing the empty not is not a relevant change"); sut.Should().BeEquivalentTo(new AccountingData()); sut.Years.Should().BeNull(); }
public void AccountingData() { List <Category> list = new List <Category> { Init.CreateCategory1(), Init.CreateCategory2() }; AccountingData ad = new AccountingData(list, Init.CreateFXMarket(), Init.CreateAssetMarket()); string fileName = SerializeObject(ad, "AccountingData"); AccountingData desAd = DeserializeObject <AccountingData>(fileName); Assert.IsTrue(ad == desAd); }
public void ShowTotal() { labelTable.Text = "Total"; DateTime?dt = GetPreviousDate(); Dictionary <string, double?> lastTotal = new Dictionary <string, double?> { }; if (dt.HasValue) { AccountingData lastData = _DataHistory.GetData(dt.Value); lastTotal[dataGridViewAccounting._LastTotalMemoryMainKey] = lastData.GetQuote(lastData.Ccy, _DataHistory.TotalCcy) * lastData.TotalValue; foreach (var cat in lastData.Categories) { lastTotal[cat.CategoryName] = cat.GetTotalAmount(_DataHistory.TotalCcy, lastData.FXMarket); } } dataGridViewAccounting.ShowTotal(Data, lastTotal); }
public async Task OnActivate_RecentProject_ProjectLoadedAndModifiedProjectAutoSaved() { var sut = CreateSut(out IFileSystem fileSystem); sut.ProjectData.AutoSaveInterval = 100.Milliseconds(); sut.ProjectData.Settings.RecentProject = "recent.project"; var sample = new AccountingData { Accounts = new List <AccountingDataAccountGroup> { new AccountingDataAccountGroup { Account = new List <AccountDefinition> { new AccountDefinition { ID = 1, Name = "TheAccount" } } } } }; fileSystem.FileExists("recent.project").Returns(true); fileSystem.ReadAllTextFromFile("recent.project").Returns(sample.Serialize()); var fileSaved = new TaskCompletionSource <bool>(); fileSystem .When(x => x.WriteAllTextIntoFile(Arg.Any <string>(), Arg.Any <string>())) .Do(x => fileSaved.SetResult(true)); ((IActivate)sut).Activate(); await sut.Awaiting(x => x.LoadingTask).Should().CompleteWithinAsync(1.Seconds()); sut.ProjectData.IsModified = true; await fileSaved.Awaiting(x => x.Task).Should().CompleteWithinAsync( 1.Seconds(), "file should be saved by auto-save task"); using var _ = new AssertionScope(); sut.ProjectData.IsModified.Should() .BeTrue("the project is ONLY auto-saved and not saved to real project file"); sut.Accounts.AccountList.Should().BeEquivalentTo(new[] { new { Name = "TheAccount" } }); fileSystem.DidNotReceive().WriteAllTextIntoFile("recent.project", Arg.Any <string>()); fileSystem.Received(1).WriteAllTextIntoFile("recent.project~", Arg.Any <string>()); }
public void HistoricalAccountingData() { HistoricalAccountingData had = new HistoricalAccountingData(); had.SetCcyDB(GetCcyDB()); // Create AccData 1 FXMarket fx1 = Init.CreateFXMarket(); fx1.CcyRef = had.CcyDB.RefCcy; fx1.AddQuote(new CurrencyPair("GBP", "EUR"), 1.1); fx1.AddQuote(new CurrencyPair("GBP", "JPY"), 130); AssetMarket amkt1 = Init.CreateAssetMarket(); amkt1.AddQuote(new AssetCcyPair(new Asset("AAPL"), new Currency("USD")), 1234.56); amkt1.PopulateWithFXMarket(fx1); List <Category> list = new List <Category> { Init.CreateCategory1(), Init.CreateCategory2() }; AccountingData ad1 = new AccountingData(list, fx1, amkt1); had.AddData(new DateTime(2020, 1, 1), ad1); // Create AccData2 FXMarket fx2 = new FXMarket(); fx2.Copy(fx1); fx2.AddQuote(new CurrencyPair("EUR", "USD"), 1.2); fx2.AddQuote(new CurrencyPair("GBP", "EUR"), 1.15); AssetMarket amkt2 = new AssetMarket(); amkt2.Copy(amkt1); amkt2.AddQuote(new AssetCcyPair(new Asset("BNP"), new Currency("EUR")), 50.0); amkt2.PopulateWithFXMarket(fx2); AccountingData ad2 = new AccountingData(list, fx2, amkt2); had.AddData(new DateTime(2020, 2, 3), ad2); // Test string fileName = SerializeObject(had, "HistoricalAccountingData"); HistoricalAccountingData desHad = DeserializeObject <HistoricalAccountingData>(fileName); Assert.IsTrue(had == desHad); }
public void ShowElement(NodeAddress na) { labelTable.Text = na.GetLabelText(); DateTime? dt = GetPreviousDate(); IAccountingElement element = Data.GetElement(na); Dictionary <string, double?> lastTotal = new Dictionary <string, double?> { }; if (dt.HasValue) { AccountingData lastData = _DataHistory.GetData(dt.Value); lastTotal[dataGridViewAccounting._LastTotalMemoryMainKey] = lastData.GetQuote(lastData.Ccy, _DataHistory.TotalCcy) * lastData.GetValue(na); foreach (var subitem in lastData.GetElement(na).GetItemList()) { lastTotal[subitem.GetName()] = subitem.GetTotalAmount(_DataHistory.TotalCcy, lastData.FXMarket); } } dataGridViewAccounting.ShowElement(Data.GetElement(na), Data.Map.GetElement(na), lastTotal);; _AddressofElementShowed = na; }
public async Task OnActivate_RecentProject_ProjectLoadedAndUnmodifiedProjectNotAutoSaved() { var sut = CreateSut(out IFileSystem fileSystem); sut.ProjectData.AutoSaveInterval = 10.Milliseconds(); sut.ProjectData.Settings.RecentProject = "recent.project"; var sample = new AccountingData { Accounts = new List <AccountingDataAccountGroup> { new AccountingDataAccountGroup { Account = new List <AccountDefinition> { new AccountDefinition { ID = 1, Name = "TheAccount" } } } } }; fileSystem.FileExists("recent.project").Returns(true); fileSystem.ReadAllTextFromFile("recent.project").Returns(sample.Serialize()); var fileSaved = new TaskCompletionSource <bool>(); fileSystem .When(x => x.WriteAllTextIntoFile(Arg.Any <string>(), Arg.Any <string>())) .Do(x => fileSaved.SetResult(true)); ((IActivate)sut).Activate(); await sut.Awaiting(x => x.LoadingTask).Should().CompleteWithinAsync(1.Seconds()); sut.ProjectData.IsModified = false; var delayTask = Task.Delay(200.Milliseconds()); var completedTask = await Task.WhenAny(fileSaved.Task, delayTask); completedTask.Should().Be(delayTask, "file should not be saved"); fileSystem.DidNotReceive().WriteAllTextIntoFile("recent.project~", Arg.Any <string>()); }
private bool LoadFile(string projectFileName, out bool autoSaveFileLoaded) { var result = MessageBoxResult.No; var autoSaveFileName = Defines.GetAutoSaveFileName(projectFileName); if (this.fileSystem.FileExists(autoSaveFileName)) { result = this.dialogs.ShowMessageBox( string.Format( CultureInfo.CurrentUICulture, Resources.Question_LoadAutoSaveProjectFileX, projectFileName), Resources.Header_LoadProject, MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.No) { this.fileSystem.FileDelete(autoSaveFileName); } } autoSaveFileLoaded = result == MessageBoxResult.Yes; string fileName = autoSaveFileLoaded ? autoSaveFileName : projectFileName; if (!this.fileSystem.FileExists(fileName)) { return(false); } var projectXml = this.fileSystem.ReadAllTextFromFile(fileName); this.ProjectData = AccountingData.Deserialize(projectXml); return(true); }
public void Update(AccountingData ad) { _Weights = new Dictionary <string, double> { }; SummaryReport sr = ad.GetSummary(); Rows.Clear(); ColumnCount = 4; Columns[0].HeaderText = "Ccy/Asset"; Columns[1].HeaderText = "Total"; Columns[2].HeaderText = "Total Converted"; Columns[3].HeaderText = "Weight"; for (int j = 0; j < ColumnCount; j++) { Columns[j].Width = 75; Columns[j].SortMode = DataGridViewColumnSortMode.Programmatic; } foreach (var item in ad.CciesAndAssets) { double amount = sr.Get(item); if (amount != 0) { double convAmount = ad.GetQuote(item, ad.Ccy) * amount; double weight = convAmount / ad.TotalValue; _Weights[item.ToString()] = weight; object[] values = { item.ToString(), ad.GetAmountToString(item, amount), ad.GetAmountToString(ad.Ccy,convAmount), $"{Math.Round(weight * 100, 2)} %" }; Rows.Add(values); } } ClearSelection(); }
public void Migrate_DataWithEmptyProperties_EmptyPropertiesRemoved() { var sut = new AccountingData { Accounts = new List <AccountingDataAccountGroup> { new AccountingDataAccountGroup { Account = new List <AccountDefinition> { new AccountDefinition { Name = "1" }, new AccountDefinition { Name = "2", ImportMapping = new AccountDefinitionImportMapping() }, new AccountDefinition { Name = "3", ImportMapping = new AccountDefinitionImportMapping { Columns = new List <AccountDefinitionImportMappingColumn>(), Patterns = new List <AccountDefinitionImportMappingPattern>() } }, new AccountDefinition { Name = "4", ImportMapping = new AccountDefinitionImportMapping { Columns = new List <AccountDefinitionImportMappingColumn> { new AccountDefinitionImportMappingColumn { Source = "A" } }, Patterns = new List <AccountDefinitionImportMappingPattern> { new AccountDefinitionImportMappingPattern { Expression = "A" } } } } } } } }; sut.Migrate().Should().BeTrue(); var expectation = new AccountingData { Accounts = new List <AccountingDataAccountGroup> { new AccountingDataAccountGroup { Account = new List <AccountDefinition> { new AccountDefinition { Name = "1" }, new AccountDefinition { Name = "2" }, new AccountDefinition { Name = "3" }, new AccountDefinition { Name = "4", ImportMapping = new AccountDefinitionImportMapping { Columns = new List <AccountDefinitionImportMappingColumn> { new AccountDefinitionImportMappingColumn { Source = "A" } }, Patterns = new List <AccountDefinitionImportMappingPattern> { new AccountDefinitionImportMappingPattern { Expression = "A" } } } } } } } }; sut.Should().BeEquivalentTo( expectation, o => o.Excluding( info => info.Path.EndsWith( nameof(AccountDefinitionImportMappingPattern.Regex), StringComparison.Ordinal))); }
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()); }