Skip to content

Commit

Permalink
ShouldGetAssembly -> FAIL
Browse files Browse the repository at this point in the history
  • Loading branch information
LBoullosa committed May 23, 2024
1 parent 2726cad commit 438aee8
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// ----------------------------------------------------------------------------------
// Copyright (c) The Standard Organization: A coalition of the Good-Hearted Engineers
// ----------------------------------------------------------------------------------

using System;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using FluentAssertions;
using Moq;

namespace STX.SPAL.Core.Tests.Unit.Services.Foundations.Assemblies
{
public partial class AssemblyServiceTests
{
[Fact]
private async Task ShouldGetAssembly()

Check warning on line 18 in STX.SPAL.Core.Tests.Unit/Services/Foundations/Assemblies/AssemblyServiceTests.Logic.GetAssembly.cs

View workflow job for this annotation

GitHub Actions / build

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 18 in STX.SPAL.Core.Tests.Unit/Services/Foundations/Assemblies/AssemblyServiceTests.Logic.GetAssembly.cs

View workflow job for this annotation

GitHub Actions / build

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
// given
Assembly randomAssembly = CreateRandomAssembly();
Assembly expectedAssembly = randomAssembly;
Assembly returnedAssembly = randomAssembly;
string randomPathAssembly = GetRandomPathAssembly();
string inputPathAssembly = randomPathAssembly;

this.assemblyBroker
.Setup(broker =>
broker.GetAssembly(
It.Is<string>(actualPathAssembly =>
actualPathAssembly == inputPathAssembly)))
.Returns(returnedAssembly);

// when
Assembly actualAssembly =
this.assemblyService.GetAssembly(inputPathAssembly);

//then
actualAssembly.Should().BeSameAs(expectedAssembly);

this.assemblyBroker.Verify(
broker =>
broker.GetAssembly(
It.Is<string>(actualPathAssembly =>
actualPathAssembly == inputPathAssembly)),
Times.Once);

this.assemblyBroker.VerifyNoOtherCalls();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using Moq;
using STX.SPAL.Core.Brokers.Assemblies;
using STX.SPAL.Core.Services.Foundations.Assemblies;
Expand All @@ -30,17 +32,33 @@ private static string GetRandomString() =>
private static int GetRandomNumber() =>
new IntRange(min: 2, max: 10).GetValue();

private static string GetRandomPathAssembly()
{
string randomPathName = GetRandomString();
string randomFileName = GetRandomString();

return $"{Path.Combine(randomPathName, randomFileName)}.dll";
}

private static string[] CreateRandomPathArray()
{
return Enumerable.Range(0, GetRandomNumber())
.Select(i =>
{
string randomPathName = GetRandomString();
string randomFileName = GetRandomString();

return $"{Path.Combine(randomPathName, randomFileName)}.dll";
})
.Select(i => GetRandomPathAssembly())
.ToArray();
}

private static Assembly CreateRandomAssembly()
{
string randomAssemblyName = GetRandomString();
var assemblyName =
new AssemblyName("randomAssemblyName");

AssemblyBuilder assemblyBuilder =
AssemblyBuilder.DefineDynamicAssembly(
assemblyName,
AssemblyBuilderAccess.Run);

return assemblyBuilder;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// ----------------------------------------------------------------------------------

using System;
using System.Reflection;
using STX.SPAL.Core.Brokers.Assemblies;

namespace STX.SPAL.Core.Services.Foundations.Assemblies
Expand All @@ -18,5 +19,8 @@ public AssemblyService(IAssemblyBroker assemblyBroker)

public string[] GetApplicationPathsAssemblies() =>
this.assemblyBroker.GetApplicationPathsAssemblies();

public Assembly GetAssembly(string fullPath) =>
throw new NotImplementedException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
// Copyright (c) The Standard Organization: A coalition of the Good-Hearted Engineers
// ----------------------------------------------------------------------------------

using System.Reflection;

namespace STX.SPAL.Core.Services.Foundations.Assemblies
{
internal interface IAssemblyService
{
string[] GetApplicationPathsAssemblies();
Assembly GetAssembly(string fullPath);
}
}

0 comments on commit 438aee8

Please sign in to comment.