Hi,
I created a unit test class following the instructions here https://academy.creatio.com/documents/technic-sdk/7-16/testing-tools-nunit for a custom class I created in Creatio.
However, in order to test I need to pass the UserConnection to my class. How do I logon and get the UserConnection from Terrasoft.Configuration.Tests?
Thanks in advance,
Jose
Like
Hello,
You can find the tests examples here https://github.com/Advance-Technologies-Foundation/repository/blob/master/ATF.Repository.Tests/RepositoryWithUserConnectionTests.cs
It is also necessary to install nuget packages from here: https://www.nuget.org/packages/CreatioMock/
https://www.nuget.org/packages/CreatioTestFramework/
Regards,
Dean
Hi, how can I mock filter behaviour in my tests? For Example, I have method: And simple test: esq always returns 2 value, so is it possible to change this and mock filtered result? Thank you in advance
Oleksii Ozerov, Try this
AddFilter to esq mock (github.com)
You can see how data is mocked in BaseMarketplaceTestFixture class
Oleksii Ozerov,
One of the options is to mock using the DBExecutor:
- 1) To set a system setting value in a test, add the system setting key and its value to the TestUserConnection.SettingsValues property (class Dictionary<string, object>)
var appConnection = Substitute.For<AppConnection>(); var userConnection = new TestUserConnection(appConnection); var dbExecutor = Substitute.For<DBExecutor>(userConnection);
2) Configuring UserConnection to work correctly without a database
userConnection.DBExecutor = dbExecutor; userConnection.DBEngine = Substitute.For<DBEngine>(); userConnection.DBTypeConverter = new TestDBTypeConverter();
3) Prepare the results table structure by forming the list of result columns and result records
var testData = new TestData() .Structure() .AddStringColumn("Code") .AddBoolColumn("CanExecute") .NewRow("CanManageAdministration", false) .NewRow("CanManageData", true); DataTable dataTable = testData.GetDataTableUseDataStructure(); // or testData.DataStructure;
Example: Mock the request to DB, which contains "SysAdminOperation" and parameter value = "CanManageAdministration"
dbExecutor.ExecuteReader(ArgExt.Contains("SysAdminOperation"), ArgExt.ContainsQueryParameterByValue("CanManageAdministration")) .Returns(dataTable.CreateDataReader());
P.S. It is recommended that the GetTestDataWithStructure method be used in the UnitTestUtilities class so as not to worry about manually forming the sampling structure. Example:
TestData testData = UnitTestUtilities.GetTestDataWithStructure(_testEntitySchemaManager, "Activity"); var customValues = new Dictionary<string, object> { {"Sender", email} }; testData.DataStructure.AddRowWithCustomColumnValues(customValues);