To replicate the problem using the provided project, follow these steps:
1. Open the solution in Rider.
2. Set breakpoints at the beginning of the test.
3. Start debugging the test.
4. Step into the constructor of the Car class and inspect the contents of the array. Note that if this step is skipped, the issue will not be reproducible.
5. Step out of the constructor.
6. Continue execution until just before calling the virtual function for the Number property.
7. Step into the function.
**EXPECTED** The value of Name should be visible.
**ACTUAL** A debugger error occurs.
The issue can appear in both Visual Studio (showing "Internal error in the C# compiler") and Rider (showing "Read out of bounds").
Good morning,
Could you please give me a help in order to use JustMock to moch the HttpContext of my API controller?
I have inclosed you my code extracted from my software with the minimal code I could.
In this one, DealControllerReadByIdShouldReturnDtos works fine but unfortunately I tried for hour to make my DealControllerReadAllShouldReturnDtos test works.
Could you please help me?
In advance I thank you
Davy MANGOLD - Humrig
The test run is aborted when a .testsettings is used for executing JustMock tests. The .testsettings contains only a description.
<?xml version="1.0" encoding="UTF-8"?>
<TestSettings name="Local" id="15694c75-be1c-4113-9d42-2cbe1013c41c" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
<Description>These are default test settings for a local test run.</Description>
</TestSettings>
It seems that the usage of the MSTest element is breaking the execution.
Workaround: As .testsettings are deprecated use .runsettings instead without MSTest element.
My setup includes my local dev environment and so called "grid node" server used by NCrunch.
Yesterday I've updated JustMock to version 2025.2.520.440.
After that update I received an error mentioning my License file not to include Telerik Just Mock.
So I've updated my License file by the way mentioned in the Release Notes.
After that my NCrunch Build crashed with an TypeInitializationException "The type initializer for 'Telerik.JustMock.Core.Licensing.LicenseManager'. String was not recognized as a valid DateTime."
I've updated my License file again today and the Exception Message has changed to "String '5/20/2025' was not recognized as a valid DateTime."
I than set my local DateDime format from dd.MM.yyyy to yyyy-MM-dd and the problem is gone.
So it seems like the current version has a problem with our German / European format.
With version 2025.1.211.365 everything worked fine.
So would you please so kind to have a look onto that?
Thank you
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.
We are trying to run unit tests via xUnit and mocking method occurence using JustMockLite. Method under arrange is creating a underlying Task however, once in a while test fails with following error
build 11-May-2021 14:36:09 Telerik.JustMock.Xunit.AssertFailedException : Multiple assertion failures: build 11-May-2021 14:36:09 1. Occurrence expectation failed. Expected exactly 1 call. Calls so far: 0 build 11-May-2021 14:36:09 Arrange expression: x => x.CallAsync(IsAny(), IsAny()) build 11-May-2021 14:36:09 2. Occurrence expectation failed. Expected exactly 1 call. Calls so far: 0 build 11-May-2021 14:36:09 Arrange expression: x => x.NotifyAsync(IsAny()) build 11-May-2021 14:36:09 build 11-May-2021 14:36:09 ---- Telerik.JustMock.Diagnostics.DebugViewDetailsException : State: build 11-May-2021 14:36:09 Elevated mocking: disabled build 11-May-2021 14:36:09 build 11-May-2021 14:36:09 Arrangements and expectations: build 11-May-2021 14:36:09 Arrangement (id=0) x => x.Load(IsAny()): build 11-May-2021 14:36:09 Met: Occurences must be in [1, 1]; calls so far: 1. build 11-May-2021 14:36:09 Arrangement (id=1) x => x.InitializePolicy(IsAny(), IsAny()): build 11-May-2021 14:36:09 Met: Occurences must be in [1, 1]; calls so far: 1. build 11-May-2021 14:36:09 Arrangement (id=2) x => x.RequestBulkSync(IsAny(), IsAny(), IsAny()): build 11-May-2021 14:36:09 Met: Occurences must be in [any, 1]; calls so far: 1. build 11-May-2021 14:36:09 Arrangement (id=3) x => x.CallAsync(IsAny(), IsAny()): build 11-May-2021 14:36:09 Unmet: Occurences must be in [1, 1]; calls so far: 0. build 11-May-2021 14:36:09 Arrangement (id=4) x => x.NotifyAsync(IsAny()): build 11-May-2021 14:36:09 Unmet: Occurences must be in [1, 1]; calls so far: 0. build 11-May-2021 14:36:09 build 11-May-2021 14:36:09 Invocations:
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
Implement a new public API that will allow the developer to iterate over all invocations of mock arrangements. Something like the following:
IEnumerable<IInvocaiton> invocations = Mock.Invocations;
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.
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");
Collection mock (result from ReturnCollection clause) does not support async queries due to the unimplemented IAsyncQueryProvider interface. The issue could be easily reproduced with the following simple test:
[Fact]
public void ShouldReturnEntity()
{
var db = Mock.Create<MyModel.MyModel>();
Mock.Arrange(() => db.SomeEntities).ReturnsCollection(someEntities);
var entity = db.SomeEntities.SingleAsync(x => x.Id == 1);
Assert.NotNull(entity);
}
The outcome is the the following exception:
System.InvalidOperationException The provider for the source 'IQueryable' doesn't implement 'IAsyncQueryProvider'. Only providers that implement 'IAsyncQueryProvider' can be used for Entity Framework asynchronous operations.
This article mentions a package that can be used to very easily mock Entity Framework types (mainly DbContext). However, this package only works for Entity Framework 6, and not Entity Framework Core, which my project uses. I would love to see this package updated to greatly simplify unit testing for my project.
I'm specifically looking to mock the following types: IDbContextFactory, my subclass of DbContext, and DbSet. All of this is currently possible of course with the standard JustMock interface but it's a hassle.