-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed issue #35: Agency_id is required if multiple agencies in agency…
….txt
- Loading branch information
Ranko Orlic
committed
Feb 16, 2016
1 parent
02be44b
commit 8480192
Showing
8 changed files
with
184 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
// The MIT License (MIT) | ||
|
||
// Copyright (c) 2014 Ben Abelshausen | ||
|
||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
|
||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
|
||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
using GTFS.IO; | ||
using GTFS.IO.CSV; | ||
using NUnit.Framework; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
using GTFS.Exceptions; | ||
|
||
namespace GTFS.Test | ||
{ | ||
/// <summary> | ||
/// Contains additional parsing tests for agencies. | ||
/// </summary> | ||
[TestFixture] | ||
public class ParseAgenciesTests | ||
{ | ||
private static Assembly _executingAssembly; | ||
|
||
/// <summary> | ||
/// Setup the test environment. | ||
/// </summary> | ||
[OneTimeSetUp] | ||
public static void Setup() | ||
{ | ||
_executingAssembly = Assembly.GetExecutingAssembly(); | ||
} | ||
|
||
/// <summary> | ||
/// Tests parsing single agency without agency_id. | ||
/// </summary> | ||
[Test] | ||
public void ParseSingleAgencyWithoutAgencyId() | ||
{ | ||
var reader = new GTFSReader<GTFSFeed>(); | ||
var source = new List<IGTFSSourceFile> | ||
{ | ||
new GTFSSourceFileStream(_executingAssembly.GetManifestResourceStream("GTFS.Test.other_feed.agency_no_id.txt"),"agency") | ||
}; | ||
|
||
|
||
var feed = reader.Read(source, source.First(x => x.Name.Equals("agency"))); | ||
|
||
|
||
var agencies = feed.Agencies; | ||
Assert.IsNotNull(agencies); | ||
|
||
var agency = agencies.SingleOrDefault(); | ||
Assert.IsNotNull(agency); | ||
Assert.IsNull(agency.Id); | ||
} | ||
|
||
/// <summary> | ||
/// Tests parsing single agency with agency_id. | ||
/// </summary> | ||
[Test] | ||
public void ParseSingleAgencyWithAgencyId() | ||
{ | ||
var reader = new GTFSReader<GTFSFeed>(); | ||
var source = new List<IGTFSSourceFile> | ||
{ | ||
new GTFSSourceFileStream(_executingAssembly.GetManifestResourceStream("GTFS.Test.other_feed.agency_with_id.txt"),"agency") | ||
}; | ||
|
||
|
||
var feed = reader.Read(source, source.First(x => x.Name.Equals("agency"))); | ||
|
||
|
||
var agencies = feed.Agencies; | ||
Assert.IsNotNull(agencies); | ||
|
||
var agency = agencies.SingleOrDefault(); | ||
Assert.IsNotNull(agency); | ||
Assert.IsNotNull(agency.Id); | ||
} | ||
|
||
/// <summary> | ||
/// Tests parsing multiple agencies with agency_id. | ||
/// </summary> | ||
[Test] | ||
public void ParseAgenciesWithAgencyId() | ||
{ | ||
var reader = new GTFSReader<GTFSFeed>(); | ||
var source = new List<IGTFSSourceFile> | ||
{ | ||
new GTFSSourceFileStream(_executingAssembly.GetManifestResourceStream("GTFS.Test.other_feed.agencies_with_id.txt"),"agency") | ||
}; | ||
|
||
|
||
var feed = reader.Read(source, source.First(x => x.Name.Equals("agency"))); | ||
|
||
|
||
var agencies = feed.Agencies; | ||
Assert.IsNotNull(agencies); | ||
Assert.IsNotNull(agencies.SingleOrDefault(x => x.Id == "DTA")); | ||
Assert.IsNotNull(agencies.SingleOrDefault(x => x.Id == "OTA")); | ||
} | ||
|
||
/// <summary> | ||
/// Tests parsing multiple agencies with agency_id. | ||
/// </summary> | ||
[Test] | ||
public void ParseAgenciesWithoutAgencyId() | ||
{ | ||
const string Agency = "agency"; | ||
var reader = new GTFSReader<GTFSFeed>(); | ||
var source = new List<IGTFSSourceFile> | ||
{ | ||
new GTFSSourceFileStream(_executingAssembly.GetManifestResourceStream("GTFS.Test.other_feed.agencies_no_id.txt"),Agency) | ||
}; | ||
|
||
|
||
Assert.Throws<GTFSRequiredFieldMissingException>(() => | ||
{ | ||
reader.Read(source, source.First(x => x.Name.Equals(Agency))); | ||
}, | ||
GTFSRequiredFieldMissingException.MessageFormat, "agency_id", Agency); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
agency_name,agency_url,agency_timezone | ||
Demo Transit Authority,http://google.com,America/Los_Angeles | ||
Other Transit Authority,http://somewhere.com,Europe/Brussels |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
agency_id,agency_name,agency_url,agency_timezone | ||
DTA,Demo Transit Authority,http://google.com,America/Los_Angeles | ||
OTA,Other Transit Authority,http://somewhere.com,Europe/Brussels |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
agency_name,agency_url,agency_timezone | ||
Demo Transit Authority,http://google.com,America/Los_Angeles |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
agency_id,agency_name,agency_url,agency_timezone | ||
DTA,Demo Transit Authority,http://google.com,America/Los_Angeles |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters