コード例 #1
0
        public void Create_Normally_ShouldReturn_Partner()
        {
            var newPartner = TestDataProvider.CreateNewPartner();
            CreatedAtActionResult actionResult;
            Partner partner;

            using (var dataLayer = DataLayerHelper.CreateDataLayer())
                using (var controller = new PartnersController(dataLayer))
                {
                    actionResult = (CreatedAtActionResult)controller.Create(newPartner);
                    partner      = (Partner)actionResult.Value;
                }

            Assert.AreEqual(actionResult.ActionName, "Get");
            Assert.IsTrue(
                partner.Id > 0,
                $"Partner ID is expected to greater than 0. Actual: {partner.Id}.");
            Assert.AreEqual(
                newPartner.Name,
                partner.Name,
                $"Invalid partner name. Expected: \"{newPartner.Name}\", actual: \"{partner.Name}\".");
            Assert.AreEqual(
                newPartner.Address,
                partner.Address,
                $"Invalid partner address. Expected: \"{newPartner.Address}\", actual: \"{partner.Address}\".");
        }
コード例 #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 Create_WhenNameNull_ShouldThrow()
 {
     using (var dataLayer = DataLayerHelper.CreateDataLayer())
         using (var controller = new PartnersController(dataLayer))
             controller.Create(new NewPartner {
                 Name = null, Address = null
             });
 }
コード例 #6
0
 public void Create_WhenCodeNull_ShouldThrow()
 {
     using (var dataLayer = DataLayerHelper.CreateDataLayer())
         using (var controller = new CurrenciesController(dataLayer))
             controller.Create(new NewCurrency {
                 Code = null
             });
 }
コード例 #7
0
 public void Create_WhenNameNull_ShouldThrow()
 {
     using (var dataLayer = DataLayerHelper.CreateDataLayer())
         using (var controller = new CategoriesController(dataLayer))
             controller.Create(new NewCategory {
                 Name = null
             });
 }
コード例 #8
0
 public void Update_WhenRecordDoesNotExist_ShouldThrow()
 {
     using (var dataLayer = DataLayerHelper.CreateDataLayer())
         using (var controller = new TransfersController(dataLayer))
         {
             var transferUpdate = TestDataProvider.CreateTransferUpdate(1, 1, 1, 1);
             controller.Update(transferUpdate);
         }
 }
コード例 #9
0
 public void Create_WhenRecordExists_ShouldThrow()
 {
     using (var dataLayer = DataLayerHelper.CreateDataLayer())
         using (var controller = new TransfersController(dataLayer))
         {
             var newTransfer = TestDataProvider.CreateNewTransfer(1, 1, 1, TestDataProvider.CreateNewTransferItem());
             controller.Create(newTransfer);
             controller.Create(newTransfer);
         }
 }
コード例 #10
0
 public void Create_WhenRecordExists_ShouldThrow()
 {
     using (var dataLayer = DataLayerHelper.CreateDataLayer())
         using (var controller = new CategoriesController(dataLayer))
         {
             var newCategory = TestDataProvider.CreateNewCategory();
             controller.Create(newCategory);
             controller.Create(newCategory);
         }
 }
コード例 #11
0
 public void Update_WhenRecordDoesNotExist_ShouldThrow()
 {
     using (var dataLayer = DataLayerHelper.CreateDataLayer())
         using (var controller = new CurrenciesController(dataLayer))
         {
             var currencyUpdate = new CurrencyUpdate {
                 Id = 1, Code = "USD"
             };
             controller.Update(currencyUpdate);
         }
 }
コード例 #12
0
 public void Update_WhenRecordDoesNotExist_ShouldThrow()
 {
     using (var dataLayer = DataLayerHelper.CreateDataLayer())
         using (var controller = new PartnersController(dataLayer))
         {
             var partnerUpdate = new PartnerUpdate {
                 Id = 1, Name = "Nowhere Man", Address = "Nowhere Land"
             };
             controller.Update(partnerUpdate);
         }
 }
コード例 #13
0
 public void Update_WhenRecordDoesNotExist_ShouldThrow()
 {
     using (var dataLayer = DataLayerHelper.CreateDataLayer())
         using (var controller = new CategoriesController(dataLayer))
         {
             var categoryUpdate = new CategoryUpdate {
                 Id = 1, Name = "Cinemae"
             };
             controller.Update(categoryUpdate);
         }
 }
コード例 #14
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);
        }
コード例 #15
0
        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);
        }
コード例 #16
0
        public void List_ShouldReturn_CreatedCategories()
        {
            Category createdCategory1, createdCategory2;
            IEnumerable <Category> queriedCategories;

            using (var dataLayer = DataLayerHelper.CreateDataLayer())
                using (var controller = new CategoriesController(dataLayer))
                {
                    createdCategory1  = controller.CreateCategory(TestDataProvider.CreateNewCategory());
                    createdCategory2  = controller.CreateCategory(TestDataProvider.CreateAnotherNewCategory());
                    queriedCategories = controller.List();
                }

            AssertCategoriesInList(queriedCategories, createdCategory1, createdCategory2);
        }
コード例 #17
0
        public void Update_Normally_ShouldWork()
        {
            Category createdCategory, updatedCategory;

            using (var dataLayer = DataLayerHelper.CreateDataLayer())
                using (var controller = new CategoriesController(dataLayer))
                {
                    createdCategory = controller.CreateCategory(TestDataProvider.CreateNewCategory());
                    controller.Update(new CategoryUpdate {
                        Id = createdCategory.Id, Name = "Cinema"
                    });
                    updatedCategory = controller.Get(createdCategory.Id);
                }

            Assert.AreEqual("Cinema", updatedCategory.Name);
        }
コード例 #18
0
        public void Get_Normally_ShouldReturn_CategoryWithId()
        {
            Category createdCategory, queriedCategory;

            using (var dataLayer = DataLayerHelper.CreateDataLayer())
                using (var controller = new CategoriesController(dataLayer))
                {
                    createdCategory = controller.CreateCategory(TestDataProvider.CreateNewCategory());
                    queriedCategory = controller.Get(createdCategory.Id);
                }

            Assert.IsTrue(
                queriedCategory.IsEqualTo(createdCategory),
                "The two categories should be equal. "
                + $"Expected: {createdCategory.Stringify()}, actual: {queriedCategory.Stringify()}.");
        }
コード例 #19
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()}.");
        }
コード例 #20
0
        public void Update_Normally_ShouldWork()
        {
            Currency createdCurrency, updatedCurrency;

            using (var dataLayer = DataLayerHelper.CreateDataLayer())
                using (var controller = new CurrenciesController(dataLayer))
                {
                    createdCurrency = controller.CreateCurrency(TestDataProvider.CreateNewCurrency());
                    controller.Update(new CurrencyUpdate {
                        Id = createdCurrency.Id, Code = "USD"
                    });
                    updatedCurrency = controller.Get(createdCurrency.Id);
                }

            Assert.AreEqual("USD", updatedCurrency.Code);
        }
コード例 #21
0
        public void Delete_Normally_ShouldWork()
        {
            Category createdCategory, queriedCategory;
            IEnumerable <Category> listedCategories;

            using (var dataLayer = DataLayerHelper.CreateDataLayer())
                using (var controller = new CategoriesController(dataLayer))
                {
                    createdCategory = controller.CreateCategory(TestDataProvider.CreateNewCategory());
                    queriedCategory = controller.Get(createdCategory.Id);
                    controller.Delete(createdCategory.Id);
                    listedCategories = controller.List();
                }

            Assert.AreEqual(createdCategory.Id, queriedCategory.Id, "Unexpected ID.");
            Assert.AreEqual(false, listedCategories.Any(), "There should be no categories returned.");
        }
コード例 #22
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.");
        }
コード例 #23
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);
        }
コード例 #24
0
        public void Create_WhenTitleNull_ShouldThrow()
        {
            var newTransfer = new NewTransfer
            {
                CategoryId = 1,
                PartnerId  = 1,
                CurrencyId = 1,
                Title      = null,
                Time       = DateTime.UtcNow,
                Discount   = 0.3M,
                Note       = null,
                Items      = null,
            };

            using (var dataLayer = DataLayerHelper.CreateDataLayer())
                using (var controller = new TransfersController(dataLayer))
                    controller.Create(newTransfer);
        }
コード例 #25
0
        public void Create_Normally_ShouldReturn_Category()
        {
            var newCategory = TestDataProvider.CreateNewCategory();
            CreatedAtActionResult actionResult;
            Category category;

            using (var dataLayer = DataLayerHelper.CreateDataLayer())
                using (var controller = new CategoriesController(dataLayer))
                {
                    actionResult = (CreatedAtActionResult)controller.Create(newCategory);
                    category     = (Category)actionResult.Value;
                }

            Assert.AreEqual(actionResult.ActionName, "Get");
            Assert.IsTrue(
                category.Id > 0,
                $"Category ID is expected to greater than 0. Actual: {category.Id}.");
            Assert.AreEqual(
                newCategory.Name,
                category.Name,
                $"Invalid category name. Expected: \"{newCategory.Name}\", actual: \"{category.Name}\".");
        }
コード例 #26
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.");
        }
コード例 #27
0
 public void Delete_WhenRecordDoesNotExist_ShouldThrow()
 {
     using (var dataLayer = DataLayerHelper.CreateDataLayer())
         using (var controller = new CategoriesController(dataLayer))
             controller.Delete(1);
 }
コード例 #28
0
 public void Create_WhenParamNull_ShouldThrow()
 {
     using (var dataLayer = DataLayerHelper.CreateDataLayer())
         using (var controller = new CategoriesController(dataLayer))
             controller.Create(null);
 }
コード例 #29
0
 public void Update_WhenNull_ShouldThrow()
 {
     using (var dataLayer = DataLayerHelper.CreateDataLayer())
         using (var controller = new CurrenciesController(dataLayer))
             controller.Update(null);
 }
コード例 #30
0
 public void Get_WhenRecordDoesNotExist_ShouldThrow()
 {
     using (var dataLayer = DataLayerHelper.CreateDataLayer())
         using (var controller = new CurrenciesController(dataLayer))
             controller.Get(0);
 }