Skip to content

Commit

Permalink
Delete Moq and replace the Mocks with our own (#220)
Browse files Browse the repository at this point in the history
* Delete Moq and replace the Mocks with our own

* Update out of date documentation and give more examples

* dotnet format
  • Loading branch information
CorruptComputer authored Nov 26, 2023
1 parent 576f119 commit 54cf525
Show file tree
Hide file tree
Showing 25 changed files with 344 additions and 220 deletions.
5 changes: 1 addition & 4 deletions UnitystationLauncher.Tests/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// Global using directives

global using System;
global using FluentAssertions;
global using Xunit;
global using Moq;
global using Xunit;
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Collections.Generic;
using UnitystationLauncher.Models.Api.Changelog;
using UnitystationLauncher.Services.Interface;

namespace UnitystationLauncher.Tests.MocksRepository.BlogService;

public class MockBlogPostsThrowException : IBlogService
{
public List<BlogPost> GetBlogPosts(int count)
{
throw new();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.Collections.Generic;
using UnitystationLauncher.Models.Api.Changelog;
using UnitystationLauncher.Services.Interface;

namespace UnitystationLauncher.Tests.MocksRepository.BlogService;

public class MockNormalBlogPosts : IBlogService
{
public List<BlogPost> GetBlogPosts(int count)
{
List<BlogPost> blogPosts = new();

for (int i = 0; i < count; i++)
{
blogPosts.Add(new()
{
Title = $"Test {i}",
Slug = $"test-{i}",
ImageUrl = $"test-{i}.png"
});
}

return blogPosts;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.Diagnostics;
using UnitystationLauncher.Models.Enums;
using UnitystationLauncher.Services.Interface;

namespace UnitystationLauncher.Tests.MocksRepository.EnvironmentService;

public class MockLinuxFlatpakEnvironment : IEnvironmentService
{
public CurrentEnvironment GetCurrentEnvironment()
{
return CurrentEnvironment.LinuxFlatpak;
}

public string GetUserdataDirectory()
{
return "/home/unitTester/UnitystationLauncher";
}

public bool ShouldDisableUpdateCheck()
{
return true;
}

public ProcessStartInfo? GetGameProcessStartInfo(string executable, string arguments)
{
throw new NotImplementedException();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.Diagnostics;
using UnitystationLauncher.Models.Enums;
using UnitystationLauncher.Services.Interface;

namespace UnitystationLauncher.Tests.MocksRepository.EnvironmentService;

public class MockLinuxStandaloneEnvironment : IEnvironmentService
{
public CurrentEnvironment GetCurrentEnvironment()
{
return CurrentEnvironment.LinuxStandalone;
}

public string GetUserdataDirectory()
{
return "/home/unitTester/UnitystationLauncher";
}

public bool ShouldDisableUpdateCheck()
{
return false;
}

public ProcessStartInfo? GetGameProcessStartInfo(string executable, string arguments)
{
throw new NotImplementedException();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.Diagnostics;
using UnitystationLauncher.Models.Enums;
using UnitystationLauncher.Services.Interface;

namespace UnitystationLauncher.Tests.MocksRepository.EnvironmentService;

public class MockMacOsStandaloneEnvironment : IEnvironmentService
{
public CurrentEnvironment GetCurrentEnvironment()
{
return CurrentEnvironment.MacOsStandalone;
}

public string GetUserdataDirectory()
{
return "/home/unitTester/UnitystationLauncher";
}

public bool ShouldDisableUpdateCheck()
{
return false;
}

public ProcessStartInfo? GetGameProcessStartInfo(string executable, string arguments)
{
throw new NotImplementedException();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.Diagnostics;
using UnitystationLauncher.Models.Enums;
using UnitystationLauncher.Services.Interface;

namespace UnitystationLauncher.Tests.MocksRepository.EnvironmentService;

public class MockWindowsStandaloneEnvironment : IEnvironmentService
{
public CurrentEnvironment GetCurrentEnvironment()
{
return CurrentEnvironment.WindowsStandalone;
}

public string GetUserdataDirectory()
{
return "C:/Users/UnitTester/UnitystationLauncher";
}

public bool ShouldDisableUpdateCheck()
{
return false;
}

public ProcessStartInfo? GetGameProcessStartInfo(string executable, string arguments)
{
throw new NotImplementedException();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System.Collections.Generic;
using UnitystationLauncher.Models;
using UnitystationLauncher.Models.Api;
using UnitystationLauncher.Services.Interface;

namespace UnitystationLauncher.Tests.MocksRepository.InstallationService;

public class MockNoActiveDownloads : IInstallationService

Check failure on line 8 in UnitystationLauncher.Tests/MocksRepository/InstallationService/MockNoActiveDownloads.cs

View workflow job for this annotation

GitHub Actions / test

'MockNoActiveDownloads' does not implement interface member 'IInstallationService.DownloadInstallation(Server)'. 'MockNoActiveDownloads.DownloadInstallation(Server)' cannot implement 'IInstallationService.DownloadInstallation(Server)' because it does not have the matching return type of 'Task<(Download?, string)>'.
{
public List<Installation> GetInstallations()
{
throw new NotImplementedException();
}

public Installation? GetInstallation(string forkName, int buildVersion)
{
return null;
}

public Download? GetInProgressDownload(string forkName, int buildVersion)
{
return null;
}

public (Download?, string) DownloadInstallation(Server server)
{
throw new NotImplementedException();
}

public (bool, string) StartInstallation(Guid installationId, string? server = null, short? port = null)
{
throw new NotImplementedException();
}

public (bool, string) DeleteInstallation(Guid installationId)
{
throw new NotImplementedException();
}

public (bool, string) CleanupOldVersions(bool isAutoRemoveAction)
{
throw new NotImplementedException();
}

public bool MoveInstallations(string newBasePath)
{
throw new NotImplementedException();
}

public (bool, string) IsValidInstallationBasePath(string path)
{
throw new NotImplementedException();
}
}
37 changes: 0 additions & 37 deletions UnitystationLauncher.Tests/MocksRepository/MockBlogService.cs

This file was deleted.

This file was deleted.

This file was deleted.

32 changes: 0 additions & 32 deletions UnitystationLauncher.Tests/MocksRepository/MockPingService.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Threading.Tasks;
using UnitystationLauncher.Models.Api;
using UnitystationLauncher.Services.Interface;

namespace UnitystationLauncher.Tests.MocksRepository.PingService;

public class MockPingReturnsNull : IPingService
{
public Task<string> GetPing(Server server)
{
return Task.FromResult(null as string)!;
}
}
Loading

0 comments on commit 54cf525

Please sign in to comment.