public async Task Should_ApplyCategoryToAllPayments_With_SameDetailsAndNoCategory() { var details = DbContentBuilder.Details().WithDetails("Details").WithAlias("Alias").Build(); var newCategory = DbContentBuilder.Category().CreateWithRandomData(); //Add payments to check that is taught only needed for (int i = 0; i < 10; i++) { DbContentBuilder.Payment().WithRandomData().Build(); } //Add payments with the same details but already set category for (int i = 0; i < 10; i++) { DbContentBuilder.Payment().WithRandomData().WithDetails(details).WithCategory(new CategoryBuilder().CreateWithRandomData()).Build(); } var paymentsToChange = new List <string>(); for (int i = 0; i < 10; i++) { paymentsToChange.Add(DbContentBuilder.Payment().WithRandomData().WithCategory(null).WithDetails(details).Build().Id); } await _editDetailsHandler.Handle(new EditDetailsRequest { Details = details, NewDefaultCategoryName = newCategory.Name.ToLower() }, CancellationToken.None); var savedDetails = await _context.Payments.Where(payment => payment.Category == newCategory).Select(payment => payment.Id).ToArrayAsync(); Assert.AreEqual(10, savedDetails.Length); CollectionAssert.AreEquivalent(paymentsToChange, savedDetails); }
public async Task Should_ChangeDetailsAlias() { var details = DbContentBuilder.Details().WithDetails("Details").WithAlias("Alias").Build(); details.Alias = "NewAlias"; await _editDetailsHandler.Handle(new EditDetailsRequest { Details = details }, CancellationToken.None); var savedDetails = await _context.Details.FindAsync(details.FullDetails); Assert.AreEqual("NewAlias", savedDetails.Alias); }
public async Task Should_ChangeDetailsCategory_To_NewOne() { var category = DbContentBuilder.Category().CreateWithRandomData(); var details = DbContentBuilder.Details().WithDetails("Details").WithAlias("Alias").WithCategory(category).Build(); await _editDetailsHandler.Handle(new EditDetailsRequest { Details = details, NewDefaultCategoryName = "New category" }, CancellationToken.None); var savedDetails = await _context.Details.FindAsync(details.FullDetails); Assert.IsNotNull(savedDetails.DefaultCategory); Assert.AreEqual("New category", savedDetails.DefaultCategory.Name); }
public async Task Should_ReturnPayments_With_SpecificDetailsAlias() { var d1 = DbContentBuilder.Details().WithDetails("1").WithAlias("Buy beer in dopio").Build(); var d2 = DbContentBuilder.Details().WithDetails("2").WithAlias("Buy coffee in dopio").Build(); var d3 = DbContentBuilder.Details().WithDetails("3").WithAlias("Buy coffee in MC").Build(); DbContentBuilder.Payment().WithDetails(d1).Build(); DbContentBuilder.Payment().WithDetails(d2).Build(); DbContentBuilder.Payment().WithDetails(d3).Build(); var getPaymentsQuery = new GetPaymentsQuery { WithPhraseInDetails = "dopio" }; var result = await _handler.Handle(getPaymentsQuery, CancellationToken.None); var payments = result.ToArray(); Assert.AreEqual(2, payments.Length); }
public async Task Should_ApplyDefaultCategory() { //Arrange var details = DbContentBuilder.Details().CreateWithRandomData(); details.DefaultCategory = DbContentBuilder.Category().CreateWithRandomData(); var payment = new PaymentInfoBuilder().WithRandomData().IsIncome(false).Build(); payment.Details = details.FullDetails; _payments.Add(payment); //Act await _importPayment.Handle(new ImportPaymentsCommand(null), CancellationToken.None); //Assert var savedPayment = await _context.Payments.FindAsync(payment.PaymentId); Assert.AreEqual(savedPayment.Category, details.DefaultCategory); Assert.AreEqual(savedPayment.Details, details); }