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}\"."); }
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 Create_WhenRecordExists_ShouldThrow() { using (var dataLayer = DataLayerHelper.CreateDataLayer()) using (var controller = new PartnersController(dataLayer)) { var newPartner = TestDataProvider.CreateNewPartner(); controller.Create(newPartner); controller.Create(newPartner); } }
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); }
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()}."); }
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); }
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."); }
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."); }