I think the complaint is that a static readonly is not a const.  I have
attached a working example.  My test classes inherit from a shared class
which defines some base elements of a xml test / object test.  You might try
const string bob = "//DataFixture/Employees";



Hope this provides some clarity.

Regards,
David



using System;
using System.Collections.Generic;
using System.Text;

using MbUnit.Core.Framework;
using MbUnit.Framework;
using System.Xml;
using System.Xml.Serialization;

using Swingvote.MBUnit.Framework;


namespace TestSample
{


    [DataFixture]
    [XmlDataProvider("sample.xml", "//DataFixture/Employees")]
    public class DataDrivenFixture : BaseDataTestFixture
    {
 
        [ForEachTest("UserTest", DataType = typeof(UserTest))]
        public void ForEachTestWithSerialization(UserTest user)
        {
            Console.WriteLine("Object HashCode: " + this.GetHashCode());
            Assert.IsNotNull(user);
            this.TearDownTest(user);
            this.SetupTest(user);

            if (user.TestName != null)
            {
                Console.WriteLine("Test Name " + user.TestName);
            }

            Console.WriteLine("User Name " + user.ToString());
        }
    }


 

 

    [XmlRoot("UserTest")]
    public class UserTest : BaseDataTest
    {
        private string name;
        private string lastName;
        public UserTest()
        { }

        [XmlAttribute("Name")]
        public String Name
        {
            get { return this.name; }
            set { this.name = value; }
        }

        [XmlAttribute("LastName")]
        public String LastName
        {
            get { return this.lastName; }
            set { this.lastName = value; }
        }
    }
}

 






-----Original Message-----
From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of Ranji
Sent: Thursday, May 18, 2006 10:58 AM
To: MbUnit.User
Subject: MbUnit XmlDataProvider attribute


Hello Folks -

I am attempting to use the "DataFixture" attribute - specifically I am
having problem with the string resource I specify for the XML file in
the XmlDataProvider attribute. If I use a constant expression for the
first argument, MbUnit is able to parse the specified XML file resource
and spit out the test cases. Unfortunately, these tests are designed to
be run on the build machine (and possibly other machines) where the
path of the XML resource is not absolute - it can be located (and found
in a fixed location) relative to the application home directory. So in
effect if I tried this -

class UnitTestSuite
{
     public static readonly String OSP_HOME = FindHomeDirectory();
     public static readonly String REG_PATH = OSP_HOME + some string;
     public static readonly String XML_FILE = REG_PATH + "test.xml";
     ....
}

If I used UnitTestSuite.XML_FILE  as the first argument to the
XmlDataProvider() attribute, I receive the following error messge -

"An attribute argument must be a constant expression, typeof expression
or array creation expression"

Is there any way I can circumvent this problem by not using a constant
expression? Would like to avoid it at all costs - would really be my
last resort though.

Cheers

Ranji




--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"MbUnit.User" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/MbUnitUser
-~----------~----~----~----~------~----~------~--~---

Reply via email to