Skip to content

Commit

Permalink
Use DryIoc for Automoqer, drop Unity dependency
Browse files Browse the repository at this point in the history
(cherry picked from commit e3468daba04b52fbf41ce3004934a26b0220ec4f)
  • Loading branch information
ta264 committed Jun 22, 2022
1 parent 9b120f4 commit cf4103d
Show file tree
Hide file tree
Showing 12 changed files with 118 additions and 237 deletions.
7 changes: 7 additions & 0 deletions src/NzbDrone.Common.Test/DiskTests/DiskProviderFixtureBase.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
using System.IO.Abstractions;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Common.Disk;
Expand All @@ -10,6 +11,12 @@ namespace NzbDrone.Common.Test.DiskTests
public abstract class DiskProviderFixtureBase<TSubject> : TestBase<TSubject>
where TSubject : class, IDiskProvider
{
[SetUp]
public void BaseSetup()
{
Mocker.SetConstant<IFileSystem>(new FileSystem());
}

[Test]
public void writealltext_should_truncate_existing()
{
Expand Down
7 changes: 7 additions & 0 deletions src/NzbDrone.Common.Test/DiskTests/FreeSpaceFixtureBase.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
using System.IO.Abstractions;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Common.Disk;
Expand All @@ -10,6 +11,12 @@ namespace NzbDrone.Common.Test.DiskTests
public abstract class FreeSpaceFixtureBase<TSubject> : TestBase<TSubject>
where TSubject : class, IDiskProvider
{
[SetUp]
public void BaseSetup()
{
Mocker.SetConstant<IFileSystem>(new FileSystem());
}

[Test]
public void should_get_free_space_for_folder()
{
Expand Down
12 changes: 5 additions & 7 deletions src/NzbDrone.Core.Test/Framework/FileSystemTest.cs
@@ -1,7 +1,8 @@
using System.IO.Abstractions.TestingHelpers;
using System.IO.Abstractions;
using System.IO.Abstractions.TestingHelpers;
using NUnit.Framework;
using NzbDrone.Common.Disk;
using Unity.Resolution;
using NzbDrone.Test.Common.AutoMoq;

namespace NzbDrone.Core.Test.Framework
{
Expand All @@ -14,12 +15,9 @@ public abstract class FileSystemTest<TSubject> : CoreTest<TSubject>
[SetUp]
public void FileSystemTestSetup()
{
FileSystem = new MockFileSystem();
FileSystem = (MockFileSystem)Mocker.Resolve<IFileSystem>(FileSystemType.Mock);

DiskProvider = Mocker.Resolve<IDiskProvider>("ActualDiskProvider", new ResolverOverride[]
{
new ParameterOverride("fileSystem", FileSystem)
});
DiskProvider = Mocker.Resolve<IDiskProvider>(FileSystemType.Mock);
}
}
}
@@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Abstractions;
using System.Linq;
using FizzWare.NBuilder;
using FluentAssertions;
Expand Down Expand Up @@ -126,6 +128,13 @@ public void should_convert_media_urls_to_local_without_time_if_file_doesnt_exist
}
};

var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "Files", "Media", "NonExistant.mp4");
var fileInfo = new FileInfo(path);

Mocker.GetMock<IDiskProvider>()
.Setup(c => c.GetFileInfo(It.IsAny<string>()))
.Returns((FileInfoBase)fileInfo);

Subject.ConvertToLocalUrls(12, MediaCoverEntity.Artist, covers);

covers.Single().Url.Should().Be("/MediaCover/12/banner" + extension);
Expand Down
5 changes: 2 additions & 3 deletions src/NzbDrone.Core.Test/MediaFiles/AudioTagServiceFixture.cs
Expand Up @@ -13,6 +13,7 @@
using NzbDrone.Core.Music;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common;
using NzbDrone.Test.Common.AutoMoq;

namespace NzbDrone.Core.Test.MediaFiles.AudioTagServiceFixture
{
Expand Down Expand Up @@ -55,9 +56,7 @@ public static IEnumerable TestCases
[SetUp]
public void Setup()
{
_diskProvider = Mocker.Resolve<IDiskProvider>("ActualDiskProvider");

Mocker.SetConstant<IDiskProvider>(_diskProvider);
_diskProvider = Mocker.Resolve<IDiskProvider>(FileSystemType.Actual);

Mocker.GetMock<IConfigService>()
.Setup(x => x.WriteAudioTags)
Expand Down
@@ -1,4 +1,5 @@
using FluentAssertions;
using System.IO.Abstractions;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Common.Disk;
using NzbDrone.Mono.Disk;
Expand All @@ -16,6 +17,7 @@ public void Setup()
{
NotBsd();

Mocker.SetConstant<IFileSystem>(new FileSystem());
Mocker.SetConstant<IDiskProvider>(Mocker.Resolve<DiskProvider>());
}

Expand Down
@@ -1,4 +1,5 @@
using System.IO;
using System.IO;
using System.IO.Abstractions;
using FluentAssertions;
using Moq;
using NUnit.Framework;
Expand All @@ -20,6 +21,7 @@ public void should_get_version_info_from_actual_linux()
{
NotBsd();

Mocker.SetConstant<IFileSystem>(new FileSystem());
Mocker.SetConstant<IDiskProvider>(Mocker.Resolve<DiskProvider>());
var info = Subject.Read();
info.FullName.Should().NotBeNullOrWhiteSpace();
Expand Down

0 comments on commit cf4103d

Please sign in to comment.