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); }
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); }
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()}."); }
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 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); }
public void Get_Normally_ShouldReturn_CurrencyWithId() { Currency createdCurrency, queriedCurrency; using (var dataLayer = DataLayerHelper.CreateDataLayer()) using (var controller = new CurrenciesController(dataLayer)) { createdCurrency = controller.CreateCurrency(TestDataProvider.CreateNewCurrency()); queriedCurrency = controller.Get(createdCurrency.Id); } Assert.IsTrue( queriedCurrency.IsEqualTo(createdCurrency), "The two currencies should be equal. " + $"Expected: {createdCurrency.Stringify()}, actual: {queriedCurrency.Stringify()}."); }
public void Delete_Normally_ShouldWork() { Currency createdCurrency, queriedCurrency; IEnumerable <Currency> listedCurrencies; using (var dataLayer = DataLayerHelper.CreateDataLayer()) using (var controller = new CurrenciesController(dataLayer)) { createdCurrency = controller.CreateCurrency(TestDataProvider.CreateNewCurrency()); queriedCurrency = controller.Get(createdCurrency.Id); controller.Delete(createdCurrency.Id); listedCurrencies = controller.List(); } Assert.AreEqual(createdCurrency.Id, queriedCurrency.Id, "Unexpected ID."); Assert.AreEqual(false, listedCurrencies.Any(), "There should be no partners returned."); }
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."); }
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."); }