-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from rorlic/develop
- Loading branch information
Showing
31 changed files
with
955 additions
and
50 deletions.
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,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))); | ||
} | ||
} | ||
} |
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,58 @@ | ||
using System.Collections.Generic; | ||
using GTFS.Entities; | ||
|
||
namespace GTFS.Test | ||
{ | ||
/// <summary> | ||
/// Compares instances of type <see cref="FeedInfo"/> for equality. | ||
/// </summary> | ||
public sealed class FeedInfoEqualityComparer : IEqualityComparer<FeedInfo> | ||
{ | ||
/// <summary> | ||
/// Determines whether the specified objects are equal. | ||
/// </summary> | ||
/// <returns> | ||
/// true if the specified objects are equal; otherwise, false. | ||
/// </returns> | ||
/// <param name="x">The first object of type <see cref="FeedInfo"/> to compare.</param> | ||
/// <param name="y">The second object of type <see cref="FeedInfo"/> to compare.</param> | ||
public bool Equals(FeedInfo x, FeedInfo y) | ||
{ | ||
if (ReferenceEquals(x, y)) return true; | ||
if (ReferenceEquals(x, null)) return false; | ||
if (ReferenceEquals(y, null)) return false; | ||
if (x.GetType() != y.GetType()) return false; | ||
|
||
return string.Equals(x.PublisherName, y.PublisherName) && | ||
string.Equals(x.PublisherUrl, y.PublisherUrl) && | ||
string.Equals(x.Lang, y.Lang) && | ||
string.Equals(x.StartDate, y.StartDate) && | ||
string.Equals(x.EndDate, y.EndDate) && | ||
Equals(x.Tag, y.Tag) && | ||
string.Equals(x.Version, y.Version); | ||
} | ||
|
||
/// <summary> | ||
/// Returns a hash code for the specified object. | ||
/// </summary> | ||
/// <returns> | ||
/// A hash code for the specified object. | ||
/// </returns> | ||
/// <param name="obj">The <see cref="T:System.Object"/> for which a hash code is to be returned.</param> | ||
/// <exception cref="T:System.ArgumentNullException">The type of <paramref name="obj"/> is a reference type and <paramref name="obj"/> is null.</exception> | ||
public int GetHashCode(FeedInfo obj) | ||
{ | ||
unchecked | ||
{ | ||
var hashCode = (obj.PublisherName != null ? obj.PublisherName.GetHashCode() : 0); | ||
hashCode = (hashCode * 397) ^ (obj.PublisherUrl != null ? obj.PublisherUrl.GetHashCode() : 0); | ||
hashCode = (hashCode * 397) ^ (obj.Lang != null ? obj.Lang.GetHashCode() : 0); | ||
hashCode = (hashCode * 397) ^ (obj.StartDate != null ? obj.StartDate.GetHashCode() : 0); | ||
hashCode = (hashCode * 397) ^ (obj.EndDate != null ? obj.EndDate.GetHashCode() : 0); | ||
hashCode = (hashCode * 397) ^ (obj.Tag != null ? obj.Tag.GetHashCode() : 0); | ||
hashCode = (hashCode * 397) ^ (obj.Version != null ? obj.Version.GetHashCode() : 0); | ||
return hashCode; | ||
} | ||
} | ||
} | ||
} |
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,100 @@ | ||
// 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.IO; | ||
using GTFS.Exceptions; | ||
using GTFS.IO; | ||
using NUnit.Framework; | ||
|
||
namespace GTFS.Test | ||
{ | ||
[TestFixture] | ||
internal class FileNotDisposedTest | ||
{ | ||
private static DirectoryInfo _assemblyLocation; | ||
|
||
private static DirectoryInfo AssemblyLocation | ||
{ | ||
get | ||
{ | ||
// ReSharper disable once AssignNullToNotNullAttribute | ||
return _assemblyLocation ?? (_assemblyLocation = new DirectoryInfo(Path.GetDirectoryName(typeof(FileNotDisposedTest).Assembly.Location))); | ||
} | ||
} | ||
|
||
[Test] | ||
public void NotDisposingDirectorySourceKeepsSourceFilesOpen() | ||
{ | ||
var directoryInfo = new DirectoryInfo(Path.Combine(AssemblyLocation.FullName, "folder-feed")); | ||
|
||
try | ||
{ | ||
var gtfsDirectorySource = new GTFSDirectorySource(directoryInfo); | ||
var reader = new GTFSReader<GTFSFeed>(); | ||
reader.Read(gtfsDirectorySource); | ||
} | ||
catch (GTFSExceptionBase) | ||
{ | ||
// ignore our exceptions | ||
} | ||
|
||
var agencyFile = Path.Combine(directoryInfo.FullName, "agency.txt"); | ||
|
||
Assert.Throws<IOException>( | ||
() => | ||
{ | ||
using (File.OpenWrite(agencyFile)) | ||
{ | ||
// do nothing | ||
} | ||
}, | ||
"The process cannot access the file '{0}' because it is being used by another process.", | ||
agencyFile); | ||
} | ||
|
||
[Test] | ||
public void DisposingDirectorySourceClosesSourceFiles() | ||
{ | ||
var directoryInfo = new DirectoryInfo(Path.Combine(AssemblyLocation.FullName, "folder-feed")); | ||
|
||
try | ||
{ | ||
using (var gtfsDirectorySource = new GTFSDirectorySource(directoryInfo)) | ||
{ | ||
var reader = new GTFSReader<GTFSFeed>(); | ||
reader.Read(gtfsDirectorySource); | ||
} | ||
} | ||
catch (GTFSExceptionBase) | ||
{ | ||
// ignore our exceptions | ||
} | ||
|
||
var agencyFile = Path.Combine(directoryInfo.FullName, "agency.txt"); | ||
|
||
using (File.OpenWrite(agencyFile)) | ||
{ | ||
// do nothing | ||
} | ||
} | ||
} | ||
} |
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
Oops, something went wrong.