Telerik Forums
JustMock Forum
3 answers
114 views

Hi

I try to fake the getitems method on a list i the sharepoint clientcontext. For some reason its always returning no elements. Can someone put me in the right direction?

ClientContext context = Isolate.Fake.NextInstance<ClientContext>();
            List list = Isolate.Fake.Instance<List>();
            ListItem fakeListItem = Isolate.Fake.Instance<ListItem>();
            List<ListItem> listItems = new List<ListItem> { fakeListItem, fakeListItem, fakeListItem };
 
            Isolate.WhenCalled(() => list.GetItems(null)).WillReturnCollectionValuesOf(listItems);
            Isolate.WhenCalled(() => context.Web.Lists.GetByTitle(string.Empty)).WillReturn(list);
            Isolate.WhenCalled(() => context.Load(list)).IgnoreCall();
            Isolate.WhenCalled(() => context.ExecuteQuery()).IgnoreCall();
 
            // Act
            var cut = new ClassUnderTest();
            int itemsCount = cut.GetListItemsCount(string.Empty, string.Empty);

           

Here itemsCount returns always 0 elements. Am I using a wrong context/instance?

 

GetListItemsCount is doing the following

using (ClientContext clientContext = new ClientContext(siteUrl))
                {
                    List theList = clientContext.Web.Lists.GetByTitle(listTitle);
                    CamlQuery q = CamlQuery.CreateAllItemsQuery();
                    var items = theList.GetItems(q);
                    clientContext.Load(theList);
                    clientContext.Load(items);
 
                    clientContext.ExecuteQuery();
 
                    return items.Count;
                }

 

Nothing special so far.

 

Ivo
Telerik team
 answered on 15 May 2019
1 answer
495 views
I am trying to test a derived class constructor, but keep hitting code in the base class constructor  This post(https://www.telerik.com/forums/mock-base-class-constructor#PUXW928ic0SPaEl3wK8Mxg) shows how to mock a base class constructor, but it does not work if the base class is abstract.
Mike
Top achievements
Rank 1
 answered on 26 Apr 2019
4 answers
761 views

I have a unit test that creates a mocked instance of a class and arranges some of its properties. The test then executes some extension methods of that class.

When I run the test under visual studio 2017 (JustMock 2019.1.207.1) my tests pass. When I run the same test using the VsTest v2 build task the test fails due to an unarranged mock on the class which corresponds to a call of an extension method.

The code looks something like :

public class Person {
  public string Name { get; }
}
 
public static PersonExtensions {
  public int NameLength(this Person person) {
    return person.Name.Length;
  }
}
 
var fakePerson = Mock.Create<Person>(Behavoir.Strict);
Mock.Arrange(() => fakePerson.Name).Returns("Toto"):
 
var expected = 4;
var actual = fakePerson.NameLength(); // <--- exception here
 
// ...etc.


First strange thing is the test works in visual studio but on the build server.
Second strange thing is the exception says I have declared a strict mock on the PersonExtensions static class :

Telerik.JustMock.Core.StrictMockException: Called unarranged member 'Int32 NameLength(Person)' on strict mock of type 'PersonExtensions'<br>at Telerik.JustMock.Core.Behaviors.StrictBehavior.Process(Invocation invocation)
at Telerik.JustMock.Core.MocksRepository.DispatchInvocation(Invocation invocation)
at Telerik.JustMock.Core.ProfilerInterceptor.DispatchInvocation(Invocation invocation)
at Telerik.JustMock.Core.ProfilerInterceptor.InterceptCall(RuntimeTypeHandle typeHandle, RuntimeMethodHandle methodHandle, Object[] data)
at PersonExtensions.NameLength(Person person)...

If I could reproduce the error in visual studio it would be easier to find a way around it, I will probably do some CallOriginal arranges on the extension methods of the class.

Have you any ideas ?

Thanks,

 

Rob

Mihail
Telerik team
 answered on 15 Apr 2019
10 answers
196 views

Does JuckMock supports mocking the static classes in unit test that runs in parallel? 

I know JuckMock supports Elevated Mocking but does it work in unit tests that runs against each other in parallel?

 

Mihail
Telerik team
 answered on 01 Apr 2019
3 answers
4.5K+ views

Hi,

 

I'm trying to mock a Dictionary.TryGetValue method based on what's described in this thread to no avail.

What I've tried so far:

var dictionary = Mock.Create<Dictionary<string, HashSet<SomeClass>>>();
 
HashSet<SomeClass> expected = new HashSet<SomeClass>();
expected.Add(new SomeClass(param1, param2));
Mock.Arrange(() => dictionary.TryGetValue(Arg.AnyString, out expected)).Returns(true);

However, when ever I run the test, I get a null in the out object.

To give some context, not sure it impacts or not, the test spans a service running in a separate thread. The mocked dictionary is successfully inserted via a PrivateAccessor. 

Thanks in advance,

JP

 

Ivo
Telerik team
 answered on 29 Mar 2019
1 answer
89 views

Hey all, 

New to mocking so bare with me :-)

trying to create a mock up of and AzureConnection within my function app. To create the connection to Azure i have a class "AzureConnection.cs that initiates a connection to Azure using "IAuthenticated Authenticate" iam able to Mock this without issues, but when i try to arrange my connection to always return a specific TenantId it fails!

            var AzureConnectionMock = Mock.Create<AzureConnection>(Behavior.Loose);
            Mock.Arrange(() => AzureConnectionMock.AzureAuthenticated.TenantId)
                .Returns("MyTenantID");

Maybe iam doing this completely wrong, thus hopping someone could help?

Thx

Lyubomir Rusev
Telerik team
 answered on 08 Feb 2019
2 answers
69 views

Hello,

From this link for 2019 R1, we see that it supports .NET Core 2.0:  https://www.telerik.com/support/whats-new/justmock/release-history/justmock-2019-r1

It's commendable to have .NET Core support in JustMock, but 2.0 has been EOL since 01 Oct 2018:  https://github.com/dotnet/announcements/issues/86

Does 2019 R1 also support .NET Core 2.1 (which is an LTS version) and 2.2?  If so, would you please update the announcement at the first link to make that immediately clear?  If not, is there a timeline for .NET Core 2.1 and 2.2 support?  I'll be removing the .NET Core 2.0 SDK from our TFS build servers soon due to the recent security issue, which will not be patched in .NET Core 2.0.

Finally, .NET Core 1.0 and 1.1 are also LTS versions.  Does the announcement of .NET Core 2.0 support include support for 1.0 and 1.2?  Regardless of the answer, would you please update the announcement at the first link to clarify that?

Thanks in advance for any illumination you can provide.

 

Regards,

Tom Slavens

Platform Configuration Architect, Software Services

Veterans United Home Loans

 

Platform
Top achievements
Rank 1
 answered on 30 Jan 2019
1 answer
418 views

I'm using the MockingContainer to automatically set up my dependencies. How do I assert that a property on one of those dependencies gets set?

[SetUp]
public void SetUp()
{
    //arrange
    _baseUrl = "http://baseUrl";
    _container = new MockingContainer<ApiInteractionService>();
    _container.Arrange<IConfigService>(m => m.BaseUrl).Returns(_baseUrl);
    _uut = _container.Instance;
}

 

The following fails with 0 calls, which makes sense since I believe it's looking at the Getter, not the Setter. So how do I assert that the Setter was called by the unit under test?

[Test]
public void BaseUrlSet()
{
    //act
    var _ = _uut.GetMazeId((InitialRequest) Arg.AnyObject);
 
    //assert     
    _container.Assert<IRestService>(m => m.BaseUrl, Occurs.Once());
}

 


Lyubomir Rusev
Telerik team
 answered on 03 Jan 2019
4 answers
800 views

Hello,

 

I'm trying to use JustMock to mock some classes from the TIA Openness https://support.industry.siemens.com/cs/document/108716692/tia-portal-openness%3A-introduction-and-demo-application?dti=0&lc=en-WW library, but I'm having trouble getting the most basic mocking to happen. The TIA Openness classes are referenced through a Siemens.Engineering.dll (which I don't think I'm allowed to link here, sorry)

 

The Project class is written as following:

namespace Siemens.Engineering {
    [DebuggerNonUserCode]
    public sealed class Project : IEngineeringObject, IEngineeringCompositionOrObject, IEngineeringInstance, ITransactionSupport, IMasterCopyTarget, IInternalObjectAccess, IInternalInstanceAccess, IInternalBaseAccess, IEngineeringServiceProvider, IServiceProvider, IEquatable<object> {
        public HardwareUtilityComposition HwUtilities { get; }
        public FileInfo Path { get; }
        public string Name { get; }
        public string LastModifiedBy { get; }
        public DateTime LastModified { get; }
        public bool IsModified { get; }
        public string Family { get; }
        public DateTime CreationTime { get; }
        public string Copyright { get; }
        public string Author { get; }
        public UsedProductComposition UsedProducts { get; }
        public DeviceSystemGroup UngroupedDevicesGroup { get; }
        public SubnetComposition Subnets { get; }
        public ProjectLibrary ProjectLibrary { get; }
        public IEngineeringObject Parent { get; }
        public LanguageSettings LanguageSettings { get; }
        public string Version { get; }
        public HistoryEntryComposition HistoryEntries { get; }
        public MultiLingualGraphicComposition Graphics { get; }
        public DeviceComposition Devices { get; }
        public DeviceUserGroupComposition DeviceGroups { get; }
        public MultilingualText Comment { get; }
        public long Size { get; }
 
        public void Close();
        public override bool Equals(object obj);
        public void ExportProjectTexts(FileInfo path, CultureInfo sourceLanguage, CultureInfo targetLanguage);
        public IList<object> GetAttributes(IEnumerable<string> names);
        public override int GetHashCode();
        public T GetService<T>() where T : class, IEngineeringService;
        public ProjectTextResult ImportProjectTexts(FileInfo path, bool updateSourceLanguage);
        public void Save();
        public void SetAttributes(IEnumerable<KeyValuePair<string, object>> attributes);
        public void ShowHwEditor(View view);
        public override string ToString();
    }
}

 

And I'm trying to get the mocking started just by mocking the getter on Name as follows:

[TestMethod]
        public void Simplest() {
            var ret = Mock.Create<Project>(Behavior.Strict);
            Mock.Arrange(() => ret.Name).Returns("Mocked project");
            Assert.AreEqual("Mocked project", ret.Name);
        }

 

But everytime the test fails with the same error:

Message: Test method UnitTestProject.SequenceTests.Simplest threw exception:
System.IO.FileNotFoundException: Could not load file or assembly 'Siemens.Engineering.Contract, Version=1500.0.2601.1, Culture=neutral, PublicKeyToken=37a18b206f7724a6' or one of its dependencies. The system cannot find the file specified.

 

The stack trace is just

Project.get_name()

SequenceTests.Simplest()

 

The actual usage of TIA Openness requires, for example, for the user to be in a specific Windows user group etc., but I thought I could just intercept all calls to the actual TIA Openness and mock everything away? I was under the impression (and that is what happens when I test JustMock on a class I wrote) that I could overwrite the whole getter of Name (and in the future other, more relevant properties)? But it doesn't seem that is the case. If someone could point me in the right direction, it would be appreciated.

Ivo
Telerik team
 answered on 13 Nov 2018
1 answer
137 views

Hi,

Our Visual Studio and VSCde extension, VS Live Share, contains a private dotnet core executable, vsls-agent.exe. The extension spawns this process within Visual Studio and VSCode. We got some crash reports for it on Windows. We think the crashes happen due to dotnet core issue https://github.com/dotnet/coreclr/issues/17943 which in turn assumes an external profiler is to blame. I see that Telerik.CodeWeaver.Profiler.dll module is loaded in vsls-agent process in all of the crash dumps, which makes the assumption quite solid.

So the questions to the community and Telerik devs:

1. Why Telerik.CodeWeaver.Profiler.dll can be loaded into our process?

2. How can we prevent this from happening? 

Thanks,
Ilya

Mihail
Telerik team
 answered on 29 Oct 2018
Narrow your results
Selected tags
Tags
+? more
Top users last month
Mark
Top achievements
Rank 1
Yurii
Top achievements
Rank 1
Leland
Top achievements
Rank 2
Iron
Iron
Iron
Hon
Top achievements
Rank 1
Iron
Deltaohm
Top achievements
Rank 3
Bronze
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Mark
Top achievements
Rank 1
Yurii
Top achievements
Rank 1
Leland
Top achievements
Rank 2
Iron
Iron
Iron
Hon
Top achievements
Rank 1
Iron
Deltaohm
Top achievements
Rank 3
Bronze
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?