sonarr-repo-only/NzbDrone.Services/NzbDrone.Services.Tests/ExceptionControllerTests/ReportExistingFixture.cs

74 lines
2.3 KiB
C#
Raw Normal View History

2012-03-01 05:10:56 +00:00
using System;
using System.Linq;
using FizzWare.NBuilder;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Common.Contract;
using NzbDrone.Services.Service.Repository.Reporting;
using NzbDrone.Services.Tests.Framework;
using NzbDrone.Test.Common;
2012-03-01 06:45:36 +00:00
namespace NzbDrone.Services.Tests.ExceptionControllerTests
2012-03-01 05:10:56 +00:00
{
[TestFixture]
public class ReportExistingFixture : ServicesTestBase
{
Service.Controllers.ExceptionController Controller
{
get
{
return Mocker.Resolve<Service.Controllers.ExceptionController>();
}
}
private static ExistingExceptionReport CreateExceptionReport()
{
return new ExistingExceptionReport
{
IsProduction = true,
Version = "1.1.2.323456",
UGuid = Guid.NewGuid(),
LogMessage = @"Log message",
Hash = "ABC123"
};
}
[Test]
public void should_log_warn_if_hash_doesnt_exist()
{
WithRealDb();
Controller.ReportExisting(CreateExceptionReport());
Db.Fetch<ExceptionDetail>().Should().BeEmpty();
Db.Fetch<ExceptionInstance>().Should().BeEmpty();
ExceptionVerification.ExpectedWarns(1);
}
[Test]
public void should_save_instance_if_hash_is_valid()
{
WithRealDb();
var existing = CreateExceptionReport();
2012-03-01 07:58:11 +00:00
2012-03-01 05:10:56 +00:00
Db.Insert(Builder<ExceptionDetail>.CreateNew().With(c => c.Hash = existing.Hash).Build());
2012-03-01 07:58:11 +00:00
Controller.ReportExisting(existing);
2012-03-01 05:10:56 +00:00
Db.Fetch<ExceptionDetail>().Should().HaveCount(1);
2012-03-01 07:58:11 +00:00
var exceptionInstance = Db.Fetch<ExceptionInstance>();
exceptionInstance.Should().HaveCount(1);
exceptionInstance.Single().Id.Should().BeGreaterThan(0);
exceptionInstance.Single().ExceptionHash.Should().NotBeBlank();
exceptionInstance.Single().IsProduction.Should().Be(existing.IsProduction);
exceptionInstance.Single().Timestamp.Should().BeWithin(TimeSpan.FromSeconds(4)).Before(DateTime.Now);
exceptionInstance.Single().LogMessage.Should().Be(existing.LogMessage);
exceptionInstance.Single().UGuid.Should().Be(existing.UGuid);
2012-03-01 05:10:56 +00:00
}
}
}