コード例 #1
0
        public void CreateValidInsertCashTransaction_Succes(decimal amount)
        {
            User user = new User("first name", "last name", "username", "*****@*****.**", 500);
            InsertCashTransaction ict = new InsertCashTransaction(user, amount);

            Assert.IsTrue(ict.User == user && ict.Amount == amount);
        }
コード例 #2
0
        public override void Execute()
        {
            if (!HasEnoughArguments(3))
            {
                barcodeCli.DisplayNotEnoughArguments(Command);
                return;
            }

            string username     = Command[1];
            string amountString = Command[2];

            try
            {
                User user = barcodeSystem.GetUserByUsername(username);

                if (decimal.TryParse(amountString, out decimal amount))
                {
                    transaction = barcodeSystem.AddCreditsToAccount(user, amount);

                    barcodeCli.DisplayAddCreditsTransaction(transaction);

                    Succeeded = true;
                }
            }
            catch (UserNotFoundException)
            {
                barcodeCli.DisplayUserNotFound(username);
            }

            base.Execute();
        }
コード例 #3
0
        public void InsertCashTransaction_CallToString_ReturnsString()
        {
            User user = Substitute.For <User>(userArgs);

            InsertCashTransaction transaction = new InsertCashTransaction(user, 50m);

            Assert.That(transaction.ToString(), Is.TypeOf <string>());
        }
コード例 #4
0
        public InsertCashTransaction CreateInsertCashTransaction(IUser user, decimal amount)
        {
            InsertCashTransaction transaction = new InsertCashTransaction(user, DateTime.Now, amount);

            transaction.NewTransactionExecutedEvent += TransactionController.Add;

            return(transaction);
        }
コード例 #5
0
        public InsertCashTransaction AddCreditsToAccount(IUser user, decimal amount)
        {
            InsertCashTransaction insertCashTransaction = new InsertCashTransaction(user, DateTime.Now, amount);

            ExecuteTransaction(insertCashTransaction);

            return(insertCashTransaction);
        }
コード例 #6
0
        public void InsertCashIntoUserAcountExecute_Succes(decimal amount)
        {
            User user = new User("first name", "last name", "username", "*****@*****.**", 500);
            InsertCashTransaction ict = new InsertCashTransaction(user, amount);

            ict.Execute();

            Assert.IsTrue(user.Balance == (500 + amount));
        }
コード例 #7
0
        public void ExecuteTransactions_ListOfTransactions_shouldAddSucceededTransactionsToListOfExecutedTransactions(string desc)
        {
            //arrange
            User    user = new User(id: 1, firstname: "jakob1", lastname: "skov", username: "******", email: "*****@*****.**", balance: 100, lowBalanceDefinition: 50);
            Product A    = new Product(id: 1, name: "A", price: 50, canBeBoughtOnCredit: true);
            Product B    = new Product(id: 2, name: "B", price: 60, active: false, canBeBoughtOnCredit: true);
            Product C    = new Product(id: 3, name: "C", price: 70, canBeBoughtOnCredit: true);
            Product D    = new Product(id: 4, name: "D", price: 80, canBeBoughtOnCredit: true);

            BuyTransaction btr1 = new BuyTransaction(user: user, product: A);
            BuyTransaction btr2 = new BuyTransaction(user: user, product: B);
            BuyTransaction btr3 = new BuyTransaction(user: user, product: C);
            BuyTransaction btr4 = new BuyTransaction(user: user, product: D);

            InsertCashTransaction Itr1 = new InsertCashTransaction(user, 100);
            //InsertCashTransaction Itr2 = new InsertCashTransaction(user, 10);
            List <Product> products = new List <Product>()
            {
                A, B, C, D
            };
            List <User> users = new List <User>()
            {
                user
            };
            Stregsystem stregsystem = new Stregsystem(users: users, products: products);


            List <Transaction> expected = new List <Transaction>()
            {
                btr1, Itr1, btr3, btr4
            };


            //act
            try
            { stregsystem.ExecuteTransaction(btr1); }
            catch { }
            try
            { stregsystem.ExecuteTransaction(btr2); }
            catch { }
            try
            { stregsystem.ExecuteTransaction(Itr1); }
            catch { }
            try
            { stregsystem.ExecuteTransaction(btr3); }
            catch { }
            try
            { stregsystem.ExecuteTransaction(btr4); }
            catch { }


            List <Transaction> actual = stregsystem.ExecutedTransactions;

            //assert
            Assert.AreEqual(expected, actual, $"{desc}: actual:{actual} expected:{expected}");
        }
コード例 #8
0
        public void AddCreditsToAccount_AddCredits_Success()
        {
            BarcodeSystem barcodeSystem = Substitute.For <BarcodeSystem>(log);
            User          user          = Substitute.For <User>(userArgs);

            InsertCashTransaction insertTransaction = barcodeSystem.AddCreditsToAccount(user, 100m);

            Assert.That(insertTransaction.Succeeded, Is.True);
            Assert.That(user.Balance, Is.EqualTo(100m));
        }
コード例 #9
0
        public void GetTransactions_UserInt_shouldReturnListOf3LatestUserTransactions(string desc)
        {
            //arrange
            User    user = new User(id: 1, firstname: "jakob1", lastname: "skov", username: "******", email: "*****@*****.**", balance: 1000, lowBalanceDefinition: 50);
            Product A    = new Product(id: 1, name: "A", price: 50);
            Product B    = new Product(id: 2, name: "B", price: 60);
            Product C    = new Product(id: 3, name: "C", price: 70);
            Product D    = new Product(id: 4, name: "D", price: 80);

            BuyTransaction btr1 = new BuyTransaction(user: user, product: A);
            BuyTransaction btr2 = new BuyTransaction(user: user, product: B);
            BuyTransaction btr3 = new BuyTransaction(user: user, product: C);
            BuyTransaction btr4 = new BuyTransaction(user: user, product: D);

            InsertCashTransaction Itr1 = new InsertCashTransaction(user, 100);
            //InsertCashTransaction Itr2 = new InsertCashTransaction(user, 10);

            List <Product> products = new List <Product>()
            {
                A, B, C, D
            };
            List <User> users = new List <User>()
            {
                user
            };
            Stregsystem stregsystem = new Stregsystem(users: users, products: products);

            List <Transaction> expected = new List <Transaction>()
            {
                Itr1, btr3, btr4
            };


            //act
            try
            { stregsystem.ExecuteTransaction(btr1); }
            catch { }
            try
            { stregsystem.ExecuteTransaction(btr2); }
            catch { }
            try
            { stregsystem.ExecuteTransaction(Itr1); }
            catch { }
            try
            { stregsystem.ExecuteTransaction(btr3); }
            catch { }
            try
            { stregsystem.ExecuteTransaction(btr4); }
            catch { }

            List <Transaction> actual = stregsystem.GetTransactions(user, 3);

            //assert
            Assert.AreEqual(expected, actual, $"{desc}: actual:{actual} expected:{expected}");
        }
コード例 #10
0
        public void Execute_UserInsertsCash_IsUserBalanceUpdatedCorrectly(decimal amount)
        {
            const decimal userBalance = 50;

            IUser        user        = CreateUser(userBalance);
            ITransaction transaction = new InsertCashTransaction(user, DateTime.Now, amount);

            transaction.Execute();

            Assert.AreEqual(userBalance + amount, user.Balance);
        }
コード例 #11
0
        public void Execute_InvalidCashAmount_ThrowInvalidCashAmountException(decimal cashAmount)
        {
            // Arrange
            IUser        user        = Substitute.For <IUser>();
            ITransaction transaction = new InsertCashTransaction(SampleID, user, SampleDate, cashAmount);

            // Act
            void ExecuteTransaction() => transaction.Execute();

            // Assert
            Assert.Throws <InvalidCashAmountException>(ExecuteTransaction);
        }
コード例 #12
0
        public void InsertCashTransaction_InsertCash_Succeeds()
        {
            User    user = Substitute.For <User>(userArgs);
            decimal previousUserBalance = user.Balance;

            InsertCashTransaction transaction = new InsertCashTransaction(user, 50m);

            transaction.Execute();

            Assert.That(user.Balance, Is.EqualTo(previousUserBalance + 50m));
            Assert.That(transaction.Succeeded, Is.True);
        }
コード例 #13
0
        public void InsertCashTransaction_UndoInsertCash_Succeeds()
        {
            User          user         = Substitute.For <User>(userArgs);
            const decimal insertAmount = 50m;

            InsertCashTransaction transaction = new InsertCashTransaction(user, insertAmount);

            transaction.Execute();
            transaction.Undo();

            Assert.That(transaction.Undone, Is.True);
            Assert.That(user.Balance, Is.EqualTo(0));
        }
コード例 #14
0
        public void InsertTransaction_InsertingAmountOnUsersBalance_ShouldUpdateBalance(decimal balance, decimal amount, string desc)
        {
            //arrange
            User user = new User(id: 1, firstname: "jakob1", lastname: "skov", username: "******", email: "*****@*****.**", balance: balance, lowBalanceDefinition: 50);
            InsertCashTransaction tr = new InsertCashTransaction(user, amount);
            decimal expected         = balance + amount;

            //act
            tr.Execute();

            //assert
            Assert.AreEqual(expected, tr.User.Balance, $"{desc}: actual:{tr.User.Balance} expected:{expected}");
        }
コード例 #15
0
        [TestCase(-1)] // Shouldn't be possible in the first place
        public void Execute_ValidCashAmount_AddCashAmountToUserBalance(decimal initialUserBalance)
        {
            // Arrange
            IUser user = Substitute.For <IUser>();

            user.Balance = initialUserBalance;
            decimal      cashToBeInserted = 10m;
            ITransaction transaction      = new InsertCashTransaction(SampleID, user, SampleDate, cashToBeInserted);

            // Act
            transaction.Execute();
            // Assert
            Assert.AreEqual(initialUserBalance + cashToBeInserted, user.Balance);
        }
コード例 #16
0
        public void ToString_BuyTransAction_ShouldReturnString(string desc)
        {
            //arrange
            User     user            = new User();
            DateTime date            = Convert.ToDateTime("1 / 1 / 2020");
            Guid     id              = Guid.NewGuid();
            decimal  amount          = 20;
            InsertCashTransaction tr = new InsertCashTransaction(user: user, date: date, id: id, amount: amount);

            string expected = $"{date};{id};Insert;{user};{amount}";
            //act
            string actual = tr.ToString();

            //assert
            Assert.AreEqual(expected, actual, desc);
        }
コード例 #17
0
ファイル: BarcodeCli.cs プロジェクト: chhoumann/Barcode
 public void DisplayAddCreditsTransaction(InsertCashTransaction transaction)
 {
     Console.WriteLine(transaction.ToString());
 }
コード例 #18
0
 public void DisplayAdminAddedCredits(InsertCashTransaction transaction)
 {
     Console.WriteLine("[{0}] was added to [{1}]'s balance.", transaction.Amount.ToKr(), transaction.User.UserName);
 }
コード例 #19
0
        public void WriteToLogFile_TransactionList_ShouldWriteListToFile(string desc)
        {
            //arrange
            User user1 = new User(id: 1, firstname: "jakob1", lastname: "skov", username: "******", email: "*****@*****.**", balance: 1000, lowBalanceDefinition: 50);
            User user2 = new User(id: 2, firstname: "jakob2", lastname: "skov", username: "******", email: "*****@*****.**", balance: 10000, lowBalanceDefinition: 50);

            Product A = new Product(id: 1, name: "A", price: 50);
            Product B = new Product(id: 2, name: "B", price: 60);
            Product C = new Product(id: 3, name: "C", price: 70);
            Product D = new Product(id: 4, name: "D", price: 80);

            //user1
            BuyTransaction btr1 = new BuyTransaction(user: user1, product: A);
            BuyTransaction btr2 = new BuyTransaction(user: user1, product: B);
            BuyTransaction btr3 = new BuyTransaction(user: user1, product: C);
            BuyTransaction btr4 = new BuyTransaction(user: user1, product: D);

            InsertCashTransaction Itr1 = new InsertCashTransaction(user1, 100);
            InsertCashTransaction Itr2 = new InsertCashTransaction(user1, 10);
            //user2
            BuyTransaction btr5 = new BuyTransaction(user: user2, product: A);
            BuyTransaction btr6 = new BuyTransaction(user: user2, product: B);
            BuyTransaction btr7 = new BuyTransaction(user: user2, product: C);
            BuyTransaction btr8 = new BuyTransaction(user: user2, product: D);

            InsertCashTransaction Itr3 = new InsertCashTransaction(user2, 100);
            InsertCashTransaction Itr4 = new InsertCashTransaction(user2, 10);

            List <Product> products = new List <Product>()
            {
                A, B, C, D
            };
            List <User> users = new List <User>()
            {
                user1, user2
            };
            Stregsystem stregsystem = new Stregsystem(users: users, products: products);

            bool expected = true;


            //act
            try
            { stregsystem.ExecuteTransaction(btr1); }
            catch { }
            try
            { stregsystem.ExecuteTransaction(btr2); }
            catch { }
            try
            { stregsystem.ExecuteTransaction(Itr1); }
            catch { }
            try
            { stregsystem.ExecuteTransaction(btr3); }
            catch { }
            try
            { stregsystem.ExecuteTransaction(btr4); }
            catch { }
            try
            { stregsystem.ExecuteTransaction(Itr2); }
            catch { }

            try
            { stregsystem.ExecuteTransaction(btr5); }
            catch { }
            try
            { stregsystem.ExecuteTransaction(btr6); }
            catch { }
            try
            { stregsystem.ExecuteTransaction(Itr3); }
            catch { }
            try
            { stregsystem.ExecuteTransaction(btr7); }
            catch { }
            try
            { stregsystem.ExecuteTransaction(btr8); }
            catch { }
            try
            { stregsystem.ExecuteTransaction(Itr4); }
            catch { }

            bool actual = stregsystem.WriteToLogFile(stregsystem.ExecutedTransactions);

            //assert
            Assert.AreEqual(actual, expected, $"{desc}: actual file:{actual}: expected file{expected}");
        }
コード例 #20
0
ファイル: StregsystemCLI.cs プロジェクト: FlunkyHD/sem3
 public void DisplayInserCashTransation(InsertCashTransaction transaction)
 {
     Console.WriteLine(transaction);
 }