Skip to content

Commit

Permalink
fixed issue itinero#27: Missing base class for all GTFS exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Ranko Orlic committed Feb 10, 2016
1 parent cd29cb9 commit a0b97a5
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 10 deletions.
55 changes: 55 additions & 0 deletions GTFS.Test/Exceptions/GTFSExceptionsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// 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 System;
using System.Linq;
using GTFS.Exceptions;
using NUnit.Framework;

namespace GTFS.Test.Exceptions
{
/// <summary>
/// Contains tests for <see cref="GTFSExceptionBase"/>.
/// </summary>
[TestFixture]
// ReSharper disable once InconsistentNaming
public class GTFSExceptionsTests
{
/// <summary>
/// Tests all exceptions derive from our base.
/// </summary>
[Test]
public void AllCustomExceptionsInheritFromOurBase()
{
// get all our exceptions.
var baseException = typeof(GTFSExceptionBase);
var systemException = typeof(Exception);
var customExceptions = baseException.Assembly
.GetTypes()
.Where(x => x != baseException && systemException.IsAssignableFrom(x))
.ToArray();

// test result.
Assert.IsTrue(customExceptions.All(x => baseException.IsAssignableFrom(x)));
}
}
}
1 change: 1 addition & 0 deletions GTFS.Test/GTFS.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
<Compile Include="DB\SQLite\SQLiteGTFSFeedDBTests.cs" />
<Compile Include="DirectorySourceTest.cs" />
<Compile Include="Entities\CalendarTests.cs" />
<Compile Include="Exceptions\GTFSExceptionsTests.cs" />
<Compile Include="FeedInfoEqualityComparer.cs" />
<Compile Include="Filters\GTFSFeedStopsFilterTests.cs" />
<Compile Include="GTFSAssert.cs" />
Expand Down
20 changes: 20 additions & 0 deletions GTFS/Exceptions/GTFSExceptionBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;

namespace GTFS.Exceptions
{
/// <summary>
/// Abstract base class for all GTFS exceptions.
/// </summary>
public abstract class GTFSExceptionBase : Exception
{
protected GTFSExceptionBase(string message)
: base(message)
{
}

protected GTFSExceptionBase(string message, Exception innerException)
: base(message, innerException)
{
}
}
}
4 changes: 1 addition & 3 deletions GTFS/Exceptions/GTFSIntegrityException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

using System;

namespace GTFS.Exceptions
{
/// <summary>
/// Exception thrown when a referred id has not been found.
/// </summary>
public class GTFSIntegrityException : Exception
public class GTFSIntegrityException : GTFSExceptionBase
{
/// <summary>
/// Creates a parsing exception.
Expand Down
2 changes: 1 addition & 1 deletion GTFS/Exceptions/GTFSParseException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace GTFS.Exceptions
/// <summary>
/// Exception thrown when a value could not be parsed.
/// </summary>
public class GTFSParseException : Exception
public class GTFSParseException : GTFSExceptionBase
{
/// <summary>
/// Creates a parsing exception.
Expand Down
4 changes: 1 addition & 3 deletions GTFS/Exceptions/GTFSRequiredFieldMissingException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

using System;

namespace GTFS.Exceptions
{
/// <summary>
/// Exception thrown when a required field is missing from a GTFS-feed.
/// </summary>
public class GTFSRequiredFieldMissingException : Exception
public class GTFSRequiredFieldMissingException : GTFSExceptionBase
{
/// <summary>
/// Creates a new field missing exception.
Expand Down
4 changes: 1 addition & 3 deletions GTFS/Exceptions/GTFSRequiredFileMissingException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

using System;

namespace GTFS.Exceptions
{
/// <summary>
/// Exception thrown when a required file was not found.
/// </summary>
public class GTFSRequiredFileMissingException : Exception
public class GTFSRequiredFileMissingException : GTFSExceptionBase
{
/// <summary>
/// Creates a missing file exception.
Expand Down
1 change: 1 addition & 0 deletions GTFS/GTFS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
<Compile Include="Entities\TimeOfDay.cs" />
<Compile Include="Entities\Transfers.cs" />
<Compile Include="Entities\Trip.cs" />
<Compile Include="Exceptions\GTFSExceptionBase.cs" />
<Compile Include="Exceptions\GTFSIntegrityException.cs" />
<Compile Include="Exceptions\GTFSParseException.cs" />
<Compile Include="Exceptions\GTFSRequiredFieldMissingException.cs" />
Expand Down

0 comments on commit a0b97a5

Please sign in to comment.