public ActionResult zagrebPost(MyModel1 request) { string ulaznaDatoteka = (string)TempData["Metro"]; // Mapa metro = new Mapa("ZagrebMetro", ulaznaDatoteka); List<Ruta> Lista = new List<Ruta>() { new Ruta(new Kvart("MAKSIMIR"), new Kvart("SIGET"),5), new Ruta(new Kvart("SIGET"),new Kvart("SPANSKO"),4), new Ruta(new Kvart("SPANSKO"),new Kvart("MEDVESCAK"),8), new Ruta(new Kvart("MEDVESCAK"),new Kvart("SPANSKO"), 8), new Ruta(new Kvart("MEDVESCAK"),new Kvart("DUBRAVA"),6), new Ruta(new Kvart("MAKSIMIR"), new Kvart("MEDVESCAK"),5), new Ruta(new Kvart("SPANSKO"),new Kvart("DUBRAVA"), 2), new Ruta(new Kvart("DUBRAVA"),new Kvart("SIGET"),3), new Ruta(new Kvart("MAKSIMIR"),new Kvart("DUBRAVA"),7) }; //List<Ruta> Lista = metro.KonstrukcijaRuta(); List<Ruta> r = new List<Ruta>(); foreach (Ruta ru in Lista) { r.Add(ru); } MyModel1 model = new MyModel1() { stations = new string[] { "" } }; model.stations = request.stations; MyModel2 model2 = new MyModel2() { distance = 0 }; model2.distance = model.DuljinaPuta(r); return View("zagrebPost"); //return Json(model2 ,JsonRequestBehavior.AllowGet); }
public void zagrebPostTest() { //Arange MyModel1 request = new MyModel1() { stations = new string[] { "MAKSIMIR", "DUBRAVA" } }; MyModel2 expected = new MyModel2() { distance = 7 }; zagrebmetroController controller = new zagrebmetroController(); //Act JsonResult result = controller.zagrebPost(request) as JsonResult; string Json = new JavaScriptSerializer().Serialize(result.Data); string expectedJson = new JavaScriptSerializer().Serialize(expected); // Assert Assert.IsNotNull(result); Assert.AreEqual(expectedJson, Json); }
public void DuljinaPutaTest() { //arrange var Lista = new List<Ruta>() { new Ruta(new Kvart("MAKSIMIR"), new Kvart("SIGET"),5), new Ruta(new Kvart("SIGET"),new Kvart("SPANSKO"),4), new Ruta(new Kvart("SPANSKO"),new Kvart("MEDVESCAK"),8), new Ruta(new Kvart("MEDVESCAK"),new Kvart("SPANSKO"), 8), new Ruta(new Kvart("MEDVESCAK"),new Kvart("DUBRAVA"),6), new Ruta(new Kvart("MAKSIMIR"), new Kvart("MEDVESCAK"),5), new Ruta(new Kvart("SPANSKO"),new Kvart("DUBRAVA"), 2), new Ruta(new Kvart("DUBRAVA"),new Kvart("SIGET"),3), new Ruta(new Kvart("MAKSIMIR"),new Kvart("DUBRAVA"),7) }; MyModel1 model1 = new MyModel1() { stations = new string[] { "MAKSIMIR", "SIGET", "SPANSKO" } }; MyModel1 model2 = new MyModel1() { stations = new string[] { "MAKSIMIR", "MEDVESCAK" } }; MyModel1 model3 = new MyModel1() { stations = new string[] { "MAKSIMIR", "MEDVESCAK", "SPANSKO" } }; MyModel1 model4 = new MyModel1() { stations = new string[] { "MAKSIMIR", "DUBRAVA", "SIGET","SPANSKO","MEDVESCAK" } }; MyModel1 model5 = new MyModel1() { stations = new string[] { "MAKSIMIR", "DUBRAVA", "MEDVESCAK" } }; //act int distance1 = model1.DuljinaPuta(Lista); int distance2 = model2.DuljinaPuta(Lista); int distance3 = model3.DuljinaPuta(Lista); int distance4 = model4.DuljinaPuta(Lista); int distance5 = model5.DuljinaPuta(Lista); //assert Assert.AreEqual<int>(9, distance1); //OK Assert.AreEqual<int>(5, distance2); //OK Assert.AreEqual<int>(13, distance3); //OK Assert.AreEqual<int>(22, distance4); //OK Assert.AreEqual<int>(7, distance5); //NO SUCH ROUTE,OK }