ERROR: Method not found: 'Void System.AppDomainSetup.set_ApplicationBase(System.String)'
PHuhn opened this issue · 1 comments
Test Code
[Test()]
public async Task EmailConfirmation_Page_Test()
{
// given
Smock.Run(async context =>
{
EmailTestPageModel _testConfirmation = new EmailTestPageModel(userManager, _emailSender.Object);
_testConfirmation.PageContext = MockHelpers.CreatePageContext(NSG_Helpers.User_Name2, "User", "/Register/", "/Account");
context.Setup(() => UrlHelperExtensions.Page(It.IsAny<IUrlHelper>(), "/Account/ConfirmEmail", null, It.IsAny<object>(), It.IsAny<string>())).Returns("https://localhost/Account/ConfirmEmail/");
// when
IActionResult _results = await _testConfirmation.OnPostAsync();
// then
Assert.AreEqual(_results, "https://localhost/Account/ConfirmEmail");
});
}
Error Message
Message:
System.MissingMethodException : Method not found: 'Void System.AppDomainSetup.set_ApplicationBase(System.String)'.
Stack Trace:
AppDomainContext.ctor(IAssemblyLoaderFactory assemblyLoaderFactory, ISerializer serializer, Logger logger, ISerializableLambdaFilter[] lambdaFilters)
AppDomainContext.ctor(IAssemblyRewriter assemblyRewriter, Logger logger)
Smock.RunAction(Action1 action, Configuration configuration) Smock.Run(Configuration configuration, Action
1 action)
Smock.Run(Action1 action) EmailConfirmation_UnitTests.EmailConfirmation_Page_Test() line 59 GenericAdapter
1.GetResult()
AsyncToSyncAdapter.Await(Func`1 invoke)
TestMethodCommand.RunTestMethod(TestExecutionContext context)
TestMethodCommand.Execute(TestExecutionContext context)
<>c__DisplayClass1_0.b__0()
BeforeAndAfterTestCommand.RunTestMethodInThreadAbortSafeZone(TestExecutionContext context, Action action)
Error Occurs
The error occurs on the execution of the first line:
Smock.Run(async context =>
You Say
Strong-named assemblies
To intercept calls to targeted methods and properties, Smocks rewrites assemblies and subsequently loads the modified copies. Should the original assembly be strong-named, the assembly will need to be signed again after modification to restore the strong-naming. Smocks currently does not support rewriting strong-named assemblies.
Assumption
This is the first time I have used SMocks and I am assuming that the above is from Microsoft strongly named assemblies.
Seeing the same Issue. using .net core 3.1 I believe that Smocks is not fully compatible with .net core because the nugget package error indicates that it's targeting .net framework 4.7. Can you confirm that this is the issue.
code:
Smock.Run(async context =>
{
Mock<ILogger<PropertySetRepository>> loggerMock = new Mock<ILogger<PropertySetRepository>>();
Mock<ISqlServerDatabase> sqlServerDatabaseMock = new Mock<ISqlServerDatabase>();
PropertySetRepository prop = new PropertySetRepository(sqlServerDatabaseMock.Object, loggerMock.Object);
var storedProc = "[dbo].[GetAuditHistoryApprovalsByPropertySetId]";
IStoredProcedure procedure = new InlineStoredProcedure(storedProc)
{
{ "PropertySetId", 1234 }
};
IReadOnlyList<ApprovalModel> approvals = new List<ApprovalModel>();
context.Setup(() => sqlServerDatabaseMock.Object.ExtractAsync(procedure, new ApprovalExtractor(), CancellationToken.None)).Returns(Task.FromResult(approvals));
//sqlServerDatabaseMock.Setup(t => t.ExtractAsync(procedure, new ApprovalExtractor(), CancellationToken.None));
var res = prop.GetCompSetAuditHistoryApprovals(1234);
});
stack trace:
at Smocks.AppDomains.AppDomainContext..ctor(IAssemblyLoaderFactory assemblyLoaderFactory, ISerializer serializer, Logger logger, ISerializableLambdaFilter[] lambdaFilters)
at Smocks.AppDomains.AppDomainContext..ctor(IAssemblyRewriter assemblyRewriter, Logger logger)
at Smocks.Smock.RunAction(Action`1 action, Configuration configuration)
at Smocks.Smock.Run(Configuration configuration, Action`1 action)
at Smocks.Smock.Run(Action`1 action)
at PropertySetData.Tests.Repositories.PropertySetRepositoryTest.a() in C:\Users\cjohnson2\source\repos\services-external-hospitality-property-set-api\Source\tests\PropertySetData.Tests\Repositories\PropertySetRepository.cs:line 25