Here is info about our technical development environment :
.NET Core 3.1
PostgreSQL 14.2, compiled by Visual C++ build 1914, 64-bit
EntityFramework.Functions Version=1.5.0
Microsoft.EntityFrameworkCore.Design Version=5.0.17
Microsoft.EntityFrameworkCore.Tools Version=5.0.17
Npgsql.EntityFrameworkCore.PostgreSQL Version=5.0.10
In my application, I have a Generic Target Class, and it's corresponding Wrapper class and Wrapper interface.
public class TargetWrapper<T> : ITargetWrapper<T>
{
private Target<T> _target;
public TargetWrapper()
{
_target = new Target<T>();
}
protected internal TargetWrapper(Target<T> target)
{
_target = target;
}
public T Data
{
get { return _target.Data; }
set { _target.Data = value; }
}
}
I have the a Business Logic class called JohnDoeClass
has the following code that uses the TargetWrapper which sets the generic type to a dynamic:
public class JohnDoeClass
{
public EmailRecord MaryDoeMethod(ITargetWrapper<dynamic> targetWrapper)
{
var dataset = targetWrapper.Data.someDynamicMetaDataEntity;
return new BlahEntity()
{
Id = dataset ["id"],
FaxId = dataset["fax_id"],
FaxNumber = dataset["fax_number"],
FaxLocation = dataset["fax_location"],
Subject = dataset["subject"]
};
}
}
However, when it comes to Unit Mock Testing using the Moq Framework, I do Not know how to code the Moq Setup and it's Return in the following code:
public class JohnDoeClassTests
{
[Fact]
public void MaryDoeMethodTest_Valid()
{
Mock<ITargetWrapper<dynamic>> targetWrapperMock = new Mock<ITargetWrapper<dynamic>>();
dynamic returnedInfo = new ExpandoObject();
returnedInfo.Id = 3;
returnedInfo.fax_id = 7;
returnedInfo.fax_number = “416-949-9393”;
returnedInfo.fax_location =”348 Rover Drive, New York, NY, USA”;
returnedInfo.Subject = “Tax Rebate info 2023”;
graphQLResponseWrapperMock.Setup(r => r.Data …What toplace as code here in order Setup someDynamicMetaDataEntity dynamic property to return > something ?
.Returns(What do I place here in order to return the returnedInfo dynamic object );
}
}
How can I write code for Moq's Setup and its return in regards to mocking the dynamic property in question?