public void TestEditCustomer() { CustomerController cc = new CustomerController(); System.Web.Mvc.ViewResult result = cc.Index(null); Customer c = ((IPagedList <Customer>)result.ViewData.Model).First(); Assert.NotNull(c); System.Web.Mvc.ActionResult customerEdition = cc.Edit(c.CustomerID); //post edited c.Address = "Address dummy"; c.City = "City dummy"; c.CompanyNumber = "23423424"; c.CP = "508000"; c.Email = "*****@*****.**"; c.Fax = "342343434"; c.Name = "Company name dummy"; c.Phone1 = "3423423423"; c.Phone2 = "234234232"; //get System.Web.Mvc.ActionResult resultEditionView = cc.Edit(c.CustomerID); Assert.IsInstanceOf(typeof(System.Web.Mvc.PartialViewResult), resultEditionView); //post System.Web.Mvc.ActionResult resultEdition = cc.Edit(c); Assert.IsInstanceOf(typeof(System.Web.Mvc.PartialViewResult), resultEdition); }
public static bool CheckPermission(System.Web.Mvc.ActionResult actionResult) { // ************************************************** System.Web.Mvc.IT4MVCActionResult oT4MVCActionResult = actionResult as System.Web.Mvc.IT4MVCActionResult; if (oT4MVCActionResult == null) { return(false); } // ************************************************** // ************************************************** string strAreaName = string.Empty; object objAreaName = oT4MVCActionResult.RouteValueDictionary["Area"]; if (objAreaName != null) { strAreaName = objAreaName.ToString().Replace(" ", string.Empty); } // ************************************************** bool blnCheckPermission = CheckPermission(strAreaName, oT4MVCActionResult.Controller, oT4MVCActionResult.Action); return(blnCheckPermission); //return (CheckPermission // (strAreaName, oT4MVCActionResult.Controller, oT4MVCActionResult.Action)); }
public void TestEditProvider() { ProviderController pc = new ProviderController(); System.Web.Mvc.ViewResult result = pc.Index(null); Provider p = ((IPagedList <Provider>)result.ViewData.Model).First(); System.Web.Mvc.ActionResult customerEdition = pc.Edit(p.ProviderID); //post edited p.Address = "Address dummy"; p.City = "City dummy"; p.CompanyNumber = "23423423424"; p.CP = "508000"; p.Email = "*****@*****.**"; p.Fax = "342343434"; p.Name = "Company name dummy"; p.Phone1 = "3423423423"; p.Phone2 = "234234232"; System.Web.Mvc.ActionResult resultEditionView = pc.Edit(p.ProviderID); Assert.IsInstanceOf(typeof(System.Web.Mvc.ViewResult), resultEditionView); System.Web.Mvc.ActionResult resultEdition = pc.Edit(p); Assert.IsInstanceOf(typeof(System.Web.Mvc.RedirectToRouteResult), resultEdition); }
public void TestHomeIndex() { HomeController hc = new HomeController(); System.Web.Mvc.ActionResult result = hc.Index(); Assert.IsInstanceOf(typeof(System.Web.Mvc.ViewResult), result); }
public void TestAddInvoice() { InvoiceController ic = new InvoiceController(); //load first customer by calling DBcontext InvoiceDB db = new InvoiceDB(); Customer c = db.Customers.First(); ((IObjectContextAdapter)db).ObjectContext.Detach(c); //http://stackoverflow.com/questions/4168073/entity-framework-code-first-no-detach-method-on-dbcontext Assert.NotNull(c); Invoice i = new Invoice(); i.CustomerID = c.CustomerID; i.Customer = c; i.AdvancePaymentTax = 10; i.Notes = "Invoice notes"; i.TimeStamp = DateTime.Now; i.DueDate = DateTime.Now.AddDays(90); i.Paid = false; i.Name = "Test invoice"; System.Web.Mvc.ActionResult resultAdd = ic.Create(i); Assert.IsInstanceOf(typeof(System.Web.Mvc.ViewResult), resultAdd); }
public void Execute_a_job() { // Arrange // - Add a job into the test scheduler IScheduler sched = GetTestScheduler(); JobDetail job = new JobDetail("TestJob", "TestGroup", typeof(Quartz.Job.NoOpJob)); sched.AddJob(job, true); // - Setup the mock HTTP Request var request = new Mock <System.Web.HttpRequestBase>(); var context = new Mock <System.Web.HttpContextBase>(); context.SetupGet(x => x.Request).Returns(request.Object); System.Collections.Specialized.NameValueCollection formParameters = new System.Collections.Specialized.NameValueCollection(); // NOTE: adding items to the formParameter collection is possible here request.SetupGet(x => x.Form).Returns(formParameters); // - Create the fake instance repo and the job execution controller QuartzAdmin.web.Models.IInstanceRepository instanceRepo = new Fakes.FakeInstanceRepository(); instanceRepo.Save(GetTestInstance()); QuartzAdmin.web.Controllers.JobExecutionController jec = new QuartzAdmin.web.Controllers.JobExecutionController(instanceRepo); // - Set the fake request for the controller jec.ControllerContext = new System.Web.Mvc.ControllerContext(context.Object, new System.Web.Routing.RouteData(), jec); // Act System.Web.Mvc.ActionResult result = jec.RunNow("MyTestInstance", "TestGroup", "TestJob"); //Assert Assert.IsTrue(result is System.Web.Mvc.ContentResult && ((System.Web.Mvc.ContentResult)result).Content == "Job execution started"); }
public void TestDeleteProvider() { ProviderController pc = new ProviderController(); System.Web.Mvc.ViewResult result = pc.Index(null); Provider c = ((IPagedList <Provider>)result.ViewData.Model).First(); Assert.NotNull(c); //ask deletion action System.Web.Mvc.ActionResult providerAskDeletion = pc.Delete(c.ProviderID); Assert.IsInstanceOf(typeof(System.Web.Mvc.ViewResult), providerAskDeletion); //delete action System.Web.Mvc.ActionResult providerDeletion = pc.DeleteConfirmed(c.ProviderID); Assert.IsInstanceOf(typeof(System.Web.Mvc.RedirectToRouteResult), providerDeletion); }
public void TestDeleteCustomer() { CustomerController cc = new CustomerController(); System.Web.Mvc.ViewResult result = cc.Index(null); Customer c = ((IPagedList <Customer>)result.ViewData.Model).First(); Assert.NotNull(c); //ask deletion action System.Web.Mvc.ActionResult customerAskDeletion = cc.Delete(c.CustomerID); Assert.IsInstanceOf(typeof(System.Web.Mvc.ViewResult), customerAskDeletion); //delete action System.Web.Mvc.ActionResult customerDeletion = cc.DeleteConfirmed(c.CustomerID); Assert.IsInstanceOf(typeof(System.Web.Mvc.RedirectToRouteResult), customerDeletion); }
public void TestDeleteInvoice() { InvoiceController ic = new InvoiceController(); System.Web.Mvc.ViewResult result = ic.Index(null); Invoice i = ((IPagedList <Invoice>)result.ViewData.Model).First(); Assert.NotNull(i); //ask deletion action System.Web.Mvc.ActionResult invoiceAskDeletion = ic.Delete(i.InvoiceID); Assert.IsInstanceOf(typeof(System.Web.Mvc.ViewResult), invoiceAskDeletion); //delete action System.Web.Mvc.ActionResult invoiceDeletion = ic.DeleteConfirmed(i.InvoiceID); Assert.IsInstanceOf(typeof(System.Web.Mvc.RedirectToRouteResult), invoiceDeletion); }
public void TestAddProvider() { ProviderController pc = new ProviderController(); Provider p = new Provider(); p.Address = "Address dummy"; p.City = "City dummy"; p.CompanyNumber = "23423423424"; p.CP = "508000"; p.Email = "*****@*****.**"; p.Fax = "342343434"; p.Name = "Provider name dummy"; p.Phone1 = "3423423423"; p.Phone2 = "234234232"; System.Web.Mvc.ActionResult result = pc.Create(p); Assert.IsInstanceOf(typeof(System.Web.Mvc.RedirectToRouteResult), result); }
public void TestEditInvoice() { InvoiceController ic = new InvoiceController(); System.Web.Mvc.ViewResult result = ic.Index(null); Invoice i = ((IPagedList <Invoice>)result.ViewData.Model).First(); System.Web.Mvc.ActionResult invoiceEdition = ic.Edit(i.InvoiceID); //post edited i.Name = "Change invoice name test"; //get System.Web.Mvc.ActionResult resultEditionView = ic.Edit(i.InvoiceID); Assert.IsInstanceOf(typeof(System.Web.Mvc.ViewResult), resultEditionView); //post System.Web.Mvc.ActionResult resultEdition = ic.Edit(i); Assert.IsInstanceOf(typeof(System.Web.Mvc.RedirectToRouteResult), resultEdition); }
public bool Register() { System.Web.Mvc.FormCollection collection = new System.Web.Mvc.FormCollection(); Task <string> content = this.Request.Content.ReadAsStringAsync(); AccountRegister body = JsonConvert.DeserializeObject <AccountRegister>(content.Result); collection.Add(FormDataKeys.Password.ToString(), body.Password); collection.Add(FormDataKeys.Email.ToString(), body.Email); collection.Add(FormDataKeys.FirstName.ToString(), body.FirstName); collection.Add(FormDataKeys.SecondName.ToString(), body.SecondName); System.Web.Mvc.ActionResult viewResult = (System.Web.Mvc.ActionResult)accountRegisterController.Register(collection); if (viewResult is System.Web.Mvc.ViewResult) { return(false);// same page User already exists } else if (viewResult is System.Web.Mvc.RedirectToRouteResult) { return(true);//direct to next page new user } return(false); }
public void TestAddCustomer() { CustomerController cc = new CustomerController(); Customer c = new Customer(); c.Address = "Address dummy"; c.City = "City dummy"; c.CompanyNumber = "23423423424"; c.CP = "508000"; c.Email = "*****@*****.**"; c.Fax = "342343434"; c.Name = "Company name dummy"; c.Phone1 = "3423423423"; c.Phone2 = "234234232"; c.Notes = "A customer!"; c.ContactPerson = "Mr customer"; System.Web.Mvc.ActionResult result = cc.Create(c); Assert.IsInstanceOf(typeof(System.Web.Mvc.PartialViewResult), result); }
public void Execute_a_job_with_job_data_map() { // Arrange // - Add a job into the test scheduler IScheduler sched = GetTestScheduler(); JobDetail job = new JobDetail("TestJob2", "TestGroup", typeof(Quartz.Job.NoOpJob)); job.JobDataMap.Add("MyParam1", "Initial Data"); sched.AddJob(job, true); // - Setup the mock HTTP Request var request = new Mock <System.Web.HttpRequestBase>(); var context = new Mock <System.Web.HttpContextBase>(); context.SetupGet(x => x.Request).Returns(request.Object); System.Collections.Specialized.NameValueCollection formParameters = new System.Collections.Specialized.NameValueCollection(); formParameters.Add("jdm_MyParam1", "Working on the railroad"); request.SetupGet(x => x.Form).Returns(formParameters); // - Create the fake instance repo and the job execution controller QuartzAdmin.web.Models.IInstanceRepository instanceRepo = new Fakes.FakeInstanceRepository(); instanceRepo.Save(GetTestInstance()); QuartzAdmin.web.Controllers.JobExecutionController jec = new QuartzAdmin.web.Controllers.JobExecutionController(instanceRepo); // - Set the mocked context for the controller jec.ControllerContext = new System.Web.Mvc.ControllerContext(context.Object, new System.Web.Routing.RouteData(), jec); // Act System.Web.Mvc.ActionResult result = jec.RunNow("MyTestInstance", "TestGroup", "TestJob2"); // - Get the triggers of the job Trigger[] trigOfJob = sched.GetTriggersOfJob("TestJob2", "TestGroup"); //Assert Assert.IsTrue(result is System.Web.Mvc.ContentResult && ((System.Web.Mvc.ContentResult)result).Content == "Job execution started"); Assert.IsTrue(trigOfJob.Count() > 0); Assert.AreEqual(trigOfJob[0].JobDataMap["MyParam1"], "Working on the railroad"); }