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.