M7 adds the double-entry ledger so that the documents of M5 and M6 reach the accounts without retyping, and the Italian VAT obligations can be prepared from the same data. - Chart of accounts on three levels with the Italian "PMI standard" model in the fiscal pack, journal templates with proposed lines, VAT registers; the chart import now writes the accounts and exports them (#62, ADR 0036). - Journal entries: draft, posted, final with the libro giornale number, reversal; recurring entries with the nightly ledger.recurring job (#63). - Documents post their entry inside the document transaction (PostingEngine, LedgerPoster) with VAT lines, open items and withholdings; a change rewrites the same entry, a cancellation removes or reverses it (#64, ADR 0037). - VAT registers with final print, monthly or quarterly settlement with pro rata, interest, minimum and advance, confirmation with the LIQ entry, period lock and F24 line, LIPE file and F24 data (#65). - Operated and suffered withholdings, CU data, stamp duty by quarter with the 5,000 euro threshold, F24 summary with its payment entry (#66). - Party ledgers, account ledgers, trial balance and libro giornale (#67). - Demo accounting with the settlements of the past months confirmed and checked by hand in a test; wiki Contabilita, IVA, Fiscalita italiana completed with screenshots; CHANGELOG 0.7.0, STATUS, ADR 0036-0037 (#68). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
101 lines
5.1 KiB
C#
101 lines
5.1 KiB
C#
using Khaemhat.Core.Instance;
|
|
using Khaemhat.Data.Mapping;
|
|
using Khaemhat.Data.Schema;
|
|
using Khaemhat.Data.SystemDatabase;
|
|
using Khaemhat.Data.Tests.Support;
|
|
|
|
namespace Khaemhat.Data.Tests;
|
|
|
|
[TestClass]
|
|
public sealed class MappingTests
|
|
{
|
|
[TestMethod]
|
|
[DataRow("RowVersion", "row_version")]
|
|
[DataRow("IsDemo", "is_demo")]
|
|
[DataRow("VatID", "vat_id")]
|
|
[DataRow("HTTPCode", "http_code")]
|
|
[DataRow("Address2", "address2")]
|
|
[DataRow("Id", "id")]
|
|
public void SnakeCase(string name, string expected) => Assert.AreEqual(expected, SqlNames.ToSnakeCase(name));
|
|
|
|
[TestMethod]
|
|
public void Conventions_KeyTypesNullabilityAndAudit()
|
|
{
|
|
var map = new TestItemMap();
|
|
map.Freeze();
|
|
|
|
Assert.AreEqual("id", map.Key.ColumnName);
|
|
Assert.IsTrue(map.Key.IsIdentity);
|
|
Assert.AreEqual("id", map.Columns[0].ColumnName);
|
|
Assert.AreEqual("row_version", map.Columns[^1].ColumnName);
|
|
Assert.AreSame(map.Columns[^1], map.RowVersion);
|
|
|
|
Assert.AreEqual("String(20)", map.Column(x => x.Code).TypeDescription);
|
|
Assert.IsFalse(map.Column(x => x.Code).IsNullable);
|
|
Assert.IsTrue(map.Column(x => x.Name).IsNullable);
|
|
Assert.AreEqual(ColumnType.Decimal, map.Column(x => x.Amount).Type);
|
|
Assert.AreEqual(ColumnType.Date, map.Column(x => x.Day).Type);
|
|
Assert.IsTrue(map.Column(x => x.Day).IsNullable);
|
|
Assert.AreEqual(ColumnType.Json, map.Column(x => x.Payload).Type);
|
|
Assert.AreEqual("String(40)", map.Column(x => x.Kind).TypeDescription);
|
|
Assert.AreEqual(ColumnType.Bool, map.Column(x => x.IsDemo).Type);
|
|
Assert.AreEqual(AuditRole.CreatedBy, map.Column(x => x.CreatedBy).Audit);
|
|
Assert.AreEqual("String(100)", map.Column(x => x.CreatedBy).TypeDescription);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void Enums_AreStoredByName()
|
|
{
|
|
var map = new CompanyMap();
|
|
map.Freeze();
|
|
var status = map.Column(x => x.Status);
|
|
|
|
Assert.AreEqual("Maintenance", status.ToProvider(CompanyStatus.Maintenance));
|
|
Assert.AreEqual(CompanyStatus.ReadOnly, status.FromProvider("ReadOnly"));
|
|
}
|
|
|
|
[TestMethod]
|
|
public void Registry_RejectsTwoMapsForOneEntity()
|
|
{
|
|
var registry = new MapRegistry().Add(new CompanyMap());
|
|
|
|
Assert.ThrowsExactly<InvalidOperationException>(() => registry.Add(new CompanyMap()));
|
|
}
|
|
|
|
[TestMethod]
|
|
public void Registry_FindsTheMapsOfBothDatabases()
|
|
{
|
|
var registry = new MapRegistry().AddFromAssembly(typeof(CompanyMap).Assembly);
|
|
|
|
string[] expected =
|
|
[
|
|
"sys_companies", "sys_data_protection_keys", "sys_job_locks", "sys_job_runs", "sys_license_activations", "sys_licenses", "sys_log",
|
|
"sys_notification_reads", "sys_notifications", "sys_roles_templates", "sys_scheduled_tasks", "sys_security_audit", "sys_sessions", "sys_settings", "sys_user_settings", "sys_users",
|
|
"attachments", "audit_log", "company_settings", "notification_reads", "notifications", "role_permissions", "roles", "user_permission_overrides", "user_roles", "user_sessions", "user_settings", "users",
|
|
"company_profile", "fiscal_years", "fiscal_periods", "countries", "provinces", "municipalities", "currencies", "exchange_rates", "units_of_measure",
|
|
"tax_codes", "payment_methods", "payment_terms", "payment_term_lines", "bank_accounts", "salespeople", "carriers", "shipping_terms", "transport_means",
|
|
"goods_appearances", "delivery_terms", "transport_reasons", "inventory_reasons", "warehouses", "item_categories", "party_categories", "price_lists",
|
|
"discount_policies", "document_numerators", "document_types", "cost_centers", "jobs", "code_sequences",
|
|
"parties", "party_addresses", "party_contacts", "party_bank_accounts", "party_sales_terms", "party_purchase_terms", "party_fiscal",
|
|
"items", "item_uoms", "item_barcodes", "item_prices", "item_suppliers", "item_substitutes", "party_item_codes",
|
|
"sale_quotations", "sale_quotation_lines", "sale_orders", "sale_order_lines", "sale_documents", "sale_document_lines",
|
|
"purchase_orders", "purchase_order_lines", "purchase_documents", "purchase_document_lines", "inventory_documents", "inventory_document_lines",
|
|
"document_links", "document_tax_summaries", "document_installments",
|
|
"inventory_entries", "inventory_entry_lines", "item_balances", "stock_takes", "stock_take_lines",
|
|
"gl_accounts", "vat_registers", "gl_journal_templates", "gl_journal_template_lines", "gl_entries", "gl_entry_lines", "gl_entry_vat",
|
|
"gl_open_items", "gl_recurring_entries", "vat_settlements", "vat_settlement_lines", "tax_payments", "withholdings", "vat_register_prints",
|
|
];
|
|
CollectionAssert.AreEquivalent(expected, registry.Maps.Select(m => m.Table).ToArray());
|
|
}
|
|
|
|
[TestMethod]
|
|
public void StringWithoutLength_IsText_AndFrozenMapsCannotChange()
|
|
{
|
|
var map = new SystemSettingMap();
|
|
map.Freeze();
|
|
|
|
Assert.AreEqual(ColumnType.Text, map.Column(x => x.Value).Type);
|
|
Assert.ThrowsExactly<InvalidOperationException>(() => map.Column(x => x.Key).MaxLength(10));
|
|
}
|
|
}
|