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