コード例 #1
0
        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);
        }
コード例 #2
0
        public void List_ShouldReturn_CreatedTransfers()
        {
            Transfer createdTransfer1, createdTransfer2;
            IEnumerable <Transfer> queriedTransfers;

            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.CreateNewPartner());
                                var currency = currenciesController.CreateCurrency(TestDataProvider.CreateNewCurrency());

                                var newTransfer1 = TestDataProvider.CreateNewTransfer(
                                    category.Id,
                                    partner.Id,
                                    currency.Id,
                                    TestDataProvider.CreateNewTransferItem());
                                createdTransfer1 = transfersController.CreateTransfer(newTransfer1);
                                var newTransfer2 = TestDataProvider.CreateNewTransfer(
                                    category.Id,
                                    partner.Id,
                                    currency.Id,
                                    TestDataProvider.CreateNewTransferItem());
                                createdTransfer2 = transfersController.CreateTransfer(newTransfer2);
                                queriedTransfers = transfersController.List();
                            }

            AssertTransfersInList(queriedTransfers, createdTransfer1, createdTransfer2);
        }
コード例 #3
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()}.");
        }
コード例 #4
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.");
        }
コード例 #5
0
        public void Get_Normally_ShouldReturn_PartnerWithId()
        {
            Partner createdPartner, queriedPartner;

            using (var dataLayer = DataLayerHelper.CreateDataLayer())
                using (var controller = new PartnersController(dataLayer))
                {
                    createdPartner = controller.CreatePartner(TestDataProvider.CreateNewPartner());
                    queriedPartner = controller.Get(createdPartner.Id);
                }

            Assert.IsTrue(
                queriedPartner.IsEqualTo(createdPartner),
                "The two partners should be equal. "
                + $"Expected: {createdPartner.Stringify()}, actual: {queriedPartner.Stringify()}.");
        }
コード例 #6
0
        public void Update_Normally_ShouldWork()
        {
            Partner createdPartner, updatedPartner;

            using (var dataLayer = DataLayerHelper.CreateDataLayer())
                using (var controller = new PartnersController(dataLayer))
                {
                    createdPartner = controller.CreatePartner(TestDataProvider.CreateNewPartner());
                    controller.Update(new PartnerUpdate {
                        Id = createdPartner.Id, Name = "Eleanor Rigby", Address = "Liverpool"
                    });
                    updatedPartner = controller.Get(createdPartner.Id);
                }

            Assert.AreEqual("Eleanor Rigby", updatedPartner.Name);
            Assert.AreEqual("Liverpool", updatedPartner.Address);
        }
コード例 #7
0
        public void Delete_Normally_ShouldWork()
        {
            Partner createdPartner, queriedPartner;
            IEnumerable <Partner> listedPartners;

            using (var dataLayer = DataLayerHelper.CreateDataLayer())
                using (var controller = new PartnersController(dataLayer))
                {
                    createdPartner = controller.CreatePartner(TestDataProvider.CreateNewPartner());
                    queriedPartner = controller.Get(createdPartner.Id);
                    controller.Delete(createdPartner.Id);
                    listedPartners = controller.List();
                }

            Assert.AreEqual(createdPartner.Id, queriedPartner.Id, "Unexpected ID.");
            Assert.AreEqual(false, listedPartners.Any(), "There should be no partners returned.");
        }
コード例 #8
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.");
        }
コード例 #9
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.");
        }