This is a migrated thread and some comments may be shown as answers.

Mock interfaces with default implementations

3 Answers 302 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
GiZ
Top achievements
Rank 1
GiZ asked on 16 Sep 2020, 09:13 AM
Visual Studio Professional 2019 16.6.5
JustMock 2020.2.616.1
.Net Core 3.1

How can I mock an interface with default implementations? The following test fails:

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

3 Answers, 1 is accepted

Sort by
0
Ivo
Telerik team
answered on 18 Sep 2020, 02:37 PM

Hello Gian,

I am afraid that JustMock is still not supporting this C# language feature. After making quick research on this topic it turns out that mocking fails in elevated mode (using profiler), otherwise - works as expected. In order to continue investigations, I have created a feature request in our Feedback portal. Subscribing to it will keep you posted for status updates.

I would like to apologize for the inconvenience and hope that we manage to implement this feature soon.

Regards,
Ivo
Progress Telerik

Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive, special prizes, and more, for FREE?! Register now for DevReach 2.0(20).

0
GiZ
Top achievements
Rank 1
answered on 21 Sep 2020, 08:15 AM
Hi Ivo
Thank you for your reply. I see, I didn't test it without elevated mode. Is there a way to disable elevated mode for certain tests only?

0
Ivo
Telerik team
answered on 21 Sep 2020, 12:51 PM

Hello Gian,

There is no option to disable elevated mode programmicaly and it is by design. Of course we could take into consideration some improvements in this directection, so this will bring a better control over test execution.

Regards,
Ivo
Progress Telerik

Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive, special prizes, and more, for FREE?! Register now for DevReach 2.0(20).

Tags
General Discussions
Asked by
GiZ
Top achievements
Rank 1
Answers by
Ivo
Telerik team
GiZ
Top achievements
Rank 1
Share this question
or