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); } }
public void Update_WhenNameNull_ShouldThrow() { var transferUpdate = new TransferUpdate { Id = 1, 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.Update(transferUpdate); }
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."); }
public void Update_WhenNull_ShouldThrow() { using (var dataLayer = DataLayerHelper.CreateDataLayer()) using (var controller = new TransfersController(dataLayer)) controller.Update(null); }