Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle dodgy data files with invalid JSON contents and rationalise fi…
…le result class
- Loading branch information
Showing
10 changed files
with
176 additions
and
75 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
70 changes: 70 additions & 0 deletions
70
ElasticTweets.Library.UnitTests/ImportFileResultFixture.cs
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,70 @@ | ||
using System; | ||
using NUnit.Framework; | ||
|
||
// ReSharper disable InconsistentNaming | ||
namespace ElasticTweets.Library.UnitTests | ||
{ | ||
[TestFixture] | ||
public class ImportFileResultFixture | ||
{ | ||
private const string TestFileName = "File1.js"; | ||
private const int TestNumberOfTweets = 123; | ||
private const string TestErrorMessage = "Went pop"; | ||
|
||
[Test] | ||
public void Constructor_Success_SetsFileName() | ||
{ | ||
var file = new ImportFileResult(TestFileName, TestNumberOfTweets); | ||
|
||
Assert.AreEqual(TestFileName, file.FileName); | ||
} | ||
|
||
[Test] | ||
public void Constructor_Success_SetsNumberOfTweets() | ||
{ | ||
var file = new ImportFileResult(TestFileName, TestNumberOfTweets); | ||
|
||
Assert.AreEqual(TestNumberOfTweets, file.NumberOfTweets); | ||
} | ||
|
||
[Test] | ||
public void Constructor_Success_DefaultsErrorMessageToEmpty() | ||
{ | ||
var file = new ImportFileResult(TestFileName, TestNumberOfTweets); | ||
|
||
Assert.AreEqual(String.Empty, file.ErrorMessage); | ||
} | ||
|
||
[Test] | ||
public void Constructor_Success_SetsSuccessFlagToTrue() | ||
{ | ||
var file = new ImportFileResult(TestFileName, TestNumberOfTweets); | ||
|
||
Assert.IsTrue(file.Success); | ||
} | ||
[Test] | ||
public void Constructor_Failure_SetsFileName() | ||
{ | ||
var file = new ImportFileResult(TestFileName, TestErrorMessage); | ||
|
||
Assert.AreEqual(TestFileName, file.FileName); | ||
} | ||
|
||
[Test] | ||
public void Constructor_Failure_SetsErrorMessage() | ||
{ | ||
var file = new ImportFileResult(TestFileName, TestErrorMessage); | ||
|
||
Assert.AreEqual(TestErrorMessage, file.ErrorMessage); | ||
} | ||
|
||
[Test] | ||
public void Constructor_Failure_SetsSuccessFlagToFalse() | ||
{ | ||
var file = new ImportFileResult(TestFileName, TestErrorMessage); | ||
|
||
Assert.IsFalse(file.Success); | ||
} | ||
} | ||
} | ||
// ReSharper restore InconsistentNaming |
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 was deleted.
Oops, something went wrong.
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
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,47 @@ | ||
using System; | ||
|
||
namespace ElasticTweets.Library | ||
{ | ||
public sealed class ImportFileResult | ||
{ | ||
private readonly string _fileName; | ||
private readonly int _numberOfTweets; | ||
private readonly string _errorMessage; | ||
private readonly bool _success; | ||
|
||
public ImportFileResult(string fileName, int numberOfTweets) | ||
{ | ||
_fileName = fileName; | ||
_numberOfTweets = numberOfTweets; | ||
_errorMessage = String.Empty; | ||
_success = true; | ||
} | ||
|
||
public ImportFileResult(string fileName, string errorMessage) | ||
{ | ||
_fileName = fileName; | ||
_errorMessage = errorMessage; | ||
_success = false; | ||
} | ||
|
||
public string FileName | ||
{ | ||
get { return _fileName; } | ||
} | ||
|
||
public int NumberOfTweets | ||
{ | ||
get { return _numberOfTweets; } | ||
} | ||
|
||
public string ErrorMessage | ||
{ | ||
get { return _errorMessage; } | ||
} | ||
|
||
public bool Success | ||
{ | ||
get { return _success; } | ||
} | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
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