public void ShouldCreateMoneyBoxWithCorrectValues() { SetupDB(); Guid userId = new Guid(); databaseContext.Users.Add(new User { Id = userId, FirstName = "test", LastName = "test", Login = "******", Password = "******", CreatedOn = new DateTime(), }); databaseContext.SaveChanges(); MoneyBox moneyBox = new MoneyBox { Id = new Guid(), Title = "Title", Target = 333333, Value = 100, UserId = userId, CreatedOn = DateTime.Now }; databaseContext.MoneyBoxes.Add(moneyBox); var saveMoneyBox = databaseContext.SaveChanges(); Assert.AreEqual(saveMoneyBox, 1); }
public async Task <Response> EditMoneyBox([FromBody] MoneyBox moneyBox, [FromRoute] Guid id) { Guid userId = new Guid(User.FindFirst(ClaimTypes.NameIdentifier).Value); MoneyBox moneyBoxDb = await _context.MoneyBoxes.FirstOrDefaultAsync(mb => mb.Id == id); if (moneyBoxDb == null) { Response.StatusCode = 400; return(new Response(clientError: "MoneyBox with provided ID hasn't been found", statusCode: System.Net.HttpStatusCode.BadRequest)); } if (moneyBoxDb.UserId != userId) { Response.StatusCode = 401; return(new Response(clientError: "Authorization error", statusCode: System.Net.HttpStatusCode.Unauthorized)); } moneyBoxDb.Title = moneyBox.Title; moneyBoxDb.Target = moneyBox.Target; _context.MoneyBoxes.Update(moneyBoxDb); await _context.SaveChangesAsync(); return(new Response(successMessage: "MoneyBox has been changed")); }
public async Task <Response> DeleteMoneyBox([FromRoute] Guid id) { Guid userId = new Guid(User.FindFirst(ClaimTypes.NameIdentifier).Value); MoneyBox moneyBox = await _context.MoneyBoxes.FirstOrDefaultAsync(mb => mb.Id == id); if (moneyBox == null) { Response.StatusCode = 400; return(new Response(clientError: "MoneyBox with provided ID hasn't been found", statusCode: System.Net.HttpStatusCode.BadRequest)); } if (moneyBox.UserId != userId) { Response.StatusCode = 401; return(new Response(clientError: "Authorization error", statusCode: System.Net.HttpStatusCode.Unauthorized)); } moneyBox.Value = (_context.Incomes.Where(i => i.MoneyBoxId == id).Select(i => i.Value).Sum() + _context.Expenses.Where(i => i.MoneyBoxId == id).Select(i => i.Value).Sum()) * (-1); Income income = new Income() { Title = "Usunięcie skarbonki " + moneyBox.Title, Value = moneyBox.Value, CreatedOn = DateTime.Now, CreatedBy = userId }; _context.Incomes.Add(income); _context.MoneyBoxes.Remove(moneyBox); await _context.SaveChangesAsync(); return(new Response(successMessage: "MoneyBox has been deleted")); }
public void Setup() { SetupDB(); Guid userGuidID = new Guid(); MoneyBox GoodMoneyBoxes = new MoneyBox { Title = "MoneyBoxes2132", Value = 123 }; databaseContext.MoneyBoxes.Add(GoodMoneyBoxes); databaseContext.Users.Add(NewUser); databaseContext.SaveChanges(); var userClaimsTypes = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.NameIdentifier, userGuidID.ToString()), }, "mock")); MoneyBoxesControl = new MoneyBoxesController(databaseContext); MoneyBoxesControl.ControllerContext = new ControllerContext() { HttpContext = new DefaultHttpContext() { User = userClaimsTypes } }; }
public static void Main(string[] args) { MoneyBox piggy = new MoneyBox(); piggy.Name = "Piggy"; piggy.Save(25); System.Console.WriteLine("Money box name: " + piggy.Name); System.Console.WriteLine("Money box saved amount: " + piggy.SavedAmount); }
public async Task CreateMoneyBoxes_CorrectData_ReturnSuccesMessage() { MoneyBox GoodMoneyBoxes1 = new MoneyBox { Title = "MoneyBoxes21", Value = 12 }; var MoneyBoxes = await MoneyBoxesControl.AddNewMoneyBox(GoodMoneyBoxes1); Assert.AreEqual("MoneyBoxes has been created!", MoneyBoxes.SuccessMessage); }
public async Task EditMoneyBox_WrongIDMoneyBox_ReturnProperlyMessage() { var testGuidID = new Guid(); MoneyBox MoneyBoxToUpdate = new MoneyBox { Title = "MoneyBox21", Value = 15 }; var MoneyBoxUpdated = await MoneyBoxesControl.EditMoneyBox(MoneyBoxToUpdate, testGuidID); Assert.AreEqual("MoneyBox with provided ID hasn't been found", MoneyBoxUpdated.ClientError); }
public async Task <Response> AddNewMoneyBox([FromBody] MoneyBox moneyBox) { Guid userId = new Guid(User.FindFirst(ClaimTypes.NameIdentifier).Value); moneyBox.UserId = userId; moneyBox.CreatedOn = DateTime.Now; _context.MoneyBoxes.Add(moneyBox); await _context.SaveChangesAsync(); return(new Response(successMessage: "MoneyBoxes has been created!")); }
public async Task EditMoneyBox_CorrectData_ReturnSuccessMessage() { MoneyBox MoneyBoxToUpdate = new MoneyBox { Title = "MoneyBox21", Value = 15 }; List <MoneyBox> MoneyBoxes = await databaseContext.MoneyBoxes.ToListAsync(); var MoneyBoxUpdated = await MoneyBoxesControl.EditMoneyBox(MoneyBoxToUpdate, MoneyBoxes[0].Id); Assert.AreEqual("MoneyBox has been changed", MoneyBoxUpdated.SuccessMessage); }
public async Task CreateMoneyBoxes_MoneyBoxesAddedToDatabase_RetrunTrue() { MoneyBox GoodMoneyBoxes1 = new MoneyBox { Title = "MoneyBoxes21", Value = 12 }; var MoneyBoxes = await MoneyBoxesControl.AddNewMoneyBox(GoodMoneyBoxes1); var MoneyBoxesCount = databaseContext.MoneyBoxes.Count(); Assert.AreEqual(2, MoneyBoxesCount); }
/// <inheritdoc/> public void Save(MoneyBox moneyBox) { if (moneyBox.Id == Guid.Empty) { throw new ArgumentException("Aggregate ID needs to be set."); } var streamName = this.StreamNameFor(moneyBox.Id); var initVer = moneyBox.InitialVersion ?? ExpectedVersion.Any; this.eventStore.AppendEventsToStream(streamName, moneyBox.Changes, initVer); }
public static void Main(string[] args) { var piggy = new MoneyBox(); piggy.name = "Miss Piggy"; System.Console.WriteLine("Money box name: " + piggy.name); System.Console.WriteLine("Money box saved amount: " + piggy.saved_amount); piggy.save(20); System.Console.WriteLine("Money box saved amount: " + piggy.saved_amount); piggy.save(100); System.Console.WriteLine("Money box saved amount: " + piggy.saved_amount); }
static void Main(string[] args) { int option = 0; ISaveMoney account = null; do { Console.WriteLine(); Console.WriteLine("---------------------"); Console.WriteLine("Este es el menú. Por favor elija una opción:"); Console.WriteLine("---------------------"); Console.WriteLine("Para crear tu cuenta: Pulsa 1"); Console.WriteLine("Para ingresar dinero: Pulsa 2"); Console.WriteLine("Para sacar dienro: Pulsa 3"); Console.WriteLine("Para ver tu saldo: Pulsa 4"); Console.WriteLine("Para salir Pulsa 5"); int.TryParse(Console.ReadLine(), out option); switch (option) { case 1: int accountType = 1; Console.WriteLine("De que tipo? 1 Bancaria. 2 Hucha"); int.TryParse(Console.ReadLine(), out accountType); switch (accountType) { case 1: account = new AccountBank(0); break; case 2: account = new MoneyBox(); break; } Console.WriteLine("La cuenta ha sido creada"); break; case 2: if (account != null) { Console.WriteLine("¿Cuanto quieres ingresar?"); decimal.TryParse(Console.ReadLine(), out decimal amount); account.AddMoney(amount); Console.WriteLine("Se ha ingresado el dinero"); } else { Console.WriteLine("No ha creado la cuenta"); } break; case 3: if (account != null) { Console.WriteLine("¿Cuanto quieres sacar?"); decimal.TryParse(Console.ReadLine(), out decimal amountTakeMoney); try { account.TakeMoney(amountTakeMoney); Console.WriteLine("Se ha sacado el dinero"); } catch (Exception) { Console.WriteLine("No se puede sacar tanto dinero"); } } else { Console.WriteLine("No ha creado la cuenta"); } break; case 4: if (account != null) { Console.WriteLine($"{account.GetBalanceWithText()}"); } else { Console.WriteLine("No ha creado la cuenta"); } break; case 5: Console.WriteLine("Hasta pronto!"); break; } } while (option != 5); }
/// <inheritdoc/> public void Add(MoneyBox moneyBox) { var streamName = this.StreamNameFor(moneyBox.Id); this.eventStore.CreateNewStream(streamName, moneyBox.Changes); }
public MoneyBox UpdateMoneyBox(MoneyBox moneyBox) { throw new NotImplementedException(); }