コード例 #1
0
ファイル: SetCategoryTest.cs プロジェクト: 13ogdan/MoneyLeak
        public async Task Should_ChangeCategory()
        {
            //Act
            _payment.Category = new Category
            {
                Name = "OldCategory"
            };
            _context.Update(_payment);
            _context.SaveChanges();

            var category = new Category
            {
                Name = "NewCategory"
            };
            var setCategoryCommand = new SetCategoryCommand
            {
                Payment  = _payment,
                Category = category
            };

            //Act
            await _setCategoryHandler.Handle(setCategoryCommand, CancellationToken.None);

            //Assert
            var paymentInDB = _context.Payments.Find(_payment.Id);

            Assert.IsNotNull(paymentInDB.Category);
            Assert.AreEqual(category.Name, paymentInDB.Category.Name);

            var categoryInDB = _context.Categories.FirstOrDefault(c => category.Name == c.Name);

            Assert.IsNotNull(categoryInDB);
        }
コード例 #2
0
ファイル: SetCategoryTest.cs プロジェクト: 13ogdan/MoneyLeak
        public async Task Should_SetCategoryToAllPaymentsWithTheSameDetails()
        {
            var newCategoryName = "NewCategory";
            var category        = new Category
            {
                Name = newCategoryName
            };
            var setCategoryCommand = new SetCategoryCommand
            {
                Payment  = _payment,
                Category = category,
                ApplyToAllWithSuchDetails = true
            };

            //Act
            await _setCategoryHandler.Handle(setCategoryCommand, CancellationToken.None);

            //Assert
            var samePaymentDetailsCount = _context.Payments.Count(payment => payment.Details == _payment.Details);
            var countOfAddedCategories  = _context.Payments.Count(payment => newCategoryName == payment.Category.Name);

            Assert.AreEqual(samePaymentDetailsCount, countOfAddedCategories);
            Assert.AreEqual(2, countOfAddedCategories);
        }