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);
        }
Beispiel #2
0
        public async Task Should_ReturnPayments_By_CombinedFilter()
        {
            var date    = new DateTime(2018, 2, 18);
            var details = "details";

            //One with everything but with category
            DbContentBuilder.Payment().WithDate(date).WithDetails(details).WithCategory(new Category()).Build();
            //One excellent
            DbContentBuilder.Payment().WithDate(date).WithDetails(details).Build();
            //Only date wrong
            DbContentBuilder.Payment().WithDate(date.AddDays(1)).WithDetails(details).Build();
            //Only details wrong
            DbContentBuilder.Payment().WithDate(date).WithDetails(details.Substring(1)).Build();

            DbContentBuilder.Payment().WithCategory(new Category()).Build();
            var getPaymentsQuery = new GetPaymentsQuery
            {
                WithEmptyCategory   = true,
                DateFrom            = date,
                DateTo              = date,
                WithPhraseInDetails = details
            };

            var result = await _handler.Handle(getPaymentsQuery, CancellationToken.None);

            var payments = result.ToArray();

            Assert.AreEqual(1, payments.Length);
        }
Beispiel #3
0
        private void CreateDefaultPayments()
        {
            var paymentBuilder = DbContentBuilder.Payment();

            for (int i = 0; i < _count; i++)
            {
                paymentBuilder.WithRandomData().Build();
            }
        }
Beispiel #4
0
        public async Task Should_ReturnPayments_With_SpecificDetails()
        {
            DbContentBuilder.Payment().WithDetails("Buy beer in dopio").Build();
            DbContentBuilder.Payment().WithDetails("Buy coffee in dopio").Build();
            DbContentBuilder.Payment().WithDetails("Dopio lunch").Build();
            var getPaymentsQuery = new GetPaymentsQuery
            {
                WithPhraseInDetails = "dopio"
            };

            var result = await _handler.Handle(getPaymentsQuery, CancellationToken.None);

            var payments = result.ToArray();

            Assert.AreEqual(3, payments.Length);
        }
Beispiel #5
0
        public async Task Should_ReturnPayments_Without_Category()
        {
            DbContentBuilder.Payment().WithCategory(null).Build();
            DbContentBuilder.Payment().WithCategory(null).Build();
            var getPaymentsQuery = new GetPaymentsQuery
            {
                WithEmptyCategory = true
            };
            var ct = _context.ChangeTracker;

            var result = await _handler.Handle(getPaymentsQuery, CancellationToken.None);

            var payments = result.ToArray();

            var paymentsWithoutCategory = _context.Payments.Where(payment => payment.Category == null).ToArray();

            Assert.AreEqual(paymentsWithoutCategory.Length, payments.Length);
            CollectionAssert.AreEquivalent(paymentsWithoutCategory, payments);
        }
Beispiel #6
0
        public async Task Should_ReturnPayments_For_SpecificDay()
        {
            var date = new DateTime(2018, 2, 18);

            DbContentBuilder.Payment().WithDate(date.AddDays(1)).Build();
            DbContentBuilder.Payment().WithDate(date.AddDays(-1)).Build();
            DbContentBuilder.Payment().WithDate(date).Build();
            DbContentBuilder.Payment().WithDate(date).Build();
            var getPaymentsQuery = new GetPaymentsQuery
            {
                DateFrom = date,
                DateTo   = date
            };

            var result = await _handler.Handle(getPaymentsQuery, CancellationToken.None);

            var payments = result.ToArray();

            Assert.AreEqual(2, payments.Length);
        }
Beispiel #7
0
        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);
        }
Beispiel #8
0
        public async Task Should_ReturnPayments_Before_SpecificDay()
        {
            var date = new DateTime(2018, 2, 18);

            DbContentBuilder.Payment().WithDate(date.AddDays(1)).Build();
            DbContentBuilder.Payment().WithDate(date.AddDays(-1)).Build();
            DbContentBuilder.Payment().WithDate(date).Build();
            DbContentBuilder.Payment().WithDate(date).Build();
            var getPaymentsQuery = new GetPaymentsQuery
            {
                DateTo = date,
            };

            var result = await _handler.Handle(getPaymentsQuery, CancellationToken.None);

            var payments = result.ToArray();

            var paymentsBefore = _context.Payments.Where(payment => payment.Date <= date).ToArray();

            Assert.AreEqual(paymentsBefore.Length, payments.Length);
            CollectionAssert.AreEquivalent(paymentsBefore, payments);
        }