namespace SmartB2B.Optima.Tests; // Atrapa granicy COM sprawdza przebieg rzeczywistej fasady bez instalacji Optimy. public sealed class FakeOrderSession { public FakeOrderDocument Document { get; } = new(); public bool Saved { get; private set; } public FakeOrderCollection CreateObject(string name) => new(name, Document); public void Save() => Saved = true; } public sealed class FakeOrderCollection(string name, FakeOrderDocument document) { public object? Item(string filter) => name switch { "CDN.DefinicjeDokumentow" => new FakeOrderDefinition(), "CDN.Kontrahenci" or "CDN.Magazyny" or "CDN.Towary" => new object(), "CDN.Waluty" => new[] { "PLN", "EUR", "USD", "CZK" } .Any(currency => filter == $"WNa_Symbol='{currency}'") ? new object() : null, _ => throw new InvalidOperationException($"Nieoczekiwana kolekcja: {name}") }; public FakeOrderDocument AddNew() => name == "CDN.DokumentyHaMag" ? document : throw new InvalidOperationException($"Nieoczekiwana kolekcja: {name}"); } public sealed class FakeOrderDefinition { public int Klasa => 308; } public sealed class FakeOrderDocument { public int Rodzaj { get; set; } public int TypDokumentu { get; set; } public object? Podmiot { get; set; } public int Bufor { get; set; } public int MagazynZrodlowyID { get; set; } public string? NumerObcy { get; set; } public string? Uwagi { get; set; } public string WalutaSymbol { get; set; } = "PLN"; public int Export { get; set; } public int TypNB => 1; public int ID => 42; public string NumerPelny => "RO/42/2026"; public FakeOrderElements Elementy { get; } public decimal RazemNettoWal => Elementy.Items.Sum(line => line.Net); public decimal RazemBruttoWal => Elementy.Items.Sum(line => line.Net * (line.ExportWhenProductAssigned == 0 ? 1.23m : 1m)); public FakeOrderDocument() => Elementy = new(this); } public sealed class FakeOrderElements(FakeOrderDocument document) { public List Items { get; } = []; public FakeOrderElement AddNew() { var item = new FakeOrderElement(document); Items.Add(item); return item; } } public sealed class FakeOrderElement(FakeOrderDocument document) { public int ExportWhenProductAssigned { get; private set; } public string? CurrencyWhenProductAssigned { get; private set; } public object Towar { set { ExportWhenProductAssigned = document.Export; CurrencyWhenProductAssigned = document.WalutaSymbol; } } public double Ilosc { get; set; } public decimal Cena0 { get; set; } public double Rabat { get; set; } public decimal Net => Convert.ToDecimal(Ilosc) * Cena0 * (1m - Convert.ToDecimal(Rabat) / 100m); }