public void BankAccount_Should_GetAccount_By_Id() { //Arrange var effortContext = new BankSystemContext(Effort.DbConnectionFactory.CreateTransient()); var mapperMock = new Mock <IMapper>(); var user = new ApplicationUser() { PasswordHash = "1234", PhoneNumber = "12455", FirstName = "asdfgh", LastName = "lastName", UserName = "******", Email = "*****@*****.**" }; effortContext.Users.Add(user); var bank = new BankAccountAddAspModel() { BankAccountType = (BankAccountType)1, Amount = 12345, Currency = (Currency)973, OwnerId = user.Id, IsDeleted = false }; var bankMock = new BankAccount() { BankAccountType = (BankAccountType)1, Amount = 12345, Currency = (Currency)973, OwnerId = user.Id, IsDeleted = false }; var bankReadModel = new BankAccountReadModel() { BankAccountType = (BankAccountType)1, Amount = 12345, Currency = (Currency)973, OwnerId = user.Id, IsDeleted = false }; mapperMock.Setup(x => x.Map <BankAccount>(It.IsAny <BankAccountAddAspModel>())) .Returns(bankMock); mapperMock.Setup(x => x.Map <BankAccountReadModel>(It.IsAny <BankAccount>())) .Returns(bankReadModel); var sut = new BankAccountServices(effortContext, mapperMock.Object); sut.AddBankAccount(bank); //Act var result = sut.GetBankAccountByID(bankMock.Id.ToString()); Assert.IsInstanceOfType(result, typeof(BankAccountReadModel)); Assert.IsTrue(result.OwnerId == bankMock.OwnerId); }
public void AddBankAccount(BankAccountAddAspModel bankAccount) { if (bankAccount == null) { throw new ArgumentNullException("the bankAccount you wish to add to the database is null, fix it now or cry latter"); } var bankAccAdd = this.mapper.Map <BankAccount>(bankAccount); this.dbContext.BankAccounts.Add(bankAccAdd); this.dbContext.SaveChanges(); }
public void BankAccountAddService_should_Add_ToDataBase_When_ToldTo() {// Tva ne e na Sashko , ne e i na Sashka //Arrange var effortContext = new BankSystemContext(Effort.DbConnectionFactory.CreateTransient()); var mapperMock = new Mock <IMapper>(); var user = new ApplicationUser() { PasswordHash = "1234", PhoneNumber = "12455", FirstName = "asdfgh", LastName = "lastName", UserName = "******", Email = "*****@*****.**" }; effortContext.Users.Add(user); var bank = new BankAccountAddAspModel() { // Id=1, BankAccountType = (BankAccountType)1, Amount = 12345, Currency = (Currency)973, OwnerId = user.Id, IsDeleted = false }; var bankMock = new BankAccount() { // Id = 1, BankAccountType = (BankAccountType)1, Amount = 12345, Currency = (Currency)973, OwnerId = user.Id, IsDeleted = false }; mapperMock.Setup(x => x.Map <BankAccount>(It.IsAny <BankAccountAddAspModel>())) .Returns(bankMock); //Act var sut = new BankAccountServices(effortContext, mapperMock.Object); sut.AddBankAccount(bank); // Assert Assert.AreEqual(1, effortContext.BankAccounts.Count()); }
public ActionResult AddBankAccount(BankAccountAddAspModel model) {//[Bind(Include = "BankAccountType,Amount,Currency,Owner,IsDeleted")] var user = new BankAccountAddAspModel { BankAccountType = model.BankAccountType, Amount = model.Amount, Currency = model.Currency, OwnerId = model.OwnerId, IsDeleted = model.IsDeleted }; //if (ModelState.IsValid) //{ // var user = new BankAccount { BankAccountType=model.BankAccountType,Amount=model.Amount,Currency=model.Currency,Owner=model.Owner,IsDeleted=model.IsDeleted }; //UserName = model.Email, Email = model.Email, FirstName = model.FirstName, LastName = model.LastName //var result = await UserManager.CreateAsync(user, model.Password); if (ModelState.IsValid) { bankAccountService.AddBankAccount(user); //db.PersonalDetails.Add(personalDetail); //db.SaveChanges(); return(RedirectToAction("Index")); } return(View()); //if (result.Succeeded) // { // await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false); // // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771 // // Send an email with this link // // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); // // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); // // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); // return RedirectToAction("Index", "Home"); // } //ModelState.AddModelError("Email", "Email not found or matched"); //return View(model); }