コード例 #1
0
        public void SurroundIsZero()
        {
            Accounting sut = new Accounting();

            sut.AddAccount("T", "Tillgångar", true);
            sut.AddAccount("S", "Skulder", true);
            sut.AddAccount("I", "Inkomster", true);
            sut.AddAccount("K", "Kostnader", true);
            sut.AddAccount("1010", "Kassa", false);
            sut.AddAccount("1040", "Handelsbanken", false);
            sut.MapParentToChild("T", "1010");
            sut.MapParentToChild("S", "1040");
            sut.AddTransaction("1010", "1040", 500);
            var entries = new List <Tuple <string, string, decimal> >();

            entries.Add(new Tuple <string, string, decimal>("1010", "1040", 500));
            entries.Add(new Tuple <string, string, decimal>("1040", "1010", 200));
            sut.AddTransactions(entries);
            Assert.Equal(sut.Surround, 0M);
            Assert.Equal(sut.AccountBalance("1010"), 500);
            Assert.Equal(sut.AccountBalance("1040"), -500);
        }
コード例 #2
0
        public void ImportSIE()
        {
            Accounting sut = new Accounting();

            sut.AddAccount("T", "Tillgångar", true);
            sut.AddAccount("S", "Skulder", true);
            sut.AddAccount("I", "Inkomster", true);
            sut.AddAccount("K", "Kostnader", true);

            var fileName     = "MATTIAS0_SIE4 2015-09-01 - 2016-08-31.SE.txt";
            var reader       = File.OpenRead(fileName);
            var stringReader = new StreamReader(reader);
            var rowCount     = 0;
            List <Tuple <string, decimal> > entries = null;

            while (true)
            {
                string line = stringReader.ReadLine();
                if (line == null)
                {
                    break;
                }
                if (line.StartsWith("#KTYP"))
                {
                    string pattern = @"#KTYP (\d{4}) (.)";
                    var    match   = Regex.Match(line, pattern);
                    sut.AddAccount(match.Groups[1].Value, "", false);
                    sut.MapParentToChild(match.Groups[2].Value, match.Groups[1].Value);
                }
                if (line.StartsWith("#VER"))
                {
                    entries = new List <Tuple <string, decimal> >();
                }
                if (line.StartsWith("   #TRANS"))
                {
                    string pattern = @"#TRANS (\d{4}) {} (-?\d*.\d*)";
                    var    match   = Regex.Match(line, pattern);
                    var    amount  = decimal.Parse(match.Groups[2].Value, CultureInfo.InvariantCulture);
                    entries.Add(new Tuple <string, decimal>(match.Groups[1].Value, amount));
                }
                if (line == "}")
                {
                    sut.AddTransaction(entries);
                }
                rowCount++;
            }
            output.WriteLine(rowCount.ToString());
            output.WriteLine("Tillgångar: " + sut.AccountBalance("T").ToString());
            output.WriteLine("Intäkter: " + sut.AccountBalance("I").ToString());
        }