private void CheckLine(Subway subway, string lineName, string[] stations) { for (int i = 0; i < stations.Length - 1; i++) { Assert.IsTrue(subway.HasConnection(stations[i], stations[i + 1], lineName)); } }
public async Task<IHttpActionResult> PutSubway(int id, Subway subway) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != subway.id) { return BadRequest(); } db.Entry(subway).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SubwayExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public void AddStationEmpty() { Subway subway = new Subway(); subway.AddStation(" "); Assert.Fail(); }
public override void Run(string[] args = null) { if (args == null || args.Length != 2) { printFailure("Usage: SubwayTester [startStation] [endStation]"); } else { try { SubwayLoader loader = new SubwayLoader(); Subway objectville = loader.loadFromFile("ObjectvilleSubway.txt"); runTest("start/end station", validateStations(objectville, args[0], args[1])); List <Connection> route = objectville.GetDirections(args[0], args[1]); SubwayPrinter printer = new SubwayPrinter(); printer.PrintDirections(route); Console.WriteLine(printer.output); } catch (Exception e) { printFailure("Every"); Console.WriteLine(e.Message); Console.WriteLine(e.StackTrace); } } Console.ReadKey(); }
public void HasStationStringTrue() { Subway subway = new Subway(); const string stationName = "Charing Cross"; subway.AddStation(stationName); Assert.IsTrue(subway.HasStation(stationName)); }
public void HasStationStringFalse() { Subway subway = new Subway(); const string stationName = "Charing Cross"; subway.AddStation(stationName); Assert.IsFalse(subway.HasStation("Bogosity")); }
public void HasConnectionStringNullString() { Subway subway = new Subway(); const string lineName = "Rock Island Line"; const string station1 = "Station 1"; subway.HasConnection(station1, null, lineName); Assert.Fail(); }
public void HasConnectionNullStringString() { Subway subway = new Subway(); const string lineName = "Rock Island Line"; const string station2 = "Station 2"; subway.HasConnection(null, station2, lineName); Assert.Fail(); }
public void AddConnectionsStringNullString() { Subway subway = new Subway(); string station1 = "s1"; subway.AddStation(station1); subway.AddConnection(station1, null, "line"); Assert.Fail(); }
public void AddStationStringDuplicate() { Subway subway = new Subway(); const string stationName = "Charing Cross"; subway.AddStation(stationName); subway.AddStation(stationName); Assert.Fail(); }
public void AddConnectionsNullStringString() { Subway subway = new Subway(); string station2 = "s2"; subway.AddStation(station2); subway.AddConnection(null, station2, "line"); Assert.Fail(); }
public void HasConnectionStringStringNull() { Subway subway = new Subway(); const string station1 = "Station 1"; const string station2 = "Station 2"; subway.HasConnection(station1, station2, null); Assert.Fail(); }
public async Task<IHttpActionResult> GetSubway(int id) { Subway subway = await db.Subways.FindAsync(id); if (subway == null) { return NotFound(); } return Ok(subway); }
public void AddConnectionNoStation2StringStringString() { Subway subway = new Subway(); string station1 = "s1"; string station2 = "s2"; subway.AddStation(station1); subway.AddConnection(station1, station2, "line"); Assert.Fail(); }
private void loadStations(Subway subway, StreamReader reader) { string currentLine = reader.ReadLine(); while (currentLine.Length > 0) { subway.AddStation(currentLine); currentLine = reader.ReadLine(); } }
public void AddStationString() { Subway subway = new Subway(); Assert.AreEqual(0, subway.GetStations().Count); const string stationName = "Charing Cross"; subway.AddStation(stationName); Assert.AreEqual(1, subway.GetStations().Count); Assert.IsTrue(subway.GetStations().Contains(new Station(stationName))); }
private void loadLine(Subway subway, StreamReader reader, string lineName) { string station1Name = reader.ReadLine(); string station2Name = reader.ReadLine(); while ((station2Name != null) && (station2Name.Length > 0)) { subway.AddConnection(lineName, station1Name, station2Name); station1Name = station2Name; station2Name = reader.ReadLine(); } }
public void SubwayLoaderTest() { SubwayLoader subwayLoader = new SubwayLoader(); using (StreamReader streamReader = new StreamReader(@"TestFiles\ObectvilleSubway.txt")) { Subway subway = subwayLoader.Load(streamReader); Assert.AreEqual(stations.Length, subway.GetStations().Count); Assert.IsTrue(subway.GetStations().SequenceEqual(stations)); CheckLine(subway, "Wirfs-Brock Line", wirfsBrockLine); } }
public async Task<IHttpActionResult> PostSubway(Subway subway) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Subways.Add(subway); await db.SaveChangesAsync(); return CreatedAtRoute("DefaultApi", new { id = subway.id }, subway); }
public async Task<IHttpActionResult> DeleteSubway(int id) { Subway subway = await db.Subways.FindAsync(id); if (subway == null) { return NotFound(); } db.Subways.Remove(subway); await db.SaveChangesAsync(); return Ok(subway); }
public void HasConnectionFalseStringStringString() { Subway subway = new Subway(); const string lineName = "Rock Island Line"; const string station1 = "Station 1"; subway.AddStation(station1); const string station2 = "Station 2"; subway.AddStation(station2); subway.AddConnection(station1, station2, lineName); Assert.IsFalse(subway.HasConnection("x", station2, lineName)); }
private static bool LoadJson(string path) { try { string json = File.ReadAllText(path); subwayMap = JsonConvert.DeserializeObject <Subway>(json); } catch (Exception e) { Console.WriteLine("地铁数据读取异常, 请确认数据文件 [{0}] 存在且完整!", path); return(false); } return(true); }
public void AddWorldObjectToWorldServer(StaticWorldObject worldObject) { UInt16 typeId = NumericalUtils.ByteArrayToUint16(worldObject.type, 1); switch (typeId) { case 6568: Subway subway = new Subway(worldObject); Subways.Add(subway); WorldSocket.subways.Add(subway); WorldSocket.gameServerEntities.Add(subway); subway.StartCountdown(); break; } }
public override void Run(string[] args = null) { try { SubwayLoader loader = new SubwayLoader(); Subway objectville = loader.loadFromFile("ObjectvilleSubway.txt"); runTest("station", validateStations(objectville)); runTest("connection", validateConnections(objectville)); } catch (Exception e) { printFailure("All"); Console.WriteLine(e.Message); Console.WriteLine(e.StackTrace); } Console.ReadKey(); }
public void AddConnectionStringStringString() { Subway subway = new Subway(); const string lineName = "Rock Island Line"; const string station1 = "Station 1"; subway.AddStation(station1); const string station2 = "Station 2"; subway.AddStation(station2); Assert.AreEqual(0, subway.GetConnections().Count); subway.AddConnection(station1, station2, lineName); Assert.AreEqual(2, subway.GetConnections().Count); ICollection <Connection> connections = subway.GetConnections(); bool result1 = connections.Contains(new Connection(new Station(station1), new Station(station2), lineName)); bool result2 = connections.Contains(new Connection(new Station(station2), new Station(station1), lineName)); Assert.IsTrue(result1 && result2); }
private bool validateConnections(Subway subway) { return(subway.HasConnection("Meyer Line", "DRY Drive", "Head First Theater") && subway.HasConnection("Wirfs-Brock Line", "Weather-O-Rama, Inc.", "XHTML Expressway") && subway.HasConnection("Rumbaugh Line", "Head First Theater", "Infinite Circle")); }
private bool validateStations(Subway subway) { return(subway.HasStation("DRY Drive") && subway.HasStation("Weather-O-Rama, Inc.") && subway.HasStation("Boards 'R' Us")); }
private static void BuilderTest() { var subway = new Subway(); }
internal static void PopulateDefaultMenuDataUserCtx(DbContext db) { try { var crafterRole = new Role { // Id = 1, Name = "Crafter" }; db.Set <Role>().Add(crafterRole); var userRole = new Role { Id = 2, Name = "User", }; db.Set <Role>().Add(userRole); var andrew = new odec.Server.Model.User.User { // Id = 1, UserName = "******", }; db.Set <odec.Server.Model.User.User>().Add(andrew); var alex = new odec.Server.Model.User.User { // Id = 2, UserName = "******", }; db.Set <odec.Server.Model.User.User>().Add(alex); var male = new Sex { // Id = 1, Name = "Male", Code = "Male", DateCreated = DateTime.Now, IsActive = true, SortOrder = 0 }; db.Set <Sex>().Add(male); db.Set <UserRole>().Add(new UserRole { RoleId = crafterRole.Id, UserId = andrew.Id }); var contact = new Contact { SexId = male.Id, Email = "*****@*****.**", BirthdayDate = DateTime.Today, Code = "*****@*****.**" + DateTime.Now.ToString(), SendNews = true, FirstName = "Alex", LastName = "Pirogov", Patronymic = "Leonidovich", IsActive = true, DateCreated = DateTime.Now, AddressDenormolized = "Litovsky Street 1 flat 512", PhoneNumberDenormolized = "9686698356", Name = "MainAddress", SortOrder = 0 }; db.Set <Contact>().Add(contact); db.Set <UserContact>().Add(new UserContact { UserId = andrew.Id, ContactId = contact.Id }); var russia = new Country { Name = "Russia", Code = "Russia", DateCreated = DateTime.Now, IsActive = true, SortOrder = 0 }; var moscow = new City { Name = "Moscow", Code = "Moscow", Region = "Moscow", DateCreated = DateTime.Now, IsActive = true, SortOrder = 0, Genitive = "Moscow", Prepositional = "Moscow" }; var yasenevo = new Subway { Name = "Yasenevo", Code = "Yasenevo", City = moscow, DateCreated = DateTime.Now, IsActive = true, SortOrder = 0, }; var litovsky = new Street { Name = "Litovsky Bulevard", Code = "LitovskyBulevard", CityId = moscow.Id, DateCreated = DateTime.Now, IsActive = true, SortOrder = 0, }; var houseOne = new House { Name = "1", Code = "ONE", DateCreated = DateTime.Now, IsActive = true, SortOrder = 0, StreetId = litovsky.Id }; var flat512 = new Flat { House = houseOne, Name = "512", Code = "512", DateCreated = DateTime.Now, IsActive = true, SortOrder = 0, }; // var noHousing = new Housing(); var address1 = new Address { Name = "MainAddress", CityId = moscow.Id, CountryId = russia.Id, StreetId = litovsky.Id, FlatId = flat512.Id, House = houseOne, Subway = yasenevo, Code = "MainAddress", IsActive = true, SortOrder = 0, StringRepresentation = String.Empty }; db.Set <Address>().Add(address1); db.Set <ContactAddress>().Add(new ContactAddress { ContactId = contact.Id, AddressId = address1.Id }); db.SaveChanges(); } catch (Exception ex) { throw; } }
public void AddStationNull() { Subway subway = new Subway(); subway.AddStation(null); }