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 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 Create_WhenNameNull_ShouldThrow() { using (var dataLayer = DataLayerHelper.CreateDataLayer()) using (var controller = new PartnersController(dataLayer)) controller.Create(new NewPartner { Name = null, Address = null }); }
public void Create_WhenCodeNull_ShouldThrow() { using (var dataLayer = DataLayerHelper.CreateDataLayer()) using (var controller = new CurrenciesController(dataLayer)) controller.Create(new NewCurrency { Code = null }); }
public void Create_WhenNameNull_ShouldThrow() { using (var dataLayer = DataLayerHelper.CreateDataLayer()) using (var controller = new CategoriesController(dataLayer)) controller.Create(new NewCategory { Name = null }); }
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 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); } }
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); } }
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); } }
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); } }
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); } }
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 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_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); }
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); }
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()}."); }
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() { 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 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."); }
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() { 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 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); }
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}\"."); }
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 Delete_WhenRecordDoesNotExist_ShouldThrow() { using (var dataLayer = DataLayerHelper.CreateDataLayer()) using (var controller = new CategoriesController(dataLayer)) controller.Delete(1); }
public void Create_WhenParamNull_ShouldThrow() { using (var dataLayer = DataLayerHelper.CreateDataLayer()) using (var controller = new CategoriesController(dataLayer)) controller.Create(null); }
public void Update_WhenNull_ShouldThrow() { using (var dataLayer = DataLayerHelper.CreateDataLayer()) using (var controller = new CurrenciesController(dataLayer)) controller.Update(null); }
public void Get_WhenRecordDoesNotExist_ShouldThrow() { using (var dataLayer = DataLayerHelper.CreateDataLayer()) using (var controller = new CurrenciesController(dataLayer)) controller.Get(0); }