We're using this DevOps task in our pipeline, however since yesterday we get the following warning:
##[warning]Task 'Telerik JustMock VSTest v.2' version 2 (JustMockVSTest@2) is dependent on a Node version (6) that is end-of-life. Contact the extension owner for an updated version of the task. Task maintainers should review Node upgrade guidance: https://aka.ms/node-runner-guidance
We're running it using a build agent hosted at the Azure DevOps cloud.
Hi.
i saw this: https://www.telerik.com/forums/how-can-i-mock-multiple-instances-of-a-struct
but still dont understand why JustMock works that way in the first place. why does it union struct mocks by value?
the above solution is only possible when i mock a struct i can change (and then add the id to it) but what about struct's from the framework that i cannot control? Is there a way to tell JustMock not to union mock structs?
Thanks,
Yosi
The issue is about interoperability between JustMock and AutoFixture. The unit test run can be 90% faster if all the fixtures are created before the JustMock arrangements.
Here is a sample code that figures out the issue:
[Fact]
public void Slow
{
var fixture = new Fixture():
var items1 = fixture.Create<List<Item>>();
Nock.Arrange(() => ItemsRepository.GetItems1()).Returns(items1);
var items2 = fixture.Create<List<Item>>();
Nock.Arrange(() => ItemsRepository.GetItems2()).Returns(items2);
var items3 = fixture.Create<List<Item>>();
Nock.Arrange(() => ItemsRepository.GetItems3()).Returns(items3);
var items4 = fixture.Create<List<Item>>();
Nock.Arrange(() => ItemsRepository.GetItems4()).Returns(items4);
}
[Fact]
public void Fast()
{
var fixture = new Fixture():
var items1 = fixture.Create<List<Item>>();
var items2 = fixture.Create<List<Item>>();
var items3 = fixture.Create<List<Item>>();
var items4 = fixture.Create<List<Item>>();
Nock.Arrange(() => ItemsRepository.GetItems1()).Returns(items1);
Nock.Arrange(() => ItemsRepository.GetItems2()).Returns(items2);
Nock.Arrange(() => ItemsRepository.GetItems3()).Returns(items3);
Nock.Arrange(() => ItemsRepository.GetItems4()).Returns(items4);
}
The test duration should not be dependent on the exact implementation.
Dear Telerik team,
It is nice to have a way to generate mocks.
But it is annoying to have lots of those messages for references in XML comments. I had to turn the feature off. Which might be the case for other customers too.
Maybe you want to have a look into it.
JustMock interprets anonymous types as tuples. The sample below demonstrates the issue:
public interface IAnsweringService
{
(int code, string desc) GetAnswer(string question);
}
[TestMethod]
public void AnswerToTheUniverseQuestionTest()
{
var apiMock = Mock.Create<IAnsweringService>();
var expectedAnswer = new { code = 42, desc = "Answer to the Ultimate Question of Life" };
Mock.Arrange(() => apiMock.GetAnswer(Arg.AnyString)).Returns(expectedAnswer);
var actualAnswer = apiMock.GetAnswer("What is a universe question answer?");
Assert.AreEqual(expectedAnswer.code, actualAnswer.code);
Assert.AreEqual(expectedAnswer.desc, actualAnswer.desc);
}
Telerik.JustMock.Core.MockException: The chained return value type '<>f__AnonymousType1`2[System.Int32,System.String]' is not compatible with the arranged method's return type 'System.ValueTuple`2[System.Int32,System.String]'
The following code snippet causes a hang in the test execution while being debugged:
Mock.SetupStatic(typeof(TimeSpan), Behavior.CallOriginal, StaticConstructor.NonMocked);
Mock.Arrange(() => TimeSpan.FromSeconds(15)).Returns(TimeSpan.MinValue);
The issue can be temporary solved by disabling the DebugWindow via JustMock extension menu.
Hello
I generate a syntax tree which I will format with Formatter.Format() from the package Microsoft.CodeAnalysis.CSharp.Workspaces 4.4.0 and .NET 6. A test exists where the formatter is used but when the JustMock profiler is enabled an InvalidProgramException is thrown. When the profiler is disabled everything works fine. It fails on Windows and on Linux.
Message: 
System.InvalidProgramException : Common Language Runtime detected an invalid program.
Stack Trace: 
ContextIntervalTree`2.ctor(TIntrospector& introspector)
FormattingContext.ctor(AbstractFormatEngine engine, TokenStream tokenStream)
AbstractFormatEngine.CreateFormattingContext(TokenStream tokenStream, CancellationToken cancellationToken)
AbstractFormatEngine.Format(CancellationToken cancellationToken)
CSharpSyntaxFormatting.Format(SyntaxNode node, SyntaxFormattingOptions options, IEnumerable`1 formattingRules, SyntaxToken startToken, SyntaxToken endToken, CancellationToken cancellationToken)
AbstractSyntaxFormatting.GetFormattingResult(SyntaxNode node, IEnumerable`1 spans, SyntaxFormattingOptions options, IEnumerable`1 rules, CancellationToken cancellationToken)
Formatter.GetFormattingResult(SyntaxNode node, IEnumerable`1 spans, Workspace workspace, OptionSet options, IEnumerable`1 rules, CancellationToken cancellationToken)
Formatter.Format(SyntaxNode node, IEnumerable`1 spans, Workspace workspace, OptionSet options, IEnumerable`1 rules, CancellationToken cancellationToken)
Formatter.Format(SyntaxNode node, Workspace workspace, OptionSet options, CancellationToken cancellationToken)
UnitTest1.Test1() line 23
You can reproduce this by writing an unit test for that (I used xUnit):
[Fact]
public void Test1()
{
var classText = @"using System; namespace TestNameSpace.Orders { public class Order
{
public Guid Id { get; set; }
}
}";
var syntaxTree = CSharpSyntaxTree.ParseText(classText);
var workspace = new AdhocWorkspace();
var formattedClassText = Formatter.Format(syntaxTree.GetRoot(), workspace).ToFullString();
var expected = @"using System;
namespace TestNameSpace.Orders
{
public class Order
{
public Guid Id { get; set; }
}
}";
Assert.Equal(expected, formattedClassText);
}
}
See attachments. We do not use the free edition.
dotnet --info
.NET SDK:
Version: 7.0.200
Commit: 534117727b
Runtime Environment:
OS Name: Windows
OS Version: 10.0.19045
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\7.0.200\
Host:
Version: 7.0.3
Architecture: x64
Commit: 0a2bda10e8
.NET SDKs installed:
6.0.406 [C:\Program Files\dotnet\sdk]
7.0.200 [C:\Program Files\dotnet\sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 6.0.14 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.14 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 6.0.14 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Other architectures found:
x86 [C:\Program Files (x86)\dotnet]
registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]
Environment variables:
Not set
global.json file:
Not found
Learn more:
https://aka.ms/dotnet/info
Download .NET:
https://aka.ms/dotnet/download
Considering the following simple test scenario:
public abstract class TestBase
{
public static TestContext TestContext { get; set; }
}
[TestClass]
public class UnitTest1 : TestBase
{
[ClassInitialize]
public static void ClassInitlialize(TestContext ctx)
{
TestContext = ctx;
}
[TestMethod]
public void TestMethod1()
{
}
}
[TestClass]
public class UnitTest2 : TestBase
{
[ClassInitialize]
public static void ClassInitlialize(TestContext ctx)
{
TestContext = ctx;
}
[TestMethod]
public void TestMethod1()
{
}
}
Attempt to run the tests above with JustMock profiler enabled fails with System.InvalidProgramException. The issue is not reproducible with MSTest.TestFramework and MSTest.TestAdapter packages prior to 3.0.x.
The issue is demonstrated with the following sample:
[Theory]
[MemberData(nameof(GetMemberDataContext))]
public void ValidParameters_Success(int param1, int param2)
{
// Arrange
Mock.SetupStatic(typeof(MyClass), Behavior.Strict, StaticConstructor.Mocked);
Mock.Arrange(() => MyClass.method1()).Returns(true);
// Act
IService service = new Service();
bool result = service.method2();
// Assert
Assert.True(result);
Mock.Assert(() => MyClass.method1(), Occurs.Once()); // <-- the test fails here because it reports that method invocation occurs twice
}
The issue in not observed if the code is modified in the following way, which indicates behavioral incinsistency:
[Theory]
[MemberData(nameof(GetMemberDataContext))]
public void ValidParameters_Success(int param1, int param2)
{
// Arrange
Mock.SetupStatic(typeof(MyClass), Behavior.Strict, StaticConstructor.Mocked);
Mock.Arrange(() => MyClass.method1()).Returns(true).OccursOnce();
// Act
IService service = new Service();
bool result = service.method2();
// Assert
Assert.True(result);
Mock.Assert<MyClass>();
}
The threading model of UI apps differs from the test host and this might become a source of issues like the following: System.InvalidOperationException: "The calling thread must be STA, because many UI components require this". The request is about extending JustMock with some helpers that can be used to solve this issue easily.