1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-14 11:23:42 +02:00
Sonarr/NzbDrone.Services/NzbDrone.Services.Tests/ReportingControllerFixture.cs

90 lines
2.7 KiB
C#
Raw Normal View History

using System;
using System.Linq;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Common.Contract;
using NzbDrone.Services.Service.Controllers;
using NzbDrone.Services.Service.Repository.Reporting;
using NzbDrone.Services.Tests.Framework;
namespace NzbDrone.Services.Tests
{
[TestFixture]
public class ReportingControllerFixture : ServicesTestBase
{
2012-03-01 09:45:36 +03:00
[SetUp]
public void Setup()
{
WithRealDb();
Mocker.Resolve<ExceptionController>();
}
ReportingController Controller
{
get
{
return Mocker.Resolve<ReportingController>();
}
}
private static ParseErrorReport CreateParseErrorReport()
{
return new ParseErrorReport
{
IsProduction = true,
Title = "MyTitle",
2012-02-05 19:53:08 +03:00
Version = "1.1.2.323456",
UGuid = Guid.NewGuid()
};
}
[Test]
public void parse_report_should_be_saved()
{
var parseReport = CreateParseErrorReport();
Controller.ParseError(parseReport);
var reports = Db.Fetch<ParseErrorRow>();
reports.Should().HaveCount(1);
reports.Single().Title.Should().Be(parseReport.Title);
reports.Single().IsProduction.Should().Be(parseReport.IsProduction);
reports.Single().Version.Should().Be(parseReport.Version);
reports.Single().Timestamp.Should().BeWithin(TimeSpan.FromSeconds(4)).Before(DateTime.Now);
reports.Single().UGuid.Should().Be(parseReport.UGuid);
}
[Test]
public void parse_report_should_save_report_if_title_doesnt_exist()
{
var parseReport1 = CreateParseErrorReport();
var parseReport2 = CreateParseErrorReport();
parseReport1.Title = Guid.NewGuid().ToString();
Controller.ParseError(parseReport1);
Controller.ParseError(parseReport2);
var reports = Db.Fetch<ParseErrorRow>();
reports.Should().HaveCount(2);
}
[Test]
public void parse_report_should_not_save_report_if_title_exist()
{
var parseReport1 = CreateParseErrorReport();
var parseReport2 = CreateParseErrorReport();
Controller.ParseError(parseReport1);
Controller.ParseError(parseReport2);
var reports = Db.Fetch<ParseErrorRow>();
reports.Should().HaveCount(1);
}
}
}