Ejemplo n.º 1
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_CreatedCurrencies()
        {
            Currency queriedCurrency1, queriedCurrency2;
            IEnumerable <Currency> queriedCurrencies;

            using (var dataLayer = DataLayerHelper.CreateDataLayer())
                using (var controller = new CurrenciesController(dataLayer))
                {
                    queriedCurrency1  = controller.CreateCurrency(TestDataProvider.CreateNewCurrency());
                    queriedCurrency2  = controller.CreateCurrency(TestDataProvider.CreateAnotherNewCurrency());
                    queriedCurrencies = controller.List();
                }

            AssertCurrenciesInList(queriedCurrencies, queriedCurrency1, queriedCurrency2);
        }
Ejemplo n.º 3
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.");
        }
Ejemplo n.º 4
0
        public void Update_Normally_ShouldWork()
        {
            Category       category2;
            Transfer       createdTransfer, updatedTransfer;
            TransferUpdate transferUpdate;

            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 category1 = categoriesController.CreateCategory(TestDataProvider.CreateNewCategory());
                                var partner   = partnersController.CreatePartner(TestDataProvider.CreateNewPartner());
                                var currency  = currenciesController.CreateCurrency(TestDataProvider.CreateAnotherNewCurrency());

                                category2 = categoriesController.CreateCategory(TestDataProvider.CreateAnotherNewCategory());

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

                                transferUpdate = TestDataProvider.CreateTransferUpdate(
                                    createdTransfer.Id,
                                    category2.Id,
                                    partner.Id,
                                    currency.Id,
                                    TestDataProvider.CreateTransferItemUpdate(createdTransfer.Items[0].Id));
                                transfersController.Update(transferUpdate);
                                updatedTransfer = transfersController.Get(createdTransfer.Id);
                            }

            // Note that EF Core behaves slightly differently when an in-memory database is used, these checks are not
            // necessarily enough. Use "curl" or something similar, preferably a REST test-client to make sure
            // everything works as expected.
            Assert.IsTrue(
                updatedTransfer.Category.IsEqualTo(category2),
                $"Unexpected category. Expected: ${category2}. Actual: ${updatedTransfer.Category}.");
            Assert.IsTrue(
                updatedTransfer.Currency.IsEqualTo(createdTransfer.Currency),
                $"Unexpected currency. Expected: ${createdTransfer.Currency}. Actual: ${updatedTransfer.Currency}.");
            Assert.AreEqual(transferUpdate.Discount, updatedTransfer.Discount, "Unexpected discount.");
            Assert.AreEqual(
                transferUpdate.Items.Length,
                updatedTransfer.Items.Length,
                "Unexpected transfer item count.");
            Assert.AreEqual(
                transferUpdate.Items[0].Discount,
                updatedTransfer.Items[0].Discount,
                "Unexpected item discount.");
            Assert.AreEqual(
                createdTransfer.Items[0].Id,
                updatedTransfer.Items[0].Id,
                "Unexpected item ID");
            Assert.AreEqual(transferUpdate.Items[0].Name, updatedTransfer.Items[0].Name, "Unexpected item name.");
            Assert.AreEqual(transferUpdate.Items[0].Price, updatedTransfer.Items[0].Price, "Unexpected item price.");
            Assert.AreEqual(transferUpdate.Note, updatedTransfer.Note, "Unexpected note.");
            Assert.IsTrue(
                updatedTransfer.Partner.IsEqualTo(createdTransfer.Partner),
                $"Unexpected partner. Expected: ${createdTransfer.Partner}. Actual: ${updatedTransfer.Partner}.");
            Assert.AreEqual(transferUpdate.Time, updatedTransfer.Time, "Unexpected time.");
            Assert.AreEqual(transferUpdate.Title, updatedTransfer.Title, "Unexpected title.");
        }