Unplanned
Last Updated: 23 Apr 2024 13:34 by Ivo
Created by: Ivo
Comments: 0
Type: Bug Report
1

With R3 2023 (2023.3.1011.155) JustMock introduces a new functionality that might lead to a huge performance drop and event to unexpected failures. Currently, the issue could be suppressed by setting up an environment variable JUSTMOCK_NEWOBJ_INTERCEPTION_ON_OVERWRITE_ENABLED to 0 (the default value is 1), but a more reliable and independent solution should be found.

Unplanned
Last Updated: 26 Feb 2024 23:58 by David

if you use the C# using declaration and have JustMock advanced (elevated) mode enabled, the runtime will throw an InvalidProgramException.

Find below the sample code that demonstrates the issue:

public class TestClass : IDisposable
{
    public void Dispose()
    {
    }
}

[TestClass]
public class Fixture
{
    public interface ITest { }

    [TestMethod]
    public async Task Test()
    {
        ITest mock = Mock.Create<ITest>();
        using TestClass test = new();
    }
}

Unplanned
Last Updated: 08 Feb 2024 18:32 by Ivo

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.

Unplanned
Last Updated: 05 Feb 2024 13:46 by Christian
When mock generation is enabled and a mock code ends with unfinished Return setup VB compiler get into a broken state. Once in broken state the user has to manually build the code or go back in code editor in order to get into correct state.
Unplanned
Last Updated: 03 Jan 2024 10:13 by Drew
Created by: Drew
Comments: 0
Type: Feature Request
1

There are no ReturnsAsync methods for mocking container async methods.

There should be a set of methods to mock async methods of a container similar to regular object mocking.

As a user I should be able to write code like:

 

container.Arrange<IContainer>(r => r.SomeAsyncMethod("data")).ReturnsAsync("returnValue");

Unplanned
Last Updated: 30 Nov 2023 08:54 by Christian
This request is about making feature parity with the existing functionality that currently supports C#.
Unplanned
Last Updated: 04 Oct 2023 06:56 by Davy
Created by: Davy
Comments: 0
Type: Feature Request
0

Provide support for .NET MAUI projects. 

Let me explain in details the current situation:

I have Unit Test project using JustMock and running into a problem. It seems like JustMock is using the wrong version number to locate the SDK. let me explain:

The project is set to: <TargetFramework>net7.0</TargetFramework>

But it also has <UseMaui>true</UseMaui> enabled

I am getting the following error:

"Framework: 'Microsoft.Maui.Core', version '7.0.92' (x64)
.NET location: C:\Program Files\dotnet
No frameworks were found.

That 7.0.92 version is only for the MAUI workload version, not the SDK versions. It seems JustMock uses a workload version as a SDK version. 

Unplanned
Last Updated: 27 Jun 2023 09:47 by Ivo
Created by: Ivo
Comments: 0
Type: Feature Request
1
In-Assembly Parallel (IAP) significantly reduces the time for test execution, but currently JustMock does not support it.
Unplanned
Last Updated: 23 Jun 2023 09:42 by ADMIN

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.


Unplanned
Last Updated: 10 May 2023 08:22 by ADMIN
ADMIN
Created by: Kamen Ivanov
Comments: 3
Type: Feature Request
5

			
Unplanned
Last Updated: 25 Apr 2023 15:53 by Ivo
Created by: Ivo
Comments: 0
Type: Feature Request
1

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);
}
The test fails with error:

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]'

Unplanned
Last Updated: 19 Apr 2023 09:59 by Ivo
Created by: Ivo
Comments: 0
Type: Feature Request
0
The DoInstead API cannot be used in scenarios that require the method call arguments to be captured and a specific return value to be provided.
Unplanned
Last Updated: 13 Apr 2023 08:40 by Ivo

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. 

Unplanned
Last Updated: 15 Mar 2023 06:42 by Quoc Tin

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.

Exception

  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

Reproduction

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);
        }
    }

System Info

JustMock

See attachments. We do not use the free edition.

.NET

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

 

I already posted a question but can't delete it anymore: InvalidProgramException thrown when formatting SyntaxNodes in JustMock | Telerik Forums
Unplanned
Last Updated: 25 Jan 2023 10:55 by Ivo

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.

 

Unplanned
Last Updated: 11 Jan 2023 11:08 by Ivo

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>();
}
 

Unplanned
Last Updated: 03 Jan 2023 16:56 by ADMIN
Created by: Mihail
Comments: 2
Type: Feature Request
1
Consider the scenario where a class has a string field which is his main data. This class has defined an implicit cast operator to string. When that cast operator is executed the resulted string will contain the value from the class field.

Implement support for mocking of an operator such as the one described. 
Unplanned
Last Updated: 10 Nov 2022 09:40 by Ivo
Mocking of these methods could not be made due to compiler (CS8175) or runtime (System.InvalidProgramException: Cannot create boxed ByRef-like values) errors.
Unplanned
Last Updated: 01 Sep 2022 07:21 by ADMIN
Created by: Mihail
Comments: 1
Type: Feature Request
1
Integration with dotCover is only available through Telerik.JustMock.Configuration.exe, which works with the machine's registry and needs JustMock to be installed. This approach is not applicable to cloud-based build agents and therefore we need an integration that does not require the installation of JustMock.
Unplanned
Last Updated: 04 Jul 2022 11:41 by Ivo
Created by: Ivo
Comments: 0
Type: Feature Request
1

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.

1 2 3