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 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 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 static Transfer CreateTransfer(this TransfersController controller, NewTransfer newTransfer) { var actionResult = (CreatedAtActionResult)controller.Create(newTransfer); return((Transfer)actionResult.Value); }
public void Create_WhenParamNull_ShouldThrow() { using (var dataLayer = DataLayerHelper.CreateDataLayer()) using (var controller = new TransfersController(dataLayer)) controller.Create(null); }