Hi all,
I followed this document to make an integration test, but I got "The ConnectionString property has not been initialized." error message when running the test. I have added CMSTestConnectionString connectionString to app.config file. Does anyone know the reason and how to fix it?
Here are my codes:
MyIntegrationTests.cs
using CMS.DataEngine; using CMS.DocumentEngine; using CMS.Helpers; using CMS.Tests; using System.Linq; namespace UnitTestProject { public class MyIntegrationTests : IntegrationTests { public static Author GetAuthor() { string NodeGUID = "fe3424aa-c1d5-4b1e-b7cb-35404b2b78ed"; var document = DocumentHelper.GetDocuments().Type("ABC.XYZ").Where("NodeGUID", QueryOperator.Equals, NodeGUID).Published().FirstOrDefault(); if (document != null) { return new Author { AuthorName = ValidationHelper.GetString(document.GetValue("Name"), ""), IsLeader = ValidationHelper.GetBoolean(document.GetValue("IsLeader"), false) }; } return null; } } public class Author { public string AuthorName { set; get; } public bool IsLeader { set; get; } } }
UnitTest1.cs
using System; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace UnitTestProject { [TestClass] public class UnitTest1 { [TestMethod] public void TestMethod1() { Author au = MyIntegrationTests.GetAuthor(); } } }
Hi Hanh,
I think you need to inherit your test class (UnitTest1) from IntegrationTests class or you can rename CMSTestConnectionString to CMSConnectionString.
Hi Anton,
It worked! Thank you for your help
Please, sign in to be able to submit a new answer.