Get "The ConnectionString property has not been initialized." error when running integration test

Hanh Dang asked on November 11, 2016 04:57

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();
        }
    }
}

Correct Answer

Anton Grekhovodov answered on November 11, 2016 07:33

Hi Hanh,

I think you need to inherit your test class (UnitTest1) from IntegrationTests class or you can rename CMSTestConnectionString to CMSConnectionString.

2 votesVote for this answer Unmark Correct answer

Recent Answers


Hanh Dang answered on November 11, 2016 07:49

Hi Anton,

It worked! Thank you for your help

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.