0

In MBUnit v2 I did this:

public class ConnectionStringFactory
    {
        [Factory]
        public string ConnectionString
        {
            get
            {
                return ConfigurationManager.ConnectionStrings["MyConnection"].ConnectionString; 
            }
        }
    }

    [ProviderFactory(typeof(ConnectionStringFactory),typeof(string))]
    public class CustomerTests
    {
        public void GetCustomerTest(string connectionString)
        { 

        }

        public void GetCustomersTest(string connectionString)
        {

        }
    }

I had to create ONE Factory class returning me a connectionString which gets injected into each test method of a unit test class.

How can this be done with MBUnit v3 where the ProviderFactory is gone?

I played a lot with the Factory class, but the result is not what I want.

I want to a Connection string factory used by all test classes where the connection string

is injected into each test method automatically.

skaffman
  • 398,947
  • 96
  • 818
  • 769
Pascal
  • 12,265
  • 25
  • 103
  • 195

1 Answers1

0

How about this?

public static class ConnectionStringFactory
{
    public static IEnumerable<string> GetConnectionString()
    {
        yield return "connString";
    }
}

[Factory(typeof(ConnectionStringFactory), "GetConnectionString")]
public class CustomerTests
{
    [Test]
    public void GetCustomerTest(string connectionString)
    {
        Console.WriteLine(connectionString);
    }

    [Test]
    public void GetCustomersTest(string connectionString)
    {
        Console.WriteLine(connectionString);
    }
}
grahamrhay
  • 2,046
  • 4
  • 19
  • 29
  • your code does not work on my pc: I get an Exception: The method has 1 parameters but the bindings only provide values for 0 of them. I use latest MBUnit 3.3 – Pascal Feb 21 '12 at 09:44
  • from http://groups.google.com/group/gallio-user/browse_thread/thread/763626ff3a5e8a36 "You cannot use DDT Attributes on the Setup Fixture." – Pascal Feb 21 '12 at 11:09
  • Thanks again for that sample code which worked: http://www.google.com/url?sa=D&q=http://mb-unit.googlecode.com/files/GallioBundle-3.3.458.0.zip&usg=AFQjCNEMRsrcoNHRJLBUKZIYta7ed1B50w – Pascal Feb 25 '12 at 22:01