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; namespace NzbDrone.Services.Tests.ExceptionControllerTests { [TestFixture] public class ReportExistingFixture : ServicesTestBase { Service.Controllers.ExceptionController Controller { get { return Mocker.Resolve(); } } 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().Should().BeEmpty(); Db.Fetch().Should().BeEmpty(); ExceptionVerification.ExpectedWarns(1); } [Test] public void should_save_instance_if_hash_is_valid() { WithRealDb(); var existing = CreateExceptionReport(); Db.Insert(Builder.CreateNew().With(c => c.Hash = existing.Hash).Build()); Controller.ReportExisting(CreateExceptionReport()); Db.Fetch().Should().HaveCount(1); Db.Fetch().Should().HaveCount(1); } } }