Fixed: Various tests

pull/2/head
ta264 5 years ago committed by Qstick
parent a22c946276
commit fd5113744f

@ -3,6 +3,7 @@ using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Common.Model;
@ -64,12 +65,30 @@ namespace NzbDrone.Common.Test
}
[Test]
public void Should_be_able_to_start_process()
public void should_be_able_to_start_process()
{
var process = StartDummyProcess();
var check = Subject.GetProcessById(process.Id);
check.Should().NotBeNull();
process.Refresh();
process.HasExited.Should().BeFalse();
process.Kill();
process.WaitForExit();
process.HasExited.Should().BeTrue();
}
[Test]
[Platform(Exclude="MacOsX")]
[Retry(3)]
public void exists_should_find_running_process()
{
var process = StartDummyProcess();
Subject.Exists(DummyApp.DUMMY_PROCCESS_NAME).Should()
.BeTrue("excepted one dummy process to be already running");
.BeTrue("expected one dummy process to be already running");
process.Kill();
process.WaitForExit();
@ -126,8 +145,8 @@ namespace NzbDrone.Common.Test
}
}
[Test]
[Platform(Exclude="MacOsX")]
public void kill_all_should_kill_all_process_with_name()
{
var dummy1 = StartDummyProcess();
@ -141,15 +160,30 @@ namespace NzbDrone.Common.Test
private Process StartDummyProcess()
{
var processStarted = new ManualResetEventSlim();
var path = Path.Combine(TestContext.CurrentContext.TestDirectory, DummyApp.DUMMY_PROCCESS_NAME + ".exe");
return Subject.Start(path);
var process = Subject.Start(path, onOutputDataReceived: (string data) => {
if (data.StartsWith("Dummy process. ID:"))
{
processStarted.Set();
}
});
if (!processStarted.Wait(2000))
{
Assert.Fail("Failed to start process within 2 sec");
}
return process;
}
[Test]
[Retry(3)]
public void ToString_on_new_processInfo()
{
Console.WriteLine(new ProcessInfo().ToString());
ExceptionVerification.MarkInconclusive(typeof(Win32Exception));
}
}
}
}

@ -19,14 +19,20 @@ namespace NzbDrone.Common.Test
}
[TestCase("")]
[TestCase("http://")]
public void DownloadString_should_throw_on_error_windows(string url)
public void DownloadString_should_throw_on_empty_string(string url)
{
WindowsOnly();
Assert.Throws<ArgumentException>(() => Subject.DownloadString(url));
ExceptionVerification.ExpectedWarns(1);
}
// .net 4.6.2 throws NotSupportedException instead of ArgumentException here
[TestCase("http://")]
public void DownloadString_should_throw_on_not_supported_string_windows(string url)
{
WindowsOnly();
Assert.Throws<NotSupportedException>(() => Subject.DownloadString(url));
ExceptionVerification.ExpectedWarns(1);
}
[TestCase("http://")]
public void DownloadString_should_throw_on_not_supported_string_mono(string url)

@ -40,7 +40,7 @@ namespace NzbDrone.Core.Test.InstrumentationTests
{
_logger.Info(_uniqueMessage);
Thread.Sleep(600);
Thread.Sleep(1000);
StoredModel.Message.Should().Be(_uniqueMessage);
VerifyLog(StoredModel, LogLevel.Info);
@ -57,7 +57,7 @@ namespace NzbDrone.Core.Test.InstrumentationTests
_logger.Info(message);
Thread.Sleep(600);
Thread.Sleep(1000);
StoredModel.Message.Should().HaveLength(message.Length);
StoredModel.Message.Should().Be(message);
@ -76,7 +76,7 @@ namespace NzbDrone.Core.Test.InstrumentationTests
_logger.Info(Guid.NewGuid());
}
Thread.Sleep(600);
Thread.Sleep(1000);
MapRepository.Instance.EnableTraceLogging = true;
}
@ -88,7 +88,7 @@ namespace NzbDrone.Core.Test.InstrumentationTests
_logger.Error(ex, _uniqueMessage);
Thread.Sleep(600);
Thread.Sleep(1000);
VerifyLog(StoredModel, LogLevel.Error);
StoredModel.Message.Should().Be(_uniqueMessage + ": " + ex.Message);
@ -106,7 +106,7 @@ namespace NzbDrone.Core.Test.InstrumentationTests
_logger.Error(ex, _uniqueMessage);
Thread.Sleep(600);
Thread.Sleep(1000);
StoredModel.Message.Should().Be(ex.Message);
@ -121,7 +121,7 @@ namespace NzbDrone.Core.Test.InstrumentationTests
var epFile = new MovieFile();
_logger.Debug("File {0} no longer exists on disk. removing from database.", epFile.RelativePath);
Thread.Sleep(600);
Thread.Sleep(1000);
epFile.RelativePath.Should().BeNull();
}

@ -7,6 +7,7 @@ using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Movies;
using NzbDrone.Core.Validation.Paths;
using NzbDrone.Test.Common;
using NzbDrone.Common.EnvironmentInfo;
namespace NzbDrone.Core.Test.ValidationTests
{
@ -52,8 +53,9 @@ namespace NzbDrone.Core.Test.ValidationTests
{
MonoOnly();
var bin = OsInfo.IsOsx ? "/System" : "/bin";
var movie = Builder<Movie>.CreateNew()
.With(s => s.Path = "/bin")
.With(s => s.Path = bin)
.Build();
_validator.Validate(movie).IsValid.Should().BeFalse();
@ -64,9 +66,10 @@ namespace NzbDrone.Core.Test.ValidationTests
{
MonoOnly();
var bin = OsInfo.IsOsx ? "/System" : "/bin";
var movie = Builder<Movie>.CreateNew()
.With(s => s.Path = "/bin/test")
.Build();
.With(s => s.Path = Path.Combine(bin, "test"))
.Build();
_validator.Validate(movie).IsValid.Should().BeFalse();
}

Loading…
Cancel
Save