Hi
I have a function:
Public Function UpdatePasswordHistory(ByVal mods As DataSource, ByVal StaffCode As String, ByVal Password As String) As Integer
Dim strSQl As New StringBuilder("Insert into [dbo].[PasswordHistory]([StaffCode],[Password],[DateSet])")
strSQl.Append($"values('{StaffCode}','{EncryptPassword(UCase(Password))}','{System.DateTime.Today.ToString("yyyy-MM-dd")}')")
Return mods.SqlDB.ExecuteNonQuery(strSQl.ToString())
End Function
I want to create 2 tests.
The staffcode is a foreign key so must exists.
If no issues it should return 1. else 0.
My 2 tests always return 0.
I probably done this all wrong
public void UpdatePasswordHistory_Staffcodeexists()
Over the weekend Visual Studio was upgraded to 16.10.0 on our self-hosted Azure DevOps agent server. This has caused all of our unit tests that rely on the JustMock profiler to begin failing with the Exception:
Failed {METHODNAME} [6 ms]
Error Message:
Test method {NAMESPACE}.{CLASSNAME}.{METHODNAME} threw exception:
System.InvalidProgramException: Common Language Runtime detected an invalid program.
Stack Trace:
at {NAMESPACE}.{CLASSNAME}.{METHODNAME}()
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
at {NAMESPACE}.{CLASSNAME}.{METHODNAME}()
We are using JustMock R2 2021, the Telerik JustMock VSTest v.2 (v2.6.1) pipeline task, and our test projects are targeting netcore3.1.
The tests run and pass when executed locally through Visual Studio (16.10.0) Test Explorer, but fail during pipeline execution. Nothing else has changed on the agent server except for the Visual Studio upgrade that I am aware of.
Pipeline YAML:
I am new to JustMock, I try to use it in .NET5 but failed, I have seen some articles related to this kind of problem but I failed to resolve it. At the same time, I use MOQ for this project, I have tried TypeMock before but have already uninstalled.
Message:
Test method threw exception:
Telerik.JustMock.Core.ElevatedMockingException: Cannot mock 'BitCoinLib.Database.Connection'. The profiler must be enabled to mock, arrange or execute the specified target.
Detected active third-party profilers:
* {324F817A-7420-4E6D-B3C1-143FBED6D855} (from process environment)
Disable the profilers or link them from the JustMock configuration utility. Restart the test runner and, if necessary, Visual Studio after linking.
Stack Trace:
ProfilerInterceptor.ThrowElevatedMockingException(MemberInfo member)
MocksRepository.InterceptStatics(Type type, MockCreationSettings settings, Boolean mockStaticConstructor)
<>c__DisplayClass67_0.<SetupStatic>b__0()
ProfilerInterceptor.GuardInternal(Action guardedAction)
Mock.SetupStatic(Type staticType, StaticConstructor staticConstructor)
Hi,
I have been using Justmock for years now without any problem. But lately we started running as our normal users and not as local administrators on our PC's.
When installing Justmock I'm using an elevated admin account and it seems to complete without any errors, afterwards I'm starting VS19 as my normal user and are presented with the dialog shown in the attached file.
The log shows that the assembly could not be found or loaded, when looking in the folder specified in the error, I do not have an <extensions> folder at the location. So I assume that installing the product with my administrator access does not work for my normal user, what to do?
The activity log shows the following error:
690 ERROR CreateInstance failed for package [JustMockPackage]Source: 'mscorlib' Description: Filen eller assemblyen 'file:///c:\users\foobar\appdata\local\microsoft\visualstudio\16.0_4cd0081b\extensions\alz4b0wd.jii\Telerik.JustMock.VS2017.dll' eller en af dens afhængigheder kunne ikke indlæses. Den angivne fil blev ikke fundet. System.IO.FileNotFoundException: Filen eller assemblyen 'file:///c:\users\foobar\appdata\local\microsoft\visualstudio\16.0_4cd0081b\extensions\alz4b0wd.jii\Telerik.JustMock.VS2017.dll' eller en af dens afhængigheder kunne ikke indlæses. Den angivne fil blev ikke fundet. File name: 'file:///c:\users\foobar\appdata\local\microsoft\visualstudio\16.0_4cd0081b\extensions\alz4b0wd.jii\Telerik.JustMock.VS2017.dll'at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)at System.Reflection.RuntimeAssembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, Boolean suppressSecurityChecks, StackCrawlMark& stackMark)at System.Reflection.Assembly.LoadFrom(String assemblyFile, Evidence securityEvidence)at System.Activator.CreateInstanceFromInternal(String assemblyFile, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityInfo)at System.AppDomain.CreateInstanceFrom(String assemblyFile, String typeName) WRN: Logføring af assemblybinding er deaktiveret. Logføring af assemblybindingsfejl aktiveres ved at angive registreringsdatabaseværdien [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) til 1. Bemærk! Ydeevnen forringes ved logføring af assemblybindingsfejl. Denne funktion deaktiveres ved at fjerne registreringsdatabaseværdien [HKLM\Software\Microsoft\Fusion!EnableLog]. {0A72E70C-4C0C-4EF0-8212-59ACF681F885} 80004005 - E_FAIL VisualStudio 2020/11/05 06:41:35.043
Hello!
I have an interesting problem I am trying to solve unit testing Sitecore. I have wrapped myController to get to a dynamic accessor and I am getting an exception way down in the mscorplib System.DefaultBinder. Looking for leads on what I am missing on my setup?
Exception:
System.ArgumentException: Array may not be empty.
Parameter name: match
Code:
var controllerAccessor = Mock.NonPublic.Wrap(_myController);
Mock.NonPublic.Arrange<IMyParameters>(controllerAccessor.GetRenderingParameters<IMyParameters>()).Returns(_myParameters);
Stack trace:
at System.DefaultBinder.BindToMethod(BindingFlags bindingAttr, MethodBase[] match, Object[]& args, ParameterModifier[] modifiers, CultureInfo cultureInfo, String[] names, Object& state)
at Telerik.JustMock.Core.MockingUtil.BindToMethod(BindingFlags bindingAttr, MethodBase[] match, Object[]& args, ParameterModifier[] modifiers, CultureInfo culture, String[] names, Object& state)
at Telerik.JustMock.PrivateAccessor.ResolveProperty(Type type, String name, Boolean ignoreCase, Object[] indexArgs, Boolean hasInstance, Object setterValue, Boolean getter)
at Telerik.JustMock.Expectations.DynaMock.ExpressionRecorder.DoBindGetMember(Type returnType, String memberName, Boolean ignoreCase)
at Telerik.JustMock.Expectations.DynaMock.ExpressionRecorder.BindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args)
at System.Dynamic.InvokeMemberBinder.Bind(DynamicMetaObject target, DynamicMetaObject[] args)
at System.Dynamic.DynamicMetaObjectBinder.Bind(Object[] args, ReadOnlyCollection`1 parameters, LabelTarget returnLabel)
at System.Runtime.CompilerServices.CallSiteBinder.BindCore[T](CallSite`1 site, Object[] args)
at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0)
at <my code line Mock.NonPublic.Arrange<IMyParameters>(controllerAccessor.GetRenderingParameters<IMyParameters>()).Returns(_myParameters)>
System.DefaultBinder code snippet:
// Decompiled with JetBrains decompiler
// Type: System.DefaultBinder
// Assembly: mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
// MVID: CACD6C6A-C61D-45CD-B58B-92E86EE53F52
// Assembly location: C:\Windows\Microsoft.NET\Framework\v4.0.30319\mscorlib.dll
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Globalization;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
namespace System
{
[Serializable]
internal class DefaultBinder : Binder
{
[SecuritySafeCritical]
public override MethodBase BindToMethod(
BindingFlags bindingAttr,
MethodBase[] match,
ref object[] args,
ParameterModifier[] modifiers,
CultureInfo cultureInfo,
string[] names,
out object state)
{
MethodBase[] methodBaseArray = match != null && match.Length != 0 ? (MethodBase[]) match.Clone() : throw new ArgumentException(Environment.GetResourceString("Arg_EmptyArray"), nameof (match));
etc etc
}
using
Telerik.JustMock;
using
Xunit;
namespace
XUnitTestProject1
{
public
interface
IMyInterface
{
bool
SomeCheck() =>
false
;
}
public
class
UnitTest1
{
[Fact]
public
void
Test1()
{
var mock = Mock.Create<IMyInterface>();
Mock.Arrange(() => mock.SomeCheck()).Returns(
true
);
Assert.True(mock.SomeCheck());
}
}
}