public void ShouldModifyModel() { // Arrange Guid expectedId = Guid.NewGuid(); Guid expectedHouseholdId = Guid.NewGuid(); Guid expectedExpenseTypeId = Guid.NewGuid(); string expectedName = "ModifiedName"; string expectedDescription = "ModifiedDescription"; decimal expectedAmount = 0.12m; DateTime expectedDate = DateTime.Now.AddDays(1); DateTime expectedStart = DateTime.Now.AddDays(1); DateTime expectedEnd = DateTime.Now.AddYears(2); Period expectedPeriod = Period.Create(expectedStart, expectedEnd); Expense actual = Expense.Create(expectedId, expectedHouseholdId, Guid.NewGuid(), "Name", "Description", 100.12M, DateTime.Now, Period.Create(DateTime.Now, DateTime.Now)); // Act actual.Modify(expectedExpenseTypeId, expectedName, expectedDescription, expectedAmount, expectedDate, Period.Create(expectedStart, expectedEnd), 1); // Assert Assert.IsTrue(actual.Id == expectedId); Assert.IsTrue(actual.Name == expectedName); Assert.IsTrue(actual.Description == expectedDescription); Assert.IsTrue(actual.Date == expectedDate); Assert.IsTrue(actual.Amount == expectedAmount); Assert.IsTrue(actual.ExpenseTypeId == expectedExpenseTypeId); Assert.IsTrue(actual.Period != null); Assert.IsTrue(actual.Period.PeriodStart == expectedStart); Assert.IsTrue(actual.Period.PeriodEnd == expectedEnd); Assert.IsTrue(!string.IsNullOrEmpty(actual.SearchValue)); }
public void ShouldHaveDeletedEvent() { // Arrange Guid expectedId = Guid.NewGuid(); Expense actual = Expense.Create(expectedId, Guid.NewGuid(), Guid.NewGuid(), "Name", "Description", 100.12M, DateTime.Now, Period.Create(DateTime.Now, DateTime.Now)); actual.FlushUncommitedEvents(); // Act actual.Delete(); // Assert Assert.IsTrue(actual.Events != null); Assert.IsTrue(actual.Events.Count == 1); var events = actual.FlushUncommitedEvents(); Assert.IsTrue(events != null); Assert.IsTrue(events.Length == 1); Assert.IsTrue(events[0] is ExpenseDeletedEvent); ExpenseDeletedEvent @event = events[0] as ExpenseDeletedEvent; Assert.IsTrue(@event.EntityId == expectedId); }
public void ShouldCreateNewModel() { // Arrange Guid expectedId = Guid.NewGuid(); Guid expectedHouseholdId = Guid.NewGuid(); Guid expectedExpenseTypeId = Guid.NewGuid(); string expectedName = "Name"; string expectedDescription = "Description"; decimal expectedAmount = 102.12m; DateTime expectedDate = DateTime.Now; DateTime expectedStart = DateTime.Now; DateTime expectedEnd = DateTime.Now.AddYears(1); Period expectedPeriod = Period.Create(expectedStart, expectedEnd); // Act Expense actual = Expense.Create(expectedId, expectedHouseholdId, expectedExpenseTypeId, expectedName, expectedDescription, expectedAmount, expectedDate, expectedPeriod); // Assert Assert.IsTrue(actual != null); Assert.IsTrue(actual.Id == expectedId); Assert.IsTrue(actual.HouseholdId == expectedHouseholdId); Assert.IsTrue(actual.ExpenseTypeId == expectedExpenseTypeId); Assert.IsTrue(actual.Name == expectedName); Assert.IsTrue(actual.Description == expectedDescription); Assert.IsTrue(actual.Amount == expectedAmount); Assert.IsTrue(actual.Date == expectedDate); Assert.IsTrue(actual.Period != null); Assert.IsTrue(actual.Period.Equals(expectedPeriod)); Assert.IsTrue(!string.IsNullOrEmpty(actual.SearchValue)); }
private void AddExpenseBtn_Click(object sender, EventArgs e) { string expenseTitle = ExpenseTitleTbx.Text; string expenseNotes = ExpenseNotesRtbx.Text; decimal expensePrice = ExpensePriceNum.Value; int expenseQuantity = Convert.ToInt32(ExpenseQuantityNum.Value); if (string.IsNullOrEmpty(ExpenseTitleTbx.Text)) { throw new ApplicationException("Please, specify a title."); } if (expensePrice <= 0) { throw new ApplicationException("Please, specify a positive price."); } Expense expense = Expense.Create(expenseTitle, expensePrice, expenseQuantity, string.IsNullOrWhiteSpace(expenseNotes) ? null : expenseNotes); // Share expeses with all users by default foreach (User user in User.Enumerate()) { if (user != Server.CurrentSession.Info) { expense.AddParticipant(user.Id); } } AddExpenseToUI(expense); }
public async Task HandleAsync(CreateExpenseCommand message, CancellationToken token = default(CancellationToken)) { var expense = Expense.Create(message.ExpenseId, message.HouseholdId, message.ExpenseTypeId, message.Name, message.Description, message.Amount, message.Date, Period.Create(message.PeriodStart, message.PeriodEnd)); _expenses.Add(expense); await _expenses.SaveChangesAsync(token); }
public void CreateExpenseWithExpenseValueAndDescription() { Expense aDinner = Expense.Create("Food"); Assert.Equal("Food", aDinner.Type); Assert.Equal(50.00, aDinner.Value); Assert.Equal("Cena con fernanda", aDinner.Description); }
public async Task <Expense> Find(int id) { var entity = await _context.Expenses.AsNoTracking().FirstOrDefaultAsync(x => x.Id == id); if (entity == null) { return(null); } var expense = Expense.Create(entity.Amount, entity.CategoryId); expense.Id = entity.Id; return(expense); }
public void ShouldHaveModifiedEvent() { // Arrange Guid expectedId = Guid.NewGuid(); Guid expectedExpenseTypeId = Guid.NewGuid(); string expectedName = "ModifiedName"; string expectedDescription = "ModifiedDescription"; decimal expectedAmount = 0.12m; DateTime expectedDate = DateTime.Now.AddDays(1); DateTime expectedStart = DateTime.Now.AddDays(1); DateTime expectedEnd = DateTime.Now.AddYears(2); Expense actual = Expense.Create(expectedId, Guid.NewGuid(), Guid.NewGuid(), "Name", "Description", 100.12M, DateTime.Now, Period.Create(DateTime.Now, DateTime.Now)); actual.FlushUncommitedEvents(); // Act actual.Modify(expectedExpenseTypeId, expectedName, expectedDescription, expectedAmount, expectedDate, Period.Create(expectedStart, expectedEnd), 1); // Assert Assert.IsTrue(actual.Events != null); Assert.IsTrue(actual.Events.Count == 1); var events = actual.FlushUncommitedEvents(); Assert.IsTrue(events != null); Assert.IsTrue(events.Length == 1); Assert.IsTrue(events[0] is ExpenseModifiedEvent); ExpenseModifiedEvent @event = events[0] as ExpenseModifiedEvent; Assert.IsTrue(@event.EntityId == expectedId); Assert.IsTrue(@event.ExpenseTypeId == expectedExpenseTypeId); Assert.IsTrue(@event.Amount == expectedAmount); Assert.IsTrue(@event.Description == expectedDescription); Assert.IsTrue(@event.Name == expectedName); Assert.IsTrue(@event.Date == expectedDate); Assert.IsTrue(@event.PeriodStart == expectedStart); Assert.IsTrue(@event.PeriodEnd == expectedEnd); }
private void AddExpenseBtn_Click(object sender, EventArgs e) { if (String.IsNullOrEmpty(ExpenseTitleTbx.Text)) { MessageBox.Show("Please enter expense title"); return; } string expenseTitle = ExpenseTitleTbx.Text; string expenseNotes = ExpenseNotesRtbx.Text; decimal expensePrice = 0; int expenseQuantity = 1; try { expensePrice = ExpensePriceNum.Value; expenseQuantity = Convert.ToInt32(ExpenseQuantityNum.Value); } catch (Exception) { MessageBox.Show("Please enter a correct number"); return; } Expense expense = Expense.Create(expenseTitle, expensePrice, expenseQuantity, expenseNotes); // Share expeses with all users by default foreach (User user in User.Enumerate()) { if (user != Server.CurrentSession.Info) { expense.AddParticipant(user.Id); } } CalculateAndPopulateExpenses(); MessageBox.Show("You successfully created the expense!"); }
public void ShouldHaveCreatedEvent() { // Arrange Guid expectedId = Guid.NewGuid(); Guid expectedHouseholdId = Guid.NewGuid(); Guid expectedExpenseTypeId = Guid.NewGuid(); string expectedName = "Name"; string expectedDescription = "Description"; decimal expectedAmount = 102.12m; DateTime expectedDate = DateTime.Now; DateTime expectedStart = DateTime.Now; DateTime expectedEnd = DateTime.Now.AddYears(1); Period expectedPeriod = Period.Create(expectedStart, expectedEnd); // Act Expense actual = Expense.Create(expectedId, expectedHouseholdId, expectedExpenseTypeId, expectedName, expectedDescription, expectedAmount, expectedDate, expectedPeriod); // Assert Assert.IsTrue(actual != null); Assert.IsTrue(actual.Events != null); Assert.IsTrue(actual.Events.Count == 1); var events = actual.FlushUncommitedEvents(); Assert.IsTrue(events != null); Assert.IsTrue(events.Length == 1); Assert.IsTrue(events[0] is ExpenseCreatedEvent); ExpenseCreatedEvent @event = events[0] as ExpenseCreatedEvent; Assert.IsTrue(@event.EntityId == expectedId); Assert.IsTrue(@event.HouseholdId == expectedHouseholdId); Assert.IsTrue(@event.ExpenseTypeId == expectedExpenseTypeId); Assert.IsTrue(@event.Description == expectedDescription); Assert.IsTrue(@event.Name == expectedName); Assert.IsTrue(@event.Date == expectedDate); Assert.IsTrue(@event.PeriodStart == expectedStart); Assert.IsTrue(@event.PeriodEnd == expectedEnd); }
public async Task <ResultOrError <ExpenseModel> > Handle(AddExpenseParameters input) { if (!await _context.DoesExist <User>(input.UserId)) { return(CommonErrors.UserNotExist); } if (input.ExpenseTypeId.HasValue && !await _context.DoesExist <ExpenseType>(input.ExpenseTypeId.Value)) { return(ExpenseTypeNotExist); } Expense newExpense; var aggregateId = input.AggregateId; if (aggregateId.HasValue) { if (!await _context.ExpensesAggregates.AnyAsync(x => x.Id == input.AggregateId.Value)) { return(CommonErrors.ExpenseAggregateNotFound); } } else { var aggregate = ExpensesAggregate.Create(input.UserId, input.Name, input.AddedDate, isDraft: false); await _context.ExpensesAggregates.AddAsync(aggregate); aggregateId = aggregate.Id; } newExpense = Expense.Create(input.Name, input.Amount, aggregateId.Value, input.ExpenseTypeId); await _context.Expenses.AddAsync(newExpense); await _context.SaveChangesAsync(); return(newExpense.ToModel()); }
public async Task ShouldModifyExisting() { // Arrange Guid expectedId = Guid.NewGuid(); string expectedName = "Modified Name"; Expense entity = Expense.Create(expectedId, Guid.NewGuid(), Guid.NewGuid(), "Name", "Description", 0.12m, DateTime.Now, Period.Create(DateTime.Now, DateTime.Now)); var repository = new Mock <IExpenseRepository>(); repository.Setup( e => e.GetByIdAsync(It.IsAny <Guid>(), It.IsAny <CancellationToken>())).ReturnsAsync(entity); ModifyExpenseCommand cmd = new ModifyExpenseCommand(expectedId, Guid.NewGuid(), expectedName, "Description", 0.12m, DateTime.Now, DateTime.Now, DateTime.Now, 1); ExpenseCommandHandler actual = new ExpenseCommandHandler(repository.Object); // Act await actual.HandleAsync(cmd); // Assert Assert.IsTrue(entity.Id == expectedId); Assert.IsTrue(entity.Name == expectedName); }
public void Handle(CreateExpenseCommand message) { var expense = Expense.Create(message.Comment, message.Amount, message.Date); _ctx.Expenses.Add(expense); }
public void CreateNewExpense() { Expense fuel = Expense.Create(""); Assert.NotNull(fuel); }
public void CreateExpenseWithExpenseType() { Expense fuel = Expense.Create("Car"); Assert.Equal("Car", fuel.Type); }