示例#1
0
        public void Acceptance()
        {
            var clock             = new Mock <IClock>();
            var mockOutputConsole = new Mock <OutputConsole>();
            var statementPrinter  = new StatementPrinter(mockOutputConsole.Object);
            var transactionLedger = new TransactionLedger(clock.Object);
            var atm = new ATM(statementPrinter, transactionLedger);

            var timeOfTransaction = new DateTime(2012, 01, 10);

            clock.Setup(clockMock => clockMock.getTime()).Returns(timeOfTransaction.ToUniversalTime);
            atm.Deposit(1000);
            timeOfTransaction = new DateTime(2012, 01, 13);
            clock.Setup(clockMock => clockMock.getTime()).Returns(timeOfTransaction.ToUniversalTime);
            atm.Deposit(2000);
            timeOfTransaction = new DateTime(2012, 01, 14);
            clock.Setup(clockMock => clockMock.getTime()).Returns(timeOfTransaction.ToUniversalTime);
            atm.Withdraw(500);
            atm.PrintStatement();


            mockOutputConsole.Verify(console => console.WriteLine("date || credit || debit || balance"));
            mockOutputConsole.Verify(outputMock => outputMock.WriteLine("14/01/2012 || || 500.00 || 2500.00"));
            mockOutputConsole.Verify(outputMock => outputMock.WriteLine("13/01/2012 || 2000.00 || || 3000.00"));
            mockOutputConsole.Verify(outputMock => outputMock.WriteLine("10/01/2012 || 1000.00 || || 1000.00"));
        }
示例#2
0
        public void PrintEmptyAccountIfNoStatements()
        {
            var statementPrinter = new StatementPrinter();
            var result           = statementPrinter.Print();

            Assert.That(result, Is.EqualTo("Date||Credit||Debit||Balance\n"));
        }
        public void Setup()
        {
            ITransactionRepository transactionRepository = new TransactionRepository(clock);
            IStatementPrinter      statementPrinter      = new StatementPrinter(console);

            account = new Account(transactionRepository, statementPrinter);
        }
示例#4
0
        public void PrintStatementAcceptanceTest()
        {
            // Arrange
            var clockMock = new Mock <IClock>();

            var consoleMock           = new Mock <IConsole>();
            var consoleCalls          = new List <string>();
            var transactionRepository = new TransactionRepository();
            var statementPrinter      = new StatementPrinter(consoleMock.Object);

            consoleMock.Setup(m => m.WriteLine(Capture.In(consoleCalls)));

            var account = new Account(clockMock.Object, transactionRepository, statementPrinter);

            // Act
            clockMock.Setup((x) => x.Now()).Returns(new DateTime(2012, 01, 10));
            account.Deposit(1000);

            clockMock.Setup((x) => x.Now()).Returns(new DateTime(2012, 01, 13));
            account.Deposit(2000);

            clockMock.Setup((x) => x.Now()).Returns(new DateTime(2012, 01, 14));
            account.Withdraw(500);

            account.PrintStatement();

            // Assert
            consoleCalls.Should().BeEquivalentTo(new string[]
            {
                "Date       || Amount || Balance",
                "14/01/2012 || -500   || 2500",
                "13/01/2012 || 2000   || 3000",
                "10/01/2012 || 1000   || 1000",
            });
        }
示例#5
0
 public Account(
     TransactionRepository transactionRepository,
     StatementPrinter printterStatemnt)
 {
     _transactionRepository = transactionRepository;
     _printterStatemnt      = printterStatemnt;
 }
示例#6
0
 public void Setup()
 {
     _calendar         = new Mock <Calendar>();
     _txHistory        = new TxHistory(_calendar.Object);
     _console          = new Mock <BankConsole>();
     _txRecordPrinter  = new Mock <IPrinter <TxRecord> >();
     _statementPrinter = new StatementPrinter(_console.Object, _txRecordPrinter.Object, _calendar.Object);
 }
示例#7
0
 public void Setup()
 {
     _transactionRepository = new TransactionRepository();
     _console          = Substitute.For <IConsole>();
     _statementPrinter = new StatementPrinter(_console);
     _clock            = Substitute.For <IClock>();
     _account          = new Account(_transactionRepository, _statementPrinter, _clock);
 }
示例#8
0
        public void PrintStatement()
        {
            var allTransactions = transactionsStore.All;

            var statementPrinter = new StatementPrinter(console);

            statementPrinter.PrintFor(allTransactions);
        }
示例#9
0
        public void Print_WhenNoTransactions_HeaderOnlyIsPrinted()
        {
            var console          = new Mock <IConsole>();
            var statementPrinter = new StatementPrinter(console.Object);

            statementPrinter.Print(new List <Transaction>());
            console.Verify(x => x.PrintLine("DATE | AMOUNT | BALANCE"));
        }
示例#10
0
        public BankAccountAcceptanceTest()
        {
            _mockPrinter = new Mock <IPrinter>(MockBehavior.Strict);
            _mockClock   = new Mock <Clock>();
            var statementFormatter = new StatementFormatter();

            _statementPrinter = new StatementPrinter(_mockPrinter.Object, statementFormatter);
        }
示例#11
0
        public void AlwaysPrintTheHeader()
        {
            var statmentPrinter = new StatementPrinter(_console.Object);

            statmentPrinter.Print(new List <Transaction>());

            _console.Verify(x => x.WriteLine("DATE | AMOUNT | BALANCE"));
        }
示例#12
0
        public void PrintStatementWithNoTransactions()
        {
            var printer      = new Mock <IPrinter>();
            var sp           = new StatementPrinter(printer.Object);
            var transactions = new List <Transaction>();

            sp.Print(new ReadOnlyCollection <Transaction>(transactions));
            printer.Verify(p => p.Print("Date || Amount || Balance"), Times.Once);
        }
示例#13
0
 public void SetUp()
 {
     _calendar         = new Mock <Calendar>();
     _console          = new Mock <BankConsole>();
     _txHistory        = new TxHistory(_calendar.Object);
     _txRecordPrinter  = new TxRecordPrinter(_console.Object, new CultureInfo("en-GB"));
     _statementPrinter = new StatementPrinter(_console.Object, _txRecordPrinter, _calendar.Object);
     _account          = new Account(_txHistory, _statementPrinter);
 }
示例#14
0
        public void Always_Print_The_Header()
        {
            IConsole         console          = Substitute.For <IConsole>();
            StatementPrinter statementPrinter = new StatementPrinter(console);

            statementPrinter.Print(NO_TRANSACTIONS);

            console.Received().PrintLine("DATE | AMOUNT | BALANCE");
        }
        public void PrintEmptyStatement()
        {
            var printer      = new StatementPrinter();
            var transactions = new List <Transaction>();

            var printedStatement  = printer.Print(transactions);
            var expectedStatement = StatementPrinter.HeaderFormat;

            Assert.Equal(expectedStatement, printedStatement);
        }
示例#16
0
        public void SetUp()
        {
            _console = new Mock <Console>();
            _clock   = new Mock <Clock>();

            var transactionRepository = new TransactionRepository(_clock.Object);
            var statementPrinder      = new StatementPrinter(_console.Object);

            _account = new Account(transactionRepository, statementPrinder);
        }
示例#17
0
        private bool ProcessStatementPrint(long statementId, long?printerId)
        {
            bool HasPrinted;

            if (!printerId.HasValue)
            {
                return(false);
            }

            using (var uow = new DevExpress.Xpo.UnitOfWork())
            {
                XDB.GLX_Statement statement = uow.Query <XDB.GLX_Statement>().SingleOrDefault(n => n.Id == statementId);

                XDB.SYS_Printer printer = uow.Query <XDB.SYS_Printer>().SingleOrDefault(n => n.Id == printerId.Value);

                try
                {
                    var account = uow.Query <XDB.GLX_Account>().Where(n => n.EntityId.Id == statement.EntityId.Id).Select(l => new { l.EntityId.CodeMain, l.EntityId.CodeSub }).FirstOrDefault();

                    if (account.CodeMain == BL.ApplicationDataContext.Instance.SiteAccounts.DebtorsEntity.CodeMain)
                    {
                        StatementPrinter sp = new StatementPrinter();
                        sp.PrintStatement(printer.Location, printer.PrinterModel, StatementCustomerPrintTemplate.OuterXml, statement.EntityId.Id, statement.PeriodId.Id, ConfigurationManager.ConnectionStrings["BaseConnection"].ConnectionString);

                        //sp = new StatementPrinter();
                        //if (!System.IO.Directory.Exists(System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\Statements"))
                        //    System.IO.Directory.CreateDirectory(System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\Statements");
                        //
                        //sp.PrintStatementToFile(string.Format(@"{0}\STATEMENT_{1}.txt", System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\Statements", statement.EntityId.Id), printer.PrinterModel, StatementCustomerPrintTemplate.OuterXml, statement.EntityId.Id, statement.PeriodId.Id, ConfigurationManager.ConnectionStrings["BaseConnection"].ConnectionString);
                    }
                    else
                    if (account.CodeMain == BL.ApplicationDataContext.Instance.SiteAccounts.CreditorsEntity.CodeMain)
                    {
                        StatementPrinter sp = new StatementPrinter();
                        sp.PrintStatement(printer.Location, printer.PrinterModel, StatementSupplierPrintTemplate.OuterXml, statement.EntityId.Id, statement.PeriodId.Id, ConfigurationManager.ConnectionStrings["BaseConnection"].ConnectionString);

                        //sp = new StatementPrinter();
                        //if (!System.IO.Directory.Exists(System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\Statements"))
                        //    System.IO.Directory.CreateDirectory(System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\Statements");
                        //
                        //sp.PrintStatementToFile(string.Format(@"{0}\STATEMENT_{1}.txt", System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\Statements", statement.EntityId.Id), printer.PrinterModel, StatementSupplierPrintTemplate.OuterXml, statement.EntityId.Id, statement.PeriodId.Id, ConfigurationManager.ConnectionStrings["BaseConnection"].ConnectionString);
                    }

                    statement.HasPrinted = HasPrinted = true;
                }
                catch
                {
                    statement.HasPrinted = HasPrinted = false;
                }

                uow.CommitChanges();
            }

            return(HasPrinted);
        }
示例#18
0
        public void write_header_to_console()
        {
            var mockOutputConsole = new Mock <OutputConsole>();

            var statementPrinter  = new StatementPrinter(mockOutputConsole.Object);
            var transactionLedger = new Mock <ITransactionLedger>();

            statementPrinter.Print(transactionLedger.Object);

            mockOutputConsole.Verify(console => console.WriteLine("date || credit || debit || balance"));
        }
示例#19
0
        public void PrintDeposit()
        {
            var statementPrinter = new StatementPrinter();

            statementPrinter.Add(new PrintableStatement(NewDeposit(1000), new Money(1000)));

            var result = statementPrinter.Print();

            Assert.That(result, Is.EqualTo("Date||Credit||Debit||Balance\n" +
                                           "10/01/2012||||1000||1000\n"));
        }
示例#20
0
        public void StatementPrinter_can_print_transaction(string dateString, int value, string expected)
        {
            var date         = DateTime.Parse(dateString);
            var transaction  = new Transaction(date, value);
            var transactions = new List <Transaction>();

            transactions.Add(transaction);

            var statementPrinter = new StatementPrinter();
            var result           = statementPrinter.Print(transactions);

            Assert.AreEqual(expected, result);
        }
示例#21
0
        static void Main(string[] args)
        {
            var clock   = new Clock();
            var console = new ConsoleWriter();
            var transactionRepository = new TransactionRepository(clock);
            var statementPrinter      = new StatementPrinter(console);
            var account = new Account(transactionRepository, statementPrinter);

            account.Deposit(1000);
            account.Withdraw(400);
            account.Deposit(100);

            account.PrintStatement();
        }
示例#22
0
        public void Increase_Balance_On_Current_Statement_After_A_Deposit()
        {
            var consoleMock = Substitute.For<IConsole>();
            var statementPrinter = new StatementPrinter(consoleMock);
            var account = new Account(new Transactions());
            var atm = new Atm(statementPrinter, account);

            // act
            atm.Deposit(2000);
            atm.PrintStatement();

            // assert
            consoleMock.Received().WriteLine(Arg.Is<string>(line => line.Contains("balance = 2000")));
        }
示例#23
0
        static void Main(string[] args)
        {
            var transactionStore = new TransactionStore(new Clock());
            var statementPrinter = new StatementPrinter(new DefaultConsole());
            var account          = new Account(transactionStore, statementPrinter);

            account.Deposit(1000);
            account.Withdraw(100);
            account.Deposit(500);

            account.PrintStatement();

            System.Console.ReadLine();
        }
示例#24
0
        static void Main(string[] args)
        {
            IClock clock = new Clock();
            ITransactionRepository transactionRepository = new TransactionRepository(clock);
            IConsole          console          = new Console();
            IStatementPrinter statementPrinter = new StatementPrinter(console);
            Account           account          = new Account(transactionRepository, statementPrinter);

            account.Deposit(1000);
            account.Withdraw(100);
            account.Deposit(500);

            account.PrintStatement();
        }
示例#25
0
        public void StatementPrinter_can_create_statement_as_defined_Kata()
        {
            var transactions = new List <Transaction>()
            {
                new Transaction(DateTime.Parse("14/01/2012"), -500),
                new Transaction(DateTime.Parse("13/01/2012"), 2000),
                new Transaction(DateTime.Parse("10/01/2012"), 1000)
            };

            var printer  = new StatementPrinter();
            var result   = printer.Print(transactions);
            var expected = $"14/01/2012,-500,2500;13/01/2012,2000,3000;10/01/2012,1000,1000;";

            Assert.AreEqual(expected, result);
        }
示例#26
0
        public void test_statement_with_new_play_types()
        {
            var plays = new Dictionary <string, Play>();

            plays.Add("henry-v", new Play("Henry V", "history"));
            plays.Add("as-like", new Play("As You Like It", "pastoral"));

            Invoice invoice = new Invoice("BigCoII", new List <Performance> {
                new Performance("henry-v", 53),
                new Performance("as-like", 55)
            });

            StatementPrinter statementPrinter = new StatementPrinter();

            Assert.Throws <Exception>(() => statementPrinter.Print(invoice, plays));
        }
示例#27
0
        private static void Main(string[] args)
        {
            var clock                 = new Clock();
            var outputWriter          = new OutputWriter();
            var transactionRepository = new TransactionRepository(clock);
            var statementPrinter      = new StatementPrinter(outputWriter);
            var account               = new Account(transactionRepository, statementPrinter);

            Console.WriteLine();
            account.Deposit(1000);
            account.Withdrawal(100);
            account.Deposit(500);

            account.PrintStatement();

            Console.ReadLine();
        }
示例#28
0
        public void test_statement_html_with_new_play_types()
        {
            var plays = new Dictionary <string, Play>();

            plays.Add("henry-v", Play.CreatePlay("Henry V", "history"));
            plays.Add("as-like", Play.CreatePlay("As You Like It", "pastoral"));

            Invoice invoice = new Invoice("BigCoII", new List <Performance> {
                new Performance("henry-v", 53),
                new Performance("as-like", 55)
            });

            StatementPrinter statementPrinter = new StatementPrinter(new HtmlStatementFormatter());

            var result = statementPrinter.Print(invoice, plays);

            Approvals.Verify(result);
        }
        public void PrintStatementWithOneTransaction()
        {
            var ammount      = 100;
            var transaction  = new Transaction(DateTime.Now, ammount, ammount);
            var transactions = new List <Transaction>()
            {
                transaction
            };
            var printer = new StatementPrinter();

            var printedStatement  = printer.Print(transactions);
            var expectedStatement =
                StatementPrinter.HeaderFormat
                + Environment.NewLine + PrintedTransaction(transaction);


            Assert.Equal(expectedStatement, printedStatement);
        }
示例#30
0
        public void test_statement_example()
        {
            var plays = new Dictionary <string, Play>();

            plays.Add("hamlet", new Play("Hamlet", "tragedy"));
            plays.Add("as-like", new Play("As You Like It", "comedy"));
            plays.Add("othello", new Play("Othello", "tragedy"));

            Invoice invoice = new Invoice("BigCo", new List <Performance> {
                new Performance("hamlet", 55),
                new Performance("as-like", 35),
                new Performance("othello", 40)
            });

            StatementPrinter statementPrinter = new StatementPrinter();
            var result = statementPrinter.Print(invoice, plays);

            Approvals.Verify(result);
        }
示例#31
0
        public void Print_WhenMultipleTransactions_TransactionsPrintedInReverseChronologicalOrder()
        {
            var console          = new Mock <IConsole>();
            var statementPrinter = new StatementPrinter(console.Object);

            var transactions = new List <Transaction>
            {
                new Transaction(-50, "10/04/2014"),
                new Transaction(100, "12/04/2014"),
                new Transaction(1000, "11/04/2014")
            };

            statementPrinter.Print(transactions);

            console.Verify(x => x.PrintLine("DATE | AMOUNT | BALANCE"));
            console.Verify(x => x.PrintLine("12/04/2014 | 100.00 | 1050.00"));
            console.Verify(x => x.PrintLine("11/04/2014 | 1000.00 | 950.00"));
            console.Verify(x => x.PrintLine("10/04/2014 | -50.00 | -50.00"));
        }
 public StatementPrinterShould()
 {
     printer = new StatementPrinter(console);
 }
 public PrintStatementFeature()
 {
     clock.TodayAsString.Returns("01/11/2015", "02/11/2015", "10/11/2015");
     transactionRepository = new InMemoryTransactionReopsitory(clock);
     statementPrinter = new StatementPrinter(console);
 }