コード例 #1
0
        public void BuyProduct_ProductPrice10_shouldChangeUserBalanceTo90(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: 1);
            Product        B        = new Product(id: 10, name: "B", price: 10);
            Product        C        = new Product(id: 33, name: "C", price: 100);
            List <Product> products = new List <Product>()
            {
                A, B, C
            };
            List <User> users = new List <User>()
            {
                user
            };
            Stregsystem stregsystem = new Stregsystem(users: users, products: products);

            decimal expected = 90;

            //act
            stregsystem.BuyProduct(user, B);
            decimal actual = user.Balance;

            //assert
            Assert.AreEqual(expected, actual, desc);
        }
コード例 #2
0
        public void GetUserByUsername_String_shouldReturnMatchingUserUser5(string desc)
        {
            //arrange
            User    user1 = new User(id: 1, firstname: "jakob1", lastname: "skov", username: "******", email: "*****@*****.**", balance: 100, lowBalanceDefinition: 50);
            User    user2 = new User(id: 2, firstname: "jakob2", lastname: "skov", username: "******", email: "*****@*****.**", balance: 100, lowBalanceDefinition: 50);
            User    user3 = new User(id: 3, firstname: "jakob3", lastname: "skov", username: "******", email: "*****@*****.**", balance: 55, lowBalanceDefinition: 50);
            User    user4 = new User(id: 4, firstname: "jakob4", lastname: "skov", username: "******", email: "*****@*****.**", balance: 20, lowBalanceDefinition: 50);
            User    user5 = new User(id: 5, firstname: "jakob5", lastname: "skov", username: "******", email: "*****@*****.**", balance: 0, lowBalanceDefinition: 50);
            Product A     = new Product(id: 1, name: "A", price: 50);

            List <Product> products = new List <Product>()
            {
                A
            };
            List <User> users = new List <User>()
            {
                user1, user2, user3, user4, user5
            };
            Stregsystem stregsystem = new Stregsystem(users: users, products: products);

            User expected = user5;

            //act
            User actual = stregsystem.GetUserByUsername("js5");

            //assert
            Assert.AreEqual(actual, expected, $"{desc}: actual:{actual} expected:{expected}");
        }
コード例 #3
0
        public void GetProductByID_ID33_shouldReturnC(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);
            Product B    = new Product(id: 2, name: "B", price: 60);
            Product C    = new Product(id: 33, name: "C", price: 70);
            Product D    = new Product(id: 4, name: "D", price: 80);

            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);

            Product expected = C;

            //act
            Product actual = stregsystem.GetProductByID(33);

            //assert
            Assert.AreEqual(expected, actual, $"{desc}: actual:{actual} expected:{expected}");
        }
コード例 #4
0
        ////done
        public void CommandParser_Command_ShouldNotTriggerException(string command, string desc)
        {
            //arrange
            User           user1    = new User(id: 1, firstname: "jakob1", lastname: "skov", username: "******", email: "*****@*****.**", balance: 100, lowBalanceDefinition: 50);
            User           user2    = new User(id: 2, firstname: "jakob1", lastname: "skov", username: "******", email: "*****@*****.**", balance: 100, lowBalanceDefinition: 50);
            User           user3    = new User(id: 3, firstname: "jakob1", lastname: "skov", username: "******", email: "*****@*****.**", balance: 100, lowBalanceDefinition: 50);
            Product        A        = new Product(id: 1, name: "A", price: 1);
            Product        B        = new Product(id: 10, name: "B", price: 10);
            Product        C        = new Product(id: 33, name: "C", price: 100);
            List <Product> products = new List <Product>()
            {
                A, B, C
            };
            List <User> users = new List <User>()
            {
                user1, user2, user3
            };
            Stregsystem           stregsystem = new Stregsystem(users: users, products: products);
            IStregsystemUI        ui          = new StregsystemCLI(stregsystem);
            StregsystemController sc          = new StregsystemController(ui, stregsystem);

            //act
            //assert
            Assert.DoesNotThrow(() => ui.Start(command), $"{desc}: exception");
        }
コード例 #5
0
        static void Main(string[] args)
        {
            IStregsystem          stregsystem = new Stregsystem();
            IStregsystemUI        ui          = new StregsystemCLI(stregsystem);
            StregsystemController sc          = new StregsystemController(ui, stregsystem);

            ui.Start();
        }
コード例 #6
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}");
        }
コード例 #7
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}");
        }
コード例 #8
0
ファイル: Program.cs プロジェクト: Stg3orge/Gundamnation
        static void Main(string[] args)
        {

            // Would have liked to use my UserList class here
            User Jacob = new User("Jacob", "Thomsen", "stgeorge", "*****@*****.**", 49);
            User John = new User("John", "Cena", "johncenashow", "*****@*****.**", 150);


            Stregsystem stregsystem = new Stregsystem();
            stregsystem.userList.Add(John);
            stregsystem.userList.Add(Jacob);
            StregsystemCLI ui = new StregsystemCLI(stregsystem);
            StregsystemController sc = new StregsystemController(ui, stregsystem);

            ui.Start(sc);

            System.Console.ReadKey();
        }
コード例 #9
0
        static void Main(string[] args)
        {
            IStregsystem          stregsystem = new Stregsystem();
            IStregsystemUI        ui          = new StregsystemUI(stregsystem);
            StregSystemController sc          = new StregSystemController(ui, stregsystem);

            ui.Start();

            /*sc.ParseCommand("jleve");
             * sc.ParseCommand("jleve 20");
             * sc.ParseCommand("jleve 3 30");
             *
             * sc.ParseCommand(":activate 25");
             *
             * IEnumerable<Product> activeproducts = stregsystem.ActiveProducts;
             *
             * foreach (Product prod in activeproducts)
             * {
             *  Console.WriteLine(prod);
             * }*/
        }
コード例 #10
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}");
        }