public void Case3_WhenCalled_ReturnTotalInterestOn2WalletFor2PersonWith2CardEachOne() { var person1 = new Person(); var wallet1 = new Wallet(); var mastercard = new MasterCard(); wallet1.AddCardToWallet(mastercard); var visacard = new VisaCard(); wallet1.AddCardToWallet(visacard); person1.AddWalletToPerson(wallet1); var person2 = new Person(); var wallet2 = new Wallet(); var visacard2 = new VisaCard(); wallet2.AddCardToWallet(visacard2); var mastercard2 = new MasterCard(); wallet2.AddCardToWallet(mastercard2); person2.AddWalletToPerson(wallet2); var resultforperson1 = person1.TotalInterest(); var resultforperson2 = person2.TotalInterest(); Assert.AreEqual(15, resultforperson1); Assert.AreEqual(15, resultforperson2); }
public void When_SimpleInterestIs10_On1Cards_InterestIs10() { Card visaCard = new VisaCard("Visa1", 100, .1); FullPersonInterestCalculator interestCalculator = new FullPersonInterestCalculator(new SimpleInterestCalculator()); Card newVisa = interestCalculator.ComputeTotalInterestForCard(visaCard, 1); Assert.That(newVisa.Interest, Is.EqualTo(10).Within(.1)); }
public void ChooseType() { if (VisaType) { ComponentCardType cvtype = new VisaCard(); ChooseCategory(cvtype); } else { ComponentCardType cmtype = new MasterCard(); ChooseCategory(cmtype); } }
static void Main(string[] args) { // REGISTRATION var container = new WindsorContainer(); // For windows you need to register Shopper. Unity does this for you automatically //container.Register(Component.For<Shopper>()); // Map ICreditCard to MasterCard concrete type with default // name by "DefaultType" container.Register(Component.For <ICreditCard>().ImplementedBy <MasterCard>().Named("DefaultType")); // Registration with instance => instead of specifying ICreditCard resolve to concrete type var cc = new VisaCard(); container.Register(Component.For <ICreditCard>().Instance(cc)); // RESOLVE container.Register(Component.For <Shopper>()); container.Register(Component.For <ICreditCard>().ImplementedBy <MasterCard>()); var shopper = container.Resolve <Shopper>(); shopper.Charge(); // AUTOMATIC SETTER INJECTION // Windsor will automatically resolve ICreditCard property // and resolve it without specifying it like in Unity // This is enought for it to resolve //container.Register(Component.For<Shopper>()); // LIFECYCLE // Transient => everything time shopper is created a new one is created container.Register(Component.For <Shopper>().LifeStyle.Transient); // Everytime I ask for MasterCard a new one is created container.Register(Component.For <ICreditCard>().ImplementedBy <MasterCard>().LifeStyle.Transient); // WINDSOR FEATURES // AddFacility => inject into Windsor engine //container.AddFacility() // Install => provides a way to put all registration in one place container.Install(new ShoppingInstaller()); }
public void Case1_WhenCalled_ReturnTotalInterestOn1WalletFor1PersonWith3Card() { var person = new Person(); var wallet = new Wallet(); var visacard = new VisaCard(); wallet.AddCardToWallet(visacard); var mastercard = new MasterCard(); wallet.AddCardToWallet(mastercard); var discovercard = new DiscoverCard(); wallet.AddCardToWallet(discovercard); person.AddWalletToPerson(wallet); var result = person.TotalInterest(); Assert.AreEqual(16, result); }
public ActionResult Create([Bind(Include = "id,cardNumber,expiryMonth,expiryYear,type")] CreditCard creditCard) { if (ModelState.IsValid) { CreditCard credCard = null; if (creditCard.type == "AmericanExpress") { credCard = new AmericanExpressCard(creditCard.cardNumber, creditCard.expiryMonth, creditCard.expiryYear); } else if (creditCard.type == "MasterCard") { credCard = new MasterCard(creditCard.cardNumber, creditCard.expiryMonth, creditCard.expiryYear); } else if (creditCard.type == "Visa") { credCard = new VisaCard(creditCard.cardNumber, creditCard.expiryMonth, creditCard.expiryYear); } credCard.user = db.Users.Find(User.Identity.GetUserId()); if (credCard.validate()) { db.CreditCards.Add(credCard); db.SaveChanges(); return(RedirectToAction("Index")); } List <Product> products = (List <Product>)Session["cart"]; foreach (var item in products) { OrderHistory hist = new OrderHistory(); hist.date = new DateTime(); hist.user = db.Users.Find(User.Identity.GetUserId()); hist.product = item; db.OrderHistories.Add(hist); db.SaveChanges(); } } return(View("Create")); }
public void When_CardIsCreateWithName_Then_NamePropertyIsName() { Card visaCard = new VisaCard("CardName", 100, 0.1); Assert.That(visaCard.Name, Is.EqualTo("CardName")); }
protected override void Seed(ApplicationContext db) { var userManager = new ApplicationUserManager(new UserStore <ApplicationUser>(db)); var roleManager = new ApplicationRoleManager(new RoleStore <ApplicationRole>(db)); // создаем две роли var role1 = new ApplicationRole { Name = "admin" }; var role2 = new ApplicationRole { Name = "user" }; var role3 = new ApplicationRole { Name = "blockedUser" }; var role4 = new ApplicationRole { Name = "moderator" }; // добавляем роли в бд roleManager.Create(role1); roleManager.Create(role2); roleManager.Create(role3); roleManager.Create(role4); var card1 = new VisaCard() { Name = "Test Card1", Number = "1234567891234567", Month = "10", Year = "20", SecurityCodeHash = "123" }; var card2 = new MasterCard() { Name = "Test Card2", Number = "9887655432216554", Month = "07", Year = "24", SecurityCodeHash = "000" }; var card3 = new MasterCard() { Name = "Test Card3", Number = "1887655432216552", Month = "02", Year = "26", SecurityCodeHash = "000" }; var card4 = new MasterCard() { Name = "Test Card4", Number = "1887655432216444", Month = "06", Year = "27", SecurityCodeHash = "000" }; var cards = new List <CreditCard> { card1, card2 }; var cards1 = new List <CreditCard> { card3 }; var cards2 = new List <CreditCard> { card4 }; db.CreditCards.Add(card1); db.CreditCards.Add(card2); db.CreditCards.Add(card3); db.CreditCards.Add(card4); //////////////create payments/////////// var payment1 = new Payment() { Amount = 100, Date = DateTime.Now, Details = "First Test payment 100", IsSent = true, Name = "Test Payment", }; var payment2 = new Payment() { Amount = 9000, Date = DateTime.Now, Details = "First Test payment 9000", IsSent = true, Name = "Test Payment", }; var payments1 = new List <Payment> { payment1 }; var payments2 = new List <Payment> { payment2 }; db.Payments.Add(payment1); ////////create accounts///////////////// var account1 = new Account() { Balance = 1000, CreditCard = card3, Number = 100000091, Name = "Account1", PaymentsRecieve = payments1, PaymentsSent = payments2 }; var account2 = new Account() { Balance = 50000, CreditCard = card4, Number = 100000099, Name = "Account2", PaymentsRecieve = payments2, PaymentsSent = payments1 }; var accounts1 = new List <Account> { account1 }; var accounts2 = new List <Account> { account2 }; db.Accounts.Add(account1); db.Accounts.Add(account2); /////////////create user profiles///////////// var profile = new ClientProfile() { Name = "Admin", BirthDate = DateTime.Now, Cards = cards, }; var userProfile1 = new ClientProfile() { Name = "User1", BirthDate = DateTime.Now, Cards = cards1, Accounts = accounts1, }; var userProfile2 = new ClientProfile() { Name = "User2", BirthDate = DateTime.Now, Cards = cards2, Accounts = accounts2, }; // создаем пользователей var admin = new ApplicationUser { Email = "*****@*****.**", UserName = "******", ClientProfile = profile, Role = "admin" }; string password = "******"; var result = userManager.Create(admin, password); var user1 = new ApplicationUser { Email = "*****@*****.**", UserName = "******", ClientProfile = userProfile1, Role = "user" }; string password1 = "User123"; var result1 = userManager.Create(user1, password1); var user2 = new ApplicationUser { Email = "*****@*****.**", UserName = "******", ClientProfile = userProfile2, Role = "user" }; string password2 = "User123"; var result2 = userManager.Create(user2, password2); // если создание пользователя прошло успешно if (result.Succeeded) { // добавляем для пользователя роль userManager.AddToRole(admin.Id, role1.Name); } if (result1.Succeeded) { // добавляем для пользователя роль userManager.AddToRole(user1.Id, role2.Name); } if (result2.Succeeded) { // добавляем для пользователя роль userManager.AddToRole(user2.Id, role2.Name); } base.Seed(db); }