-
Notifications
You must be signed in to change notification settings - Fork 20
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 #96 from GHPReporter/feature-tests
Feature tests
- Loading branch information
Showing
52 changed files
with
1,865 additions
and
45 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
using System; | ||
using Ghpr.Core.Common; | ||
using Ghpr.Core.Settings; | ||
using Ghpr.Core.Utils; | ||
using NUnit.Framework; | ||
|
||
namespace Ghpr.Core.Tests.Core.Common | ||
{ | ||
[TestFixture] | ||
public class CommonCacheTests | ||
{ | ||
[Test] | ||
public void InitTest() | ||
{ | ||
var logger = new EmptyLogger(); | ||
var settings = new ReporterSettings(); | ||
var cache = CommonCache.Instance; | ||
Assert.IsInstanceOf(typeof(CommonCache), cache.GetDataReader()); | ||
Assert.IsInstanceOf(typeof(CommonCache), cache.GetDataWriter()); | ||
Assert.Throws<NullReferenceException>(() => cache.SaveTestRun(new TestRunDto(), new TestOutputDto())); | ||
Assert.Throws<NullReferenceException>(() => cache.GetTestRun(new ItemInfoDto())); | ||
Assert.Throws<NullReferenceException>(() => cache.GetReportSettings()); | ||
Assert.Throws<NullReferenceException>(() => cache.GetLatestTestRun(Guid.NewGuid())); | ||
Assert.Throws<NullReferenceException>(() => cache.GetRun(Guid.NewGuid())); | ||
Assert.Throws<NullReferenceException>(() => cache.GetRunInfos()); | ||
Assert.Throws<NullReferenceException>(() => cache.GetTestInfos(Guid.NewGuid())); | ||
Assert.Throws<NullReferenceException>(() => cache.GetTestOutput(new TestRunDto())); | ||
Assert.Throws<NullReferenceException>(() => cache.GetTestRunsFromRun(new RunDto())); | ||
Assert.Throws<NullReferenceException>(() => cache.GetTestScreenshots(new TestRunDto())); | ||
Assert.Throws<NullReferenceException>(() => cache.SaveReportSettings(new ReportSettingsDto(1, 2, "", ""))); | ||
Assert.Throws<NullReferenceException>(() => cache.SaveRun(new RunDto())); | ||
var scr = new TestScreenshotDto | ||
{ | ||
Base64Data = "adfas", | ||
Format = "png", | ||
TestGuid = Guid.NewGuid(), | ||
TestScreenshotInfo = new SimpleItemInfoDto {Date = DateTime.Now, ItemName = "item"} | ||
}; | ||
Assert.Throws<NullReferenceException>(() => cache.SaveScreenshot(scr)); | ||
Assert.Throws<NullReferenceException>(() => cache.UpdateTestOutput(new ItemInfoDto(), new TestOutputDto())); | ||
Assert.Throws<NullReferenceException>(() => cache.DeleteRun(new ItemInfoDto())); | ||
Assert.Throws<NullReferenceException>(() => cache.DeleteTest(new TestRunDto())); | ||
Assert.Throws<NullReferenceException>(() => cache.DeleteTestOutput(new TestRunDto(), new TestOutputDto())); | ||
Assert.Throws<NullReferenceException>(() => cache.DeleteTestScreenshot(new TestRunDto(), new TestScreenshotDto())); | ||
cache.InitializeDataWriter(settings, logger); | ||
cache.InitializeDataReader(settings, logger); | ||
Assert.IsInstanceOf(typeof(CommonCache), cache.GetDataReader()); | ||
Assert.IsInstanceOf(typeof(CommonCache), cache.GetDataWriter()); | ||
Assert.DoesNotThrow(() => cache.SaveTestRun(new TestRunDto(), new TestOutputDto())); | ||
Assert.DoesNotThrow(() => cache.GetTestRun(new ItemInfoDto())); | ||
Assert.DoesNotThrow(() => cache.GetReportSettings()); | ||
Assert.DoesNotThrow(() => cache.GetLatestTestRun(Guid.NewGuid())); | ||
Assert.DoesNotThrow(() => cache.GetRun(Guid.NewGuid())); | ||
Assert.DoesNotThrow(() => cache.GetRunInfos()); | ||
Assert.DoesNotThrow(() => cache.GetTestInfos(Guid.NewGuid())); | ||
Assert.DoesNotThrow(() => cache.GetTestOutput(new TestRunDto())); | ||
Assert.DoesNotThrow(() => cache.GetTestRunsFromRun(new RunDto())); | ||
Assert.DoesNotThrow(() => cache.GetTestScreenshots(new TestRunDto())); | ||
Assert.DoesNotThrow(() => cache.SaveReportSettings(new ReportSettingsDto(1, 2, "", ""))); | ||
Assert.DoesNotThrow(() => cache.SaveRun(new RunDto())); | ||
Assert.DoesNotThrow(() => cache.SaveScreenshot(scr)); | ||
Assert.DoesNotThrow(() => cache.UpdateTestOutput(new ItemInfoDto(), new TestOutputDto())); | ||
Assert.DoesNotThrow(() => cache.DeleteRun(new ItemInfoDto())); | ||
Assert.DoesNotThrow(() => cache.DeleteTest(new TestRunDto())); | ||
Assert.DoesNotThrow(() => cache.DeleteTestOutput(new TestRunDto(), new TestOutputDto())); | ||
Assert.DoesNotThrow(() => cache.DeleteTestScreenshot(new TestRunDto(), scr)); | ||
cache.TearDown(); | ||
} | ||
} | ||
} |
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,32 @@ | ||
using System; | ||
using Ghpr.Core.Common; | ||
using NUnit.Framework; | ||
|
||
namespace Ghpr.Core.Tests.Core.Common | ||
{ | ||
[TestFixture] | ||
public class TestCaseFullDtoTests | ||
{ | ||
[Test] | ||
public void Init() | ||
{ | ||
var t = new TestCaseFullDto(); | ||
Assert.AreEqual("", t.ParentId); | ||
Assert.AreEqual("", t.Id); | ||
Assert.AreEqual("", t.GhprTestRun.Name); | ||
Assert.AreEqual(Guid.Empty, t.GhprTestRun.TestInfo.Guid); | ||
Assert.AreEqual(0, t.GhprTestScreenshots.Count); | ||
} | ||
|
||
[Test] | ||
public void ToStringTest() | ||
{ | ||
var t = new TestCaseFullDto | ||
{ | ||
ParentId = "p id", | ||
Id = "id" | ||
}; | ||
Assert.AreEqual("GhprTestCase: Id = id, ParentID = p id", t.ToString()); | ||
} | ||
} | ||
} |
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,33 @@ | ||
using System; | ||
using Ghpr.Core.Common; | ||
using NUnit.Framework; | ||
|
||
namespace Ghpr.Core.Tests.Core.Common | ||
{ | ||
[TestFixture] | ||
public class TestEventDtoTests | ||
{ | ||
[Test] | ||
public void CreateEmptyTest() | ||
{ | ||
var e = new TestEventDto(); | ||
Assert.AreEqual("", e.Comment); | ||
Assert.AreEqual(default(DateTime), e.Started); | ||
Assert.AreEqual(default(DateTime), e.Finished); | ||
Assert.AreEqual(null, e.EventInfo.ItemName); | ||
Assert.AreEqual(default(DateTime), e.EventInfo.Date); | ||
} | ||
|
||
[Test] | ||
public void CreateNotEmptyTest() | ||
{ | ||
var now = DateTime.Now; | ||
var e = new TestEventDto("comment", now, now.AddSeconds(2)); | ||
Assert.AreEqual("comment", e.Comment); | ||
Assert.AreEqual(now, e.Started); | ||
Assert.AreEqual(now.AddSeconds(2), e.Finished); | ||
Assert.AreEqual(null, e.EventInfo.ItemName); | ||
Assert.AreEqual(default(DateTime), e.EventInfo.Date); | ||
} | ||
} | ||
} |
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,40 @@ | ||
using Ghpr.Core.Common; | ||
using Ghpr.Core.Enums; | ||
using NUnit.Framework; | ||
|
||
namespace Ghpr.Core.Tests.Core.Common | ||
{ | ||
[TestFixture] | ||
public class TestRunDtoTests | ||
{ | ||
[TestCase("passed", TestResult.Passed)] | ||
[TestCase("Passed", TestResult.Passed)] | ||
[TestCase("Passed test", TestResult.Passed)] | ||
[TestCase("test passed", TestResult.Passed)] | ||
[TestCase("error", TestResult.Broken)] | ||
[TestCase("ERROR", TestResult.Broken)] | ||
[TestCase("broken", TestResult.Broken)] | ||
[TestCase("Broken", TestResult.Broken)] | ||
[TestCase("failed", TestResult.Failed)] | ||
[TestCase("failure", TestResult.Failed)] | ||
[TestCase("Failed", TestResult.Failed)] | ||
[TestCase("FAILURE", TestResult.Failed)] | ||
[TestCase("inconclusive", TestResult.Inconclusive)] | ||
[TestCase("Inconclusive", TestResult.Inconclusive)] | ||
[TestCase("ignored", TestResult.Ignored)] | ||
[TestCase("skipped", TestResult.Ignored)] | ||
[TestCase("Ignored", TestResult.Ignored)] | ||
[TestCase("notexecuted", TestResult.Ignored)] | ||
[TestCase("as1dfd2fa4sd", TestResult.Unknown)] | ||
[TestCase("123", TestResult.Unknown)] | ||
[TestCase("!@#$%^&*(", TestResult.Unknown)] | ||
public void TestResultTest(string testResult, TestResult result) | ||
{ | ||
var test = new TestRunDto | ||
{ | ||
Result = testResult | ||
}; | ||
Assert.AreEqual(result, test.TestResult); | ||
} | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
Ghpr.Core.Tests/Core/Comparers/ItemInfoDtoComparerTests.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,76 @@ | ||
using System; | ||
using Ghpr.Core.Common; | ||
using Ghpr.Core.Comparers; | ||
using NUnit.Framework; | ||
|
||
namespace Ghpr.Core.Tests.Core.Comparers | ||
{ | ||
[TestFixture] | ||
public class ItemInfoDtoComparerTests | ||
{ | ||
private readonly ItemInfoDtoComparer _comparer = new ItemInfoDtoComparer(); | ||
|
||
[Test] | ||
public void TestNull() | ||
{ | ||
Assert.IsFalse(_comparer.Equals(null, new ItemInfoDto())); | ||
Assert.IsFalse(_comparer.Equals(new ItemInfoDto(), null)); | ||
Assert.IsTrue(_comparer.Equals(null, null)); | ||
} | ||
|
||
[Test] | ||
public void AreEqualTest() | ||
{ | ||
var now = DateTime.Now; | ||
var guid1 = Guid.NewGuid(); | ||
var dto1 = new ItemInfoDto(); | ||
var dto2 = new ItemInfoDto(); | ||
Assert.IsTrue(_comparer.Equals(dto1, dto2)); | ||
dto1.Guid = guid1; | ||
dto2.Guid = guid1; | ||
Assert.IsTrue(_comparer.Equals(dto1, dto2)); | ||
dto1.ItemName = "a1"; | ||
dto2.ItemName = "a2"; | ||
Assert.IsTrue(_comparer.Equals(dto1, dto2)); | ||
dto1.Start = now; | ||
dto2.Start = now; | ||
Assert.IsTrue(_comparer.Equals(dto1, dto2)); | ||
dto1.Finish = now.AddSeconds(1); | ||
dto2.Finish = now.AddSeconds(1); | ||
Assert.IsTrue(_comparer.Equals(dto1, dto2)); | ||
} | ||
|
||
[Test] | ||
public void AreNotEqualTest() | ||
{ | ||
var now = DateTime.Now; | ||
var guid1 = Guid.NewGuid(); | ||
var guid2 = Guid.NewGuid(); | ||
var dto1 = new ItemInfoDto { Guid = guid1, ItemName = "a1", Start = now, Finish = now.AddSeconds(1) }; | ||
var dto2 = new ItemInfoDto { Guid = guid2, ItemName = "a1", Start = now, Finish = now.AddSeconds(1) }; | ||
Assert.IsFalse(_comparer.Equals(dto1, dto2)); | ||
Assert.IsFalse(_comparer.Equals(dto2, dto1)); | ||
dto1 = new ItemInfoDto { Guid = guid1, ItemName = "a1", Start = now.AddSeconds(2), Finish = now.AddSeconds(1) }; | ||
dto2 = new ItemInfoDto { Guid = guid1, ItemName = "a1", Start = now, Finish = now.AddSeconds(1) }; | ||
Assert.IsFalse(_comparer.Equals(dto1, dto2)); | ||
Assert.IsFalse(_comparer.Equals(dto2, dto1)); | ||
dto1 = new ItemInfoDto { Guid = guid1, ItemName = "a1", Start = now, Finish = now.AddSeconds(1) }; | ||
dto2 = new ItemInfoDto { Guid = guid1, ItemName = "a1", Start = now, Finish = now.AddSeconds(2) }; | ||
Assert.IsFalse(_comparer.Equals(dto1, dto2)); | ||
Assert.IsFalse(_comparer.Equals(dto2, dto1)); | ||
dto1 = new ItemInfoDto { Guid = guid1, ItemName = "a1", Start = now.AddSeconds(2), Finish = now.AddSeconds(1) }; | ||
dto2 = new ItemInfoDto { Guid = guid1, ItemName = "a1", Start = now, Finish = now.AddSeconds(2) }; | ||
Assert.IsFalse(_comparer.Equals(dto1, dto2)); | ||
Assert.IsFalse(_comparer.Equals(dto2, dto1)); | ||
} | ||
|
||
[Test] | ||
public void HashCodeTest() | ||
{ | ||
var now = DateTime.Now; | ||
var guid = Guid.NewGuid(); | ||
var dto = new ItemInfoDto { Guid = guid, ItemName = "a1", Start = now, Finish = now.AddSeconds(1) }; | ||
Assert.AreEqual(dto.GetHashCode(), _comparer.GetHashCode(dto)); | ||
} | ||
} | ||
} |
95 changes: 95 additions & 0 deletions
95
Ghpr.Core.Tests/Core/Comparers/SimpleItemInfoDtoComparerTests.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,95 @@ | ||
using System; | ||
using Ghpr.Core.Common; | ||
using Ghpr.Core.Comparers; | ||
using NUnit.Framework; | ||
|
||
namespace Ghpr.Core.Tests.Core.Comparers | ||
{ | ||
[TestFixture] | ||
public class SimpleItemInfoDtoComparerTests | ||
{ | ||
private readonly SimpleItemInfoDtoComparer _comparer = new SimpleItemInfoDtoComparer(); | ||
|
||
[Test] | ||
public void TestEmptyItems() | ||
{ | ||
var dto1 = new SimpleItemInfoDto(); | ||
var dto2 = new SimpleItemInfoDto(); | ||
Assert.IsTrue(_comparer.Equals(dto1, dto2)); | ||
} | ||
|
||
[Test] | ||
public void TestNullItems() | ||
{ | ||
var dto = new SimpleItemInfoDto(); | ||
Assert.IsFalse(_comparer.Equals(null, dto)); | ||
Assert.IsFalse(_comparer.Equals(dto, null)); | ||
} | ||
|
||
[Test] | ||
public void TestNullItemName() | ||
{ | ||
var dto1 = new SimpleItemInfoDto { ItemName = "a" }; | ||
var dto2 = new SimpleItemInfoDto { ItemName = null }; | ||
Assert.IsFalse(_comparer.Equals(dto1, dto2)); | ||
Assert.IsFalse(_comparer.Equals(dto2, dto1)); | ||
} | ||
|
||
[Test] | ||
public void TestNullItemNameDifferentDates() | ||
{ | ||
var now = DateTime.Now; | ||
var dto1 = new SimpleItemInfoDto { ItemName = null, Date = now }; | ||
var dto2 = new SimpleItemInfoDto { ItemName = null, Date = now.AddSeconds(2) }; | ||
Assert.IsFalse(_comparer.Equals(dto1, dto2)); | ||
Assert.IsFalse(_comparer.Equals(dto1, dto2)); | ||
} | ||
|
||
[Test] | ||
public void TestNullItemNameSameDates() | ||
{ | ||
var now = DateTime.Now; | ||
var dto1 = new SimpleItemInfoDto { ItemName = null, Date = now }; | ||
var dto2 = new SimpleItemInfoDto { ItemName = null, Date = now }; | ||
Assert.IsTrue(_comparer.Equals(dto1, dto2)); | ||
Assert.IsTrue(_comparer.Equals(dto2, dto1)); | ||
} | ||
|
||
[Test] | ||
public void TestNotNullItemNameDifferentDates() | ||
{ | ||
var now = DateTime.Now; | ||
var dto1 = new SimpleItemInfoDto { ItemName = "a", Date = now }; | ||
var dto2 = new SimpleItemInfoDto { ItemName = "a", Date = now.AddSeconds(2) }; | ||
Assert.IsFalse(_comparer.Equals(dto1, dto2)); | ||
Assert.IsFalse(_comparer.Equals(dto2, dto1)); | ||
} | ||
|
||
[Test] | ||
public void TestNotNullItemNameSameDates() | ||
{ | ||
var now = DateTime.Now; | ||
var dto1 = new SimpleItemInfoDto { ItemName = "b", Date = now }; | ||
var dto2 = new SimpleItemInfoDto { ItemName = "b", Date = now }; | ||
Assert.IsTrue(_comparer.Equals(dto1, dto2)); | ||
Assert.IsTrue(_comparer.Equals(dto2, dto1)); | ||
} | ||
|
||
[Test] | ||
public void TestNotNullDifferentItemNameSameDates() | ||
{ | ||
var now = DateTime.Now; | ||
var dto1 = new SimpleItemInfoDto { ItemName = "a", Date = now }; | ||
var dto2 = new SimpleItemInfoDto { ItemName = "b", Date = now }; | ||
Assert.IsFalse(_comparer.Equals(dto1, dto2)); | ||
Assert.IsFalse(_comparer.Equals(dto2, dto1)); | ||
} | ||
|
||
[Test] | ||
public void TestHash() | ||
{ | ||
var dto = new SimpleItemInfoDto(); | ||
Assert.AreEqual(dto.GetHashCode(), _comparer.GetHashCode(dto)); | ||
} | ||
} | ||
} |
Oops, something went wrong.