Пример #1
0
        public void Get_Normally_ShouldReturn_TransferWithId()
        {
            CreatedAtActionResult actionResult;
            Transfer createdTransfer, queriedTransfer;

            using (var dataLayer = DataLayerHelper.CreateDataLayer())
                using (var categoriesController = new CategoriesController(dataLayer))
                    using (var currenciesController = new CurrenciesController(dataLayer))
                        using (var partnersController = new PartnersController(dataLayer))
                            using (var transfersController = new TransfersController(dataLayer))
                            {
                                var category = categoriesController.CreateCategory(TestDataProvider.CreateNewCategory());
                                var partner  = partnersController.CreatePartner(TestDataProvider.CreateAnotherNewPartner());
                                var currency = currenciesController.CreateCurrency(TestDataProvider.CreateNewCurrency());

                                var newTransfer = TestDataProvider.CreateNewTransfer(
                                    category.Id,
                                    partner.Id,
                                    currency.Id,
                                    TestDataProvider.CreateNewTransferItem());
                                actionResult    = (CreatedAtActionResult)transfersController.Create(newTransfer);
                                createdTransfer = (Transfer)actionResult.Value;
                                queriedTransfer = transfersController.Get(createdTransfer.Id);
                            }

            Assert.AreEqual(actionResult.ActionName, "Get");
            Assert.IsTrue(
                queriedTransfer.IsEqualTo(createdTransfer),
                "The two transfers should be equal. "
                + $"Expected: {createdTransfer.Stringify()}, actual: {queriedTransfer.Stringify()}.");
        }
Пример #2
0
        public void Delete_Normally_ShouldWork()
        {
            Transfer createdTransfer, queriedTransfer;
            IEnumerable <Transfer> listedTransfers;

            using (var dataLayer = DataLayerHelper.CreateDataLayer())
                using (var categoriesController = new CategoriesController(dataLayer))
                    using (var currenciesController = new CurrenciesController(dataLayer))
                        using (var partnersController = new PartnersController(dataLayer))
                            using (var transfersController = new TransfersController(dataLayer))
                            {
                                var category = categoriesController.CreateCategory(TestDataProvider.CreateNewCategory());
                                var partner  = partnersController.CreatePartner(TestDataProvider.CreateAnotherNewPartner());
                                var currency = currenciesController.CreateCurrency(TestDataProvider.CreateAnotherNewCurrency());

                                var newTransfer = TestDataProvider.CreateNewTransfer(
                                    category.Id,
                                    partner.Id,
                                    currency.Id,
                                    TestDataProvider.CreateNewTransferItem());
                                createdTransfer = transfersController.CreateTransfer(newTransfer);

                                queriedTransfer = transfersController.Get(createdTransfer.Id);
                                transfersController.Delete(createdTransfer.Id);
                                listedTransfers = transfersController.List();
                            }

            Assert.AreEqual(createdTransfer.Id, queriedTransfer.Id, "Unexpected ID.");
            Assert.AreEqual(false, listedTransfers.Any(), "There should be no transfers returned.");
        }
        public void List_ShouldReturn_CreatedPartners()
        {
            Partner createdPartner1, createdPartner2;
            IEnumerable <Partner> queriedPartners;

            using (var dataLayer = DataLayerHelper.CreateDataLayer())
                using (var controller = new PartnersController(dataLayer))
                {
                    createdPartner1 = controller.CreatePartner(TestDataProvider.CreateNewPartner());
                    createdPartner2 = controller.CreatePartner(TestDataProvider.CreateAnotherNewPartner());
                    queriedPartners = controller.List();
                }

            AssertPartnersInList(queriedPartners, createdPartner1, createdPartner2);
        }
Пример #4
0
        public void Create_Normally_ShouldReturn_Transfer()
        {
            NewTransfer newTransfer;
            Transfer    transfer;

            using (var dataLayer = DataLayerHelper.CreateDataLayer())
                using (var categoriesController = new CategoriesController(dataLayer))
                    using (var currenciesController = new CurrenciesController(dataLayer))
                        using (var partnersController = new PartnersController(dataLayer))
                            using (var transfersController = new TransfersController(dataLayer))
                            {
                                var category = categoriesController.CreateCategory(TestDataProvider.CreateNewCategory());
                                var partner  = partnersController.CreatePartner(TestDataProvider.CreateAnotherNewPartner());
                                var currency = currenciesController.CreateCurrency(TestDataProvider.CreateAnotherNewCurrency());

                                newTransfer = TestDataProvider.CreateNewTransfer(
                                    category.Id,
                                    partner.Id,
                                    currency.Id,
                                    TestDataProvider.CreateNewTransferItem());
                                transfer = transfersController.CreateTransfer(newTransfer);
                            }

            Assert.AreEqual(newTransfer.CategoryId, transfer.Category.Id, "Unexpected category.");
            Assert.AreEqual(newTransfer.CurrencyId, transfer.Currency.Id, "Unexpected currency.");
            Assert.AreEqual(newTransfer.Discount, transfer.Discount, "Unexpected discount.");
            Assert.IsTrue(transfer.Id > 0, $"Transfer ID is expected to greater than 0. Actual: {transfer.Id}.");
            Assert.AreEqual(newTransfer.Items.Length, transfer.Items.Length, "Unexpected transfer item count.");
            Assert.AreEqual(newTransfer.Items[0].Discount, transfer.Items[0].Discount, "Unexpected item discount.");
            Assert.IsTrue(
                transfer.Items[0].Id > 0,
                $"Item ID is expected to greater than 0. Actual: {transfer.Items[0].Id}.");
            Assert.AreEqual(newTransfer.Items[0].Name, transfer.Items[0].Name, "Unexpected item name.");
            Assert.AreEqual(newTransfer.Items[0].Price, transfer.Items[0].Price, "Unexpected item price.");
            Assert.AreEqual(newTransfer.Note, transfer.Note, "Unexpected note.");
            Assert.AreEqual(newTransfer.PartnerId, transfer.Partner.Id, "Unexpected partner.");
            Assert.AreEqual(newTransfer.Time, transfer.Time, "Unexpected time.");
            Assert.AreEqual(newTransfer.Title, transfer.Title, "Unexpected title.");
        }