public void Startup() { nav_mock = new Mock <INavigationService>(); nav = nav_mock.Object; toaster_mock = new Mock <IToaster>(); toaster = toaster_mock.Object; item_report_storage = new VolatileItemReportStorage(); }
public async void SubmitItem_ValidItemReport_Async() { Mock <IValidator <ItemReport> > validator_mock = new Mock <IValidator <ItemReport> >(); VolatileItemReportStorage virs = new VolatileItemReportStorage(validator_mock.Object); ItemReport ir = new ItemReport(); await virs.SubmitItem(ir); Assert.AreEqual(ir, virs.LocalItemReports[0]); Assert.AreEqual(1, ir.ID); // sets ID to 1. 0 is invalid }
public async void SubmitItem_InvalidEdit_Async() { Mock <IValidator <ItemReport> > validator_mock = new Mock <IValidator <ItemReport> >(); VolatileItemReportStorage virs = new VolatileItemReportStorage(validator_mock.Object); ItemReport ir = new ItemReport() { ID = 5 }; await Assert.ThrowsExceptionAsync <InvalidOperationException>( () => virs.SubmitItem(ir)); }
public async void SubmitItem_InvalidItemReport_Async() { Mock <IValidator <ItemReport> > validator_mock = new Mock <IValidator <ItemReport> >(); validator_mock.Setup(v => v.BrokenRules(It.IsAny <ItemReport>())) .Throws(new DataInvalidException( new List <string>() { "The item report is invalid" } ) ); VolatileItemReportStorage virs = new VolatileItemReportStorage(validator_mock.Object); await Assert.ThrowsExceptionAsync <DataInvalidException>( () => virs.SubmitItem(new ItemReport())); }
public async void SubmitItem_EditItemReport_Async() { Mock <IValidator <ItemReport> > validator_mock = new Mock <IValidator <ItemReport> >(); VolatileItemReportStorage virs = new VolatileItemReportStorage(validator_mock.Object); ItemReport ir = new ItemReport(); await virs.SubmitItem(ir); Assert.AreEqual(ir, virs.LocalItemReports[0]); Assert.AreEqual(1, ir.ID); // sets ID to 1. 0 is invalid ItemReport edited = new ItemReport() { ID = 1, Title = "new title" }; await virs.SubmitItem(edited); Assert.AreNotEqual(ir, virs.LocalItemReports[0]); Assert.AreEqual(edited, virs.LocalItemReports[0]); Assert.AreEqual("new title", virs.LocalItemReports[0].Title); }