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_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);
        }
Exemple #3
0
        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);
        }