Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions AdvancedSharpAdbClient.Tests/AdbServerTests.Async.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using AdvancedSharpAdbClient.Exceptions;
using Moq;
using NSubstitute;
using NSubstitute.ExceptionExtensions;
using System;
using System.Net.Sockets;
using System.Threading;
Expand All @@ -12,11 +13,10 @@ public partial class AdbServerTests
[Fact]
public async void GetStatusAsyncNotRunningTest()
{
Mock<IAdbClient> adbClientMock = new();
adbClientMock.Setup(c => c.GetAdbVersionAsync(It.IsAny<CancellationToken>()))
.Throws(new AggregateException(new SocketException(AdbServer.ConnectionRefused)));
IAdbClient adbClientMock = Substitute.For<IAdbClient>();
adbClientMock.GetAdbVersionAsync(Arg.Any<CancellationToken>()).Throws(new AggregateException(new SocketException(AdbServer.ConnectionRefused)));

AdbServer adbServer = new(adbClientMock.Object, adbCommandLineClientFactory);
AdbServer adbServer = new(adbClientMock, adbCommandLineClientFactory);

AdbServerStatus status = await adbServer.GetStatusAsync();
Assert.False(status.IsRunning);
Expand Down
10 changes: 5 additions & 5 deletions AdvancedSharpAdbClient.Tests/AdbServerTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using AdvancedSharpAdbClient.Exceptions;
using Moq;
using NSubstitute;
using NSubstitute.ExceptionExtensions;
using System;
using System.Net;
using System.Net.Sockets;
Expand Down Expand Up @@ -36,11 +37,10 @@ public AdbServerTests()
[Fact]
public void GetStatusNotRunningTest()
{
Mock<IAdbClient> adbClientMock = new();
adbClientMock.Setup(c => c.GetAdbVersion())
.Throws(new SocketException(AdbServer.ConnectionRefused));
IAdbClient adbClientMock = Substitute.For<IAdbClient>();
adbClientMock.GetAdbVersion().Throws(new SocketException(AdbServer.ConnectionRefused));

AdbServer adbServer = new(adbClientMock.Object, adbCommandLineClientFactory);
AdbServer adbServer = new(adbClientMock, adbCommandLineClientFactory);

AdbServerStatus status = adbServer.GetStatus();
Assert.False(status.IsRunning);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
<PackageReference Include="coverlet.msbuild" Version="6.0.0" PrivateAssets="all">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.0" />
<PackageReference Include="Moq" Version="4.20.69" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.1" />
<PackageReference Include="NSubstitute" Version="5.0.0" />
<PackageReference Include="xunit" Version="2.5.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0" PrivateAssets="all">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using AdvancedSharpAdbClient.Tests;
using Moq;
using NSubstitute;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
Expand All @@ -17,16 +17,16 @@ public void StatAsyncTest()
TaskCompletionSource<FileStatistics> tcs = new();
tcs.SetResult(stats);

Mock<IAdbClient> client = new();
Mock<ISyncService> mock = new();
mock.Setup(m => m.StatAsync("/test", It.IsAny<CancellationToken>())).Returns(tcs.Task);
IAdbClient client = Substitute.For<IAdbClient>();
ISyncService mock = Substitute.For<ISyncService>();
mock.StatAsync("/test", Arg.Any<CancellationToken>()).Returns(tcs.Task);

lock (FactoriesTests.locker)
{
Factories.SyncServiceFactory = (c, d) => mock.Object;
Factories.SyncServiceFactory = (c, d) => mock;

DeviceData device = new();
Assert.Equal(tcs.Task.Result, client.Object.StatAsync(device, "/test").Result);
Assert.Equal(tcs.Task.Result, client.StatAsync(device, "/test").Result);

Factories.Reset();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using AdvancedSharpAdbClient.Tests;
using Moq;
using NSubstitute;
using System.Collections.Generic;
using System.Linq;
using Xunit;
Expand All @@ -16,16 +16,16 @@ public void StatTest()
{
FileStatistics stats = new();

Mock<IAdbClient> client = new();
Mock<ISyncService> mock = new();
mock.Setup(m => m.Stat("/test")).Returns(stats);
IAdbClient client = Substitute.For<IAdbClient>();
ISyncService mock = Substitute.For<ISyncService>();
mock.Stat("/test").Returns(stats);

lock (FactoriesTests.locker)
{
Factories.SyncServiceFactory = (c, d) => mock.Object;
Factories.SyncServiceFactory = (c, d) => mock;

DeviceData device = new();
Assert.Equal(stats, client.Object.Stat(device, "/test"));
Assert.Equal(stats, client.Stat(device, "/test"));

Factories.Reset();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using AdvancedSharpAdbClient.Tests;
using Moq;
using NSubstitute;
using System;
using System.IO;
using Xunit;
Expand All @@ -14,7 +14,7 @@ public void ConstructorNullTest()
{
_ = Assert.Throws<ArgumentNullException>(() => new PackageManager(null, null));
_ = Assert.Throws<ArgumentNullException>(() => new PackageManager(null, new DeviceData()));
_ = Assert.Throws<ArgumentNullException>(() => new PackageManager(Mock.Of<IAdbClient>(), null));
_ = Assert.Throws<ArgumentNullException>(() => new PackageManager(Substitute.For<IAdbClient>(), null));
}

[Theory]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Moq;
using NSubstitute;
using System;
using System.IO;
using Xunit;
Expand All @@ -17,10 +17,10 @@ public void EnsureIsValidAdbFileNullValueTest() =>
[Fact]
public void EnsureIsValidAdbFileInvalidFileTest()
{
Mock<IAdbCommandLineClient> clientMock = new();
clientMock.Setup(c => c.IsValidAdbFile(It.IsAny<string>())).Returns(false);
IAdbCommandLineClient clientMock = Substitute.For<IAdbCommandLineClient>();
clientMock.IsValidAdbFile(Arg.Any<string>()).Returns(false);

IAdbCommandLineClient client = clientMock.Object;
IAdbCommandLineClient client = clientMock;

_ = Assert.Throws<FileNotFoundException>(() => client.EnsureIsValidAdbFile("xyz.exe"));
}
Expand Down