Solved

Walkthrough - using a Configuration File to Define a Data Source

Posted on 2012-03-20
46
1,813 Views
Last Modified: 2012-03-22
Dear Sirs:  I am working on a Walkthrough: Using a Configuration file to define a Data Source.  I have errors on MyTestMethod and MyTestMethod2 tests.  This is a lab2 presentation that I must make.  It is classwork.  Is it possible to help me with.  I do not understand what the issues are with context and the arrays.  Can you help me?  I am using Microsoft Visual Studio.


<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="microsoft.visualstudio.testtools" type="Microsoft.VisualStudio.TestTools.UnitTesting.TestConfigurationSection, Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
  </configSections>
  <connectionStrings>
    <add name="MyJetConn" connectionString="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:Libraries\Documents\testdatasource.accdb; Persist Security Info=False;" providerName="System.Data.OleDb" />
    <add name="MyExcelConn" connectionString="Dsn=Excel Files;dbq=Libraries\Documents\data.xlsx;defaultdir=.; driverid=790;maxbuffersize=2048;pagetimeout=5" providerName="System.Data.Odbc" />
  </connectionStrings>
  <microsoft.visualstudio.testtools>
    <dataSources>
      <add name="MyJetDataSource" connectionString="MyJetConn" dataTableName="MyDataTable" dataAccessMethod="Sequential"/>
      <add name="MyExcelDataSource" connectionString="MyExcelConn" dataTableName="Sheet1$" dataAccessMethod="Sequential"/>
    </dataSources>
  </microsoft.visualstudio.testtools>
</configuration>
 

public class UnitTest1
    {
        private TestContext context;

        public TestContext TestContext
        {
            get { return context; }
            set { context = value; }
        }

        [TestMethod()]
        [DeploymentItem("MyTestProject\\testdatasource.accdb")]
        [DataSource("MyJetDataSource")]
        public void MyTestMethod()
        {
            int a = Int32.Parse(context.DataRow["Arg1"].ToString());
            int b = Int32.Parse(context.DataRow["Arg2"].ToString());
            Assert.AreNotEqual(a, b, "A value was equal.");
        }

        [TestMethod()]
        [DeploymentItem("MyTestProject\\data.xlsx")]
        [DataSource("MyExcelDataSource")]
        public void MyTestMethod2()
        {
            Assert.AreEqual(context.DataRow["Val1"], context.DataRow["Val2"]);
        }
    }
}
 MyTestMethod errors

Error      13      The type 'System.Data.DataRow' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.      C:\Users\acer\Documents\Bank-Blackboard\Bank\TestProject2\UnitTest1.cs      22      13      TestProject2
Error      14      Cannot apply indexing with [] to an expression of type 'System.Data.DataRow'      C:\Users\acer\Documents\Bank-Blackboard\Bank\TestProject2\UnitTest1.cs      22      33      TestProject2
Error      15      Cannot apply indexing with [] to an expression of type 'System.Data.DataRow'      C:\Users\acer\Documents\Bank-Blackboard\Bank\TestProject2\UnitTest1.cs      23      33      TestProject2
Error      16      Cannot apply indexing with [] to an expression of type 'System.Data.DataRow'      C:\Users\acer\Documents\Bank-Blackboard\Bank\TestProject2\UnitTest1.cs      32      29      TestProject2
Error      17      Cannot apply indexing with [] to an expression of type 'System.Data.DataRow'      C:\Users\acer\Documents\Bank-Blackboard\Bank\TestProject2\UnitTest1.cs      32      54      TestProject2


MyTestMethod2 errors

Error      13      The type 'System.Data.DataRow' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.      C:\Users\acer\Documents\Bank-Blackboard\Bank\TestProject2\UnitTest1.cs      22      13      TestProject2
Error      14      Cannot apply indexing with [] to an expression of type 'System.Data.DataRow'      C:\Users\acer\Documents\Bank-Blackboard\Bank\TestProject2\UnitTest1.cs      22      33      TestProject2
Error      15      Cannot apply indexing with [] to an expression of type 'System.Data.DataRow'      C:\Users\acer\Documents\Bank-Blackboard\Bank\TestProject2\UnitTest1.cs      23      33      TestProject2
Error      16      Cannot apply indexing with [] to an expression of type 'System.Data.DataRow'      C:\Users\acer\Documents\Bank-Blackboard\Bank\TestProject2\UnitTest1.cs      32      29      TestProject2
Error      17      Cannot apply indexing with [] to an expression of type 'System.Data.DataRow'      C:\Users\acer\Documents\Bank-Blackboard\Bank\TestProject2\UnitTest1.cs      32      54      TestProject2
0
Comment
Question by:assaultkitty
  • 31
  • 14
46 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 37741943
Do you understand the nature of this error?

The type 'System.Data.DataRow' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

Do you know how to add references to a project?
0
 

Author Comment

by:assaultkitty
ID: 37743123
No.  Can you explain?  I am being with C# and I am having a lot of difficulty.  Please elaborate. Thank you.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 37743136
Right-click on a project in the Solution Explorer, and select Add Reference.  On the .NET tab, you should look for the System.Data.dll, select the entry, and select Add.  

The specific steps may vary depending on the Add Reference dialog that you are using.
0
 

Author Comment

by:assaultkitty
ID: 37743212
I have added a reference.  Now, what do I do.  I need a little explanation.  I guess this is going to take alot of troubleshooting.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 37743272
After you add the reference, that error should go away.  Then, you need to address the other references.  Sometimes, when you are missing a reference, you can get a lot of cascading errors resulting from that missing reference.  It is a good practice to clear up those types of errors, before you continue on with the next set, so that you don't waste time trying to figure out why they are happening.

The compiler errors reference a file, line number, and column.  Since I can't see the line numbers, you will need to take a compiler error, and show me the corresponding line.  You should be able to double-click on the compiler error in the Error List, and it should take you to the corresponding line in the associated file.
0
 

Author Comment

by:assaultkitty
ID: 37743296
I have added the reference.  I still have the same problem.  Where do we go from here?
0
 

Author Comment

by:assaultkitty
ID: 37743434
int a = Int32.Parse(context.DataRow["Arg1"].ToString());


Error number one.

Error      1      The type 'System.Data.DataRow' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.      C:\Users\Administrator\Documents\Attachments_2012_03_20\Bank_Blackboard\Bank_Blackboard\Bank\TestProject2\UnitTest1.cs      22      13      TestProject2
0
 

Author Comment

by:assaultkitty
ID: 37743445
Error two

int a = Int32.Parse(context.DataRow["Arg1"].ToString());
int b = Int32.Parse(context.DataRow["Arg2"].ToString());

Error      2      Cannot apply indexing with [] to an expression of type 'System.Data.DataRow'      C:\Users\Administrator\Documents\Attachments_2012_03_20\Bank_Blackboard\Bank_Blackboard\Bank\TestProject2\UnitTest1.cs      22      33      TestProject2
0
 

Author Comment

by:assaultkitty
ID: 37743454
Error      3      Cannot apply indexing with [] to an expression of type 'System.Data.DataRow'      C:\Users\Administrator\Documents\Attachments_2012_03_20\Bank_Blackboard\Bank_Blackboard\Bank\TestProject2\UnitTest1.cs      23      33      TestProject2

All of the context variable are highlighted.
0
 

Author Comment

by:assaultkitty
ID: 37743462
TestProject1 -> C:\Users\Administrator\Documents\Attachments_2012_03_20\Bank_Blackboard\Bank_Blackboard\Bank\TestProject1\bin\Debug\TestProject1.dll
------ Rebuild All started: Project: TestProject2, Configuration: Debug Any CPU ------
C:\Users\Administrator\Documents\Attachments_2012_03_20\Bank_Blackboard\Bank_Blackboard\Bank\TestProject2\UnitTest1.cs(22,13): error CS0012: The type 'System.Data.DataRow' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
C:\Users\Administrator\Documents\Attachments_2012_03_20\Bank_Blackboard\Bank_Blackboard\Bank\TestProject2\UnitTest1.cs(22,33): error CS0021: Cannot apply indexing with [] to an expression of type 'System.Data.DataRow'
C:\Users\Administrator\Documents\Attachments_2012_03_20\Bank_Blackboard\Bank_Blackboard\Bank\TestProject2\UnitTest1.cs(23,33): error CS0021: Cannot apply indexing with [] to an expression of type 'System.Data.DataRow'
C:\Users\Administrator\Documents\Attachments_2012_03_20\Bank_Blackboard\Bank_Blackboard\Bank\TestProject2\UnitTest1.cs(32,29): error CS0021: Cannot apply indexing with [] to an expression of type 'System.Data.DataRow'
C:\Users\Administrator\Documents\Attachments_2012_03_20\Bank_Blackboard\Bank_Blackboard\Bank\TestProject2\UnitTest1.cs(32,54): error CS0021: Cannot apply indexing with [] to an expression of type 'System.Data.DataRow'

This is the output.
0
 

Author Comment

by:assaultkitty
ID: 37743539
These are the errors.  I hope this helps.
Errors.docx
0
 

Author Comment

by:assaultkitty
ID: 37743572
Fixed error number one added a reference to the Bank, TestProject1, and TestProject2.  Have four errors.
0
 

Author Comment

by:assaultkitty
ID: 37743617
Thanks you are great!  I do not have anymore errors.  I did not know how to add the system.data reference.  No more errors.  I will continue with the project and let you know if I am having anymore problems.
0
 

Author Comment

by:assaultkitty
ID: 37743912
UTA049: TestProject1.UnitTest1.MyTestMethod has invalid DataSource attribute. Either DataSourceSettingName or ConnectionString and TableName must be specified and cannot be empty.

UTA049: TestProject1.UnitTest1.MyTestMethod2 has invalid DataSource attribute. Either DataSourceSettingName or ConnectionString and TableName

I have these errors after adding the connection string to the my unit test.  I am sending a copy of my Unit test.

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace TestProject1
{
    [TestClass]
    public class UnitTest1
    {
        private TestContext context;

        public TestContext TestContext
        {
            get { return context; }
            set { context = value; }
        }

        [DeploymentItem("MyTestProject\\testdatasource.accdb"), DeploymentItem("TestProject2\\testdatasource.laccdb"), DeploymentItem("TestProject2\\data.xlsx"), TestMethod()]
        [DataSource("System.Data.OleDb", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\\testdatasource.laccdb;Jet OLEDB:Database Password=P@ssw)rd", "", DataAccessMethod.Sequential)]
        public void MyTestMethod()
        {
            int a = Int32.Parse(context.DataRow["Arg1"].ToString());
            int b = Int32.Parse(context.DataRow["Arg2"].ToString());
            Assert.AreNotEqual(a, b, "A value was equal.");
        }

        [DeploymentItem("MyTestProject\\data.xlsx"), DeploymentItem("TestProject2\\testdatasource.laccdb"), TestMethod()]
        [DataSource("System.Data.OleDb", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\\testdatasource.laccdb;Persist Security Info=True;Jet OLEDB:Database Password=P@ssw0rd", "", DataAccessMethod.Sequential)]
        public void MyTestMethod2()
        {
            Assert.AreEqual(context.DataRow["Val1"], context.DataRow["Val2"]);
        }
    }
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 37744061
You are using this constructor form for the DataSourceAttribute:

DataSourceAttribute Class
http://msdn.microsoft.com/en-us/library/ms243384.aspx

providerInvariantName
Type: System.String
Invariant data provider name, such as System.Data.SqlClient.

connectionString
Type: System.String
A data provider-specific connection string.

tableName
Type: System.String
The name of the data table.

dataAccessMethod
Type: Microsoft.VisualStudio.TestTools.UnitTesting.DataAccessMethod
Specifies the order to access data. It takes a DataAccessMethod.

Look at the arguments that you are specifying for the DataSource attribute, and match them up to the parameters shown above, and see if you can't find a reason for that error.
0
 

Author Comment

by:assaultkitty
ID: 37744102
0
 

Author Comment

by:assaultkitty
ID: 37744178
http://msdn.microsoft.com/en-us/library/ms182527(v=VS.90).aspx
I am using this to determine the data source for the app.config file in my bank.

 <?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="microsoft.visualstudio.testtools" type="Microsoft.VisualStudio.TestTools.UnitTesting.TestConfigurationSection, Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
  </configSections>
  <connectionStrings>
    <add name="MyJetConn" connectionString="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\testdatasource.accdb; Persist Security Info=False;" providerName="System.Data.OleDb" />
    <add name="MyExcelConn" connectionString="Dsn=Excel Files;dbq=C:data.xlsx;defaultdir=.; driverid=790;maxbuffersize=2048;pagetimeout=5" providerName="System.Data.Odbc" />
  </connectionStrings>
  <microsoft.visualstudio.testtools>
    <dataSources>
      <add name="MyJetDataSource" connectionString="MyJetConn" dataTableName="MyDataTable" dataAccessMethod="Sequential"/>
      <add name="MyExcelDataSource" connectionString="MyExcelConn" dataTableName="Sheet1$" dataAccessMethod="Sequential"/>
    </dataSources>
  </microsoft.visualstudio.testtools>
</configuration>

using BankAccountNS;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

namespace TestProject1
{
   
   
    /// <summary>
    ///This is a test class for BankAccountTest and is intended
    ///to contain all BankAccountTest Unit Tests
    ///</summary>
    [TestClass()]
    public class BankAccountTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for Debit
        ///</summary>
        [TestMethod()]
        public void DebitTest()
        {
            BankAccount target = new BankAccount("Mr. Bryan Walton", 11.99); // TODO: Initialize to an appropriate value
            double amount = 11.22; // TODO: Initialize to an appropriate value
            target.Debit(amount);
            // Assert.Inconclusive("A method that does not return a value cannot be verified.");
            Assert.AreEqual((System.Convert.ToDouble(0.77)), target.Balance, 0.05);
        }

        /// <summary>
        ///A test for Credit
        ///</summary>
        [TestMethod()]
        public void CreditTest()
        {
            BankAccount target = new BankAccount("Mr. Bryan Walton", 11.99); // TODO: Initialize to an appropriate value
            double amount = 0F; // TODO: Initialize to an appropriate value
            target.Credit(amount);
            Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }

        /// <summary>
        ///A test for FreezeAccount
        ///</summary>
        [TestMethod()]
        [DeploymentItem("Bank.dll")]
        public void FreezeAccountTest()
        {
            BankAccount_Accessor target = new BankAccount_Accessor("Mr. Bryan Walton", 11.99); // TODO: Initialize to an appropriate value
            target.FreezeAccount();
            // Assert.Inconclusive("A method that does not return a value cannot be verified.");

            bool creditAccount = false; // False means account could be credited: Fail test.
            // Try to credit account
            try
            {
                target.Credit(1.00);
            }
            catch (System.Exception)
            {
                // Threw exception. FreezeAccount worked correctly: Pass test.
                creditAccount = true;
            }

            // Assert fails if 'creditAccount' condition is false. Fail test.
            Assert.IsTrue(creditAccount, "Was able to credit account.");
        }


        /// <summary>
        ///A test for FreezeAccount
        ///</summary>
        [TestMethod()]
        [DeploymentItem("Bank.dll")]
        public void FreezeAccountTest1()
        {
            BankAccount_Accessor target = new BankAccount_Accessor(); // TODO: Initialize to an appropriate value
            target.FreezeAccount();
            Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }

        /// <summary>
        ///A test for UnfreezeAccount
        ///</summary>
        [TestMethod()]
        [DeploymentItem("Bank.dll")]
        public void UnfreezeAccountTest()
        {
            BankAccount_Accessor target = new BankAccount_Accessor("Mr. Bryan Walton", 11.99); // TODO: Initialize to an appropriate value
            target.UnfreezeAccount();
            // Assert.Inconclusive("A method that does not return a value cannot be verified.");

            bool creditAccount = true; // True means account could not be credited: Fail test.
            // Try to credit account
            try
            {
                target.Credit(1.00);
            }
            catch (System.Exception)
            {
                // Threw exception. FreezeAccount worked correctly: Pass test.
                creditAccount = false;
            }

            // Assert fails if 'creditAccount' condition is false. Fail test.
            Assert.IsTrue(creditAccount, "Was able to credit account.");
        }

    }
}

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace TestProject1
{
    [TestClass]
    public class UnitTest1
    {
        private TestContext context;

        public TestContext TestContext
        {
            get { return context; }
            set { context = value; }
        }

        [DeploymentItem("MyTestProject\\testdatasource.accdb"), DeploymentItem("TestProject2\\testdatasource.laccdb"), DeploymentItem("TestProject2\\data.xlsx"), TestMethod()]
        [DataSource("System.Data.OleDb", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\\testdatasource.laccdb;Jet OLEDB:Database Password=P@ssw)rd", "", DataAccessMethod.Sequential)]
        public void MyTestMethod()
        {
            int a = Int32.Parse(context.DataRow["Arg1"].ToString());
            int b = Int32.Parse(context.DataRow["Arg2"].ToString());
            Assert.AreNotEqual(a, b, "A value was equal.");
        }

        [DeploymentItem("MyTestProject\\data.xlsx"), DeploymentItem("TestProject2\\testdatasource.laccdb"), TestMethod()]
        [DataSource("System.Data.OleDb", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\\testdatasource.laccdb;Persist Security Info=True;Jet OLEDB:Database Password=P@ssw0rd", "", DataAccessMethod.Sequential)]
        public void MyTestMethod2()
        {
            Assert.AreEqual(context.DataRow["Val1"], context.DataRow["Val2"]);
        }
    }
}

I hope this helps you to help me!
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 37744376
I am trying to get you to help yourself.

There are 4 parameters to the DataSource attribute in the line:

DataSource(

"System.Data.OleDb"

 "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\\testdatasource.laccdb;Jet OLEDB:Database Password=P@ssw)rd"

""

 DataAccessMethod.Sequential)



Match them up against the descriptions in the help for DataSourceAttribute, and you should see what I see that explains, "Either DataSourceSettingName or ConnectionString and TableName must be specified and cannot be empty."
0
 

Author Comment

by:assaultkitty
ID: 37745564
I am not done with this problem.  I have to get some sleep.  I will start work on this problem tomorrow.
0
 

Author Comment

by:assaultkitty
ID: 37749061
I am back and I need help.  I will be in touch soon.  Thanks expert!
0
 

Author Comment

by:assaultkitty
ID: 37749395
configuration string    

add name="MyJetConn" connectionString=""System.Data.OleDb"; Data Source=C:\testdatasource.accdb; Persist Security Info=False;" providerName="System.Data.OleDb" />

Is this your expected result.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 37749410
Are you still talking about the DataSource attribute?
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:assaultkitty
ID: 37749761
Thanks for you gentle urging.  I figured out the process.  I was totally off on this project.  I went back and figured out what was wrong with this project.  It had nothing to do with the bank project. It is is just two files.  One DatadrivenTest.cs and UnitTest1.  Once I completed this process. I found that the connection was correct.  Therefore, I needed to run the test on the the first method in the unittest1.  The unittest1 method has thrown an exception.  So, here is the error.  (classmates can stir you in the wrong direction).  The test on the the method failed.  

Unit Test Adapter threw exception:
The type initializer for 'Microsoft.VisualStudio.TestTools.UnitTesting.TestConfiguration' threw an exception.
An error occurred creating the configuration section handler for microsoft.visualstudio.testtools: Could not load file or assembly 'Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. (C:\Users\acer\Documents\Visual Studio 2010\Projects\DataDrivenTest\bin\Debug\DataDrivenTest.DLL.config line 4)
Could not load file or assembly 'Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified..

Here is the code for the unit test and app.configuration file.  I hope I am on the right track this time.

app.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="microsoft.visualstudio.testtools" type="Microsoft.VisualStudio.TestTools.UnitTesting.TestConfigurationSection, Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
  </configSections>
  <connectionStrings>
    <add name="MyJetConn" connectionString="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\testdatasource.accdb; Persist Security Info=False;" providerName="System.Data.OleDb" />
    <add name="MyExcelConn" connectionString="Dsn=Excel Files;dbq=C:\data.xlsx;defaultdir=.; driverid=790;maxbuffersize=2048;pagetimeout=5" providerName="System.Data.Odbc" />
  </connectionStrings>
  <microsoft.visualstudio.testtools>
    <dataSources>
      <add name="MyJetDataSource" connectionString="MyJetConn" dataTableName="MyDataTable" dataAccessMethod="Sequential"/>
      <add name="MyExcelDataSource" connectionString="MyExcelConn" dataTableName="Sheet1$" dataAccessMethod="Sequential"/>
    </dataSources>
  </microsoft.visualstudio.testtools>
</configuration>

Unit test

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace TestProject1
{
    [TestClass]
    public class UnitTest1
    {
        private TestContext context;

        public TestContext TestContext
        {
            get { return context; }
            set { context = value; }
        }

        [TestMethod()]
        [DeploymentItem("MyTestProject\\testdatasource.accdb")]
        [DataSource("MyJetDataSource")]
        public void MyTestMethod()
        {
            int a = Int32.Parse(context.DataRow["Arg1"].ToString());
            int b = Int32.Parse(context.DataRow["Arg2"].ToString());
            Assert.AreNotEqual(a, b, "A value was equal.");
        }

        [TestMethod()]
        [DeploymentItem("MyTestProject\\data.xlsx")]
        [DataSource("MyExcelDataSource")]
        public void MyTestMethod2()
        {
            Assert.AreEqual(context.DataRow["Val1"], context.DataRow["Val2"]);
        }
    }
}

Can you help me with the exception from the run test?
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 37749915
Do you have a reference in the unit test project to your project that you are trying to test (DataDrivenTest.DLL)?
0
 

Author Comment

by:assaultkitty
ID: 37750020
I have added it.  Now I have an error.
error.docx
0
 

Author Comment

by:assaultkitty
ID: 37750061
Sorry. I loaded the Metaload file.  Thanks.
0
 

Author Comment

by:assaultkitty
ID: 37750067
I still have the exception fail after the run test on MyTestMethod()
0
 

Author Comment

by:assaultkitty
ID: 37750521
Dear Expert,

I am spinning my wheels.  I tried what you asked and I have not gotten anywhere.  It does not matter I add reference it seems.  Can you give me some guidance on this project.

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace TestProject1
{
    [TestClass]
    public class UnitTest1
    {
        private TestContext context;

        public TestContext TestContext
        {
            get { return context; }
            set { context = value; }
        }

        [DeploymentItem("testdatasource.laccdb"), DeploymentItem("testdatasource.accdb"), TestMethod()]
        [DataSource("System.Data.OleDb", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\"C:\\testdatasource.laccdb", "MyDataTable", DataAccessMethod.Sequential)]
        public void MyTestMethod()
        {
            int a = Int32.Parse(TestContext.DataRow["Arg1"].ToString());
            int b = Int32.Parse(TestContext.DataRow["Arg2"].ToString());
            Assert.AreNotEqual(a, b, "A value was equal.");
        }

        [TestMethod()]
        [DeploymentItem("MyTestProject\\data.xlsx")]
        [DataSource("MyExcelDataSource")]
        public void MyTestMethod2()
        {
            Assert.AreEqual(context.DataRow["Val1"], context.DataRow["Val2"]);
        }
    }
}


<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="microsoft.visualstudio.testtools" type="Microsoft.VisualStudio.TestTools.UnitTesting.TestConfigurationSection, Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
    <!--<section name="microsoft.visualstudio.testtools" type="Microsoft.VisualStudio.TestTools.UnitTesting.TestConfigurationSection, Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />-->
  </configSections>
  <connectionStrings>
    <add name="MyJetConn" connectionString="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:MyTestProject\testdatasource.accdb; Persist Security Info=False;" providerName="System.Data.OleDb" />
    <add name="MyExcelConn" connectionString="Dsn=Excel Files;dbq=C:\data.xlsx;defaultdir=.; driverid=790;maxbuffersize=2048;pagetimeout=5" providerName="System.Data.Odbc" />
  </connectionStrings>
  <microsoft.visualstudio.testtools>
    <dataSources>
      <add name="MyJetDataSource" connectionString="MyJetConn" dataTableName="MyDataTable" dataAccessMethod="Sequential"/>
      <add name="MyExcelDataSource" connectionString="MyExcelConn" dataTableName="Sheet1$" dataAccessMethod="Sequential"/>
    </dataSources>
  </microsoft.visualstudio.testtools>
</configuration>
0
 

Author Comment

by:assaultkitty
ID: 37751088
Can someone help me with this problem?  It is urgent?  Thank you!
0
 

Author Comment

by:assaultkitty
ID: 37751148
this is the entire project.  It is named datadriventest.  Can someone help me?
Projects.zip
0
 

Author Comment

by:assaultkitty
ID: 37751282
Hi Experts,

I have asked for help more than 12 hours ago.  I have received no response.  Can I get some help?
Projects.zip
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 37752107
There should be an option to Request Attention.  I can't always be available to answer questions (I do have to sleep after all).
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 37752115
What version of Visual Studio .NET are you working with?  What is the target framework version for the Unit Test project?
0
 

Author Comment

by:assaultkitty
ID: 37752343
I am working with Visual Studio 2010.  I am using target framework 4.0 from the testproject.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 37752424
There error states, "Could not load file or assembly 'Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies."

The version for 2010 is 10.0.0.0.

Make sure that you have the proper version referenced in the app.config file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="microsoft.visualstudio.testtools" type="Microsoft.VisualStudio.TestTools.UnitTesting.TestConfigurationSection, Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
  </configSections>
  <connectionStrings>
0
 

Author Comment

by:assaultkitty
ID: 37752444
<section name="microsoft.visualstudio.testtools" type="Microsoft.VisualStudio.TestTools.UnitTesting.TestConfigurationSection, Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>

This is the line I already have the Version in there.  OK I am listening.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 37752448
Are you still getting that error about 8.0.0.0?

If so, please check the file references for the unit test project to make sure that you are referencing the correct version for that assembly.
0
 

Author Comment

by:assaultkitty
ID: 37752530
This is the error I am getting.  I had the correct version from the beginning.  I am running the test for the first method in the Unit test.

The unit test adapter failed to connect to the data source or to read the data. For more information on troubleshooting this error, see "Troubleshooting Data-Driven Unit Tests" (http://go.microsoft.com/fwlink/?LinkId=62412) in the MSDN Library.
Error details: Format of the initialization string does not conform to specification starting at index 33.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 37752564
Too many problems, so little time...

I believe that error is indicating that your connection string is incorrect for the data source.
0
 

Author Comment

by:assaultkitty
ID: 37752614
I got the connection string directly from

http://msdn.microsoft.com/en-us/library/ms243192.aspx

This is the connectionString can you help me to resolve this problem.  Do you know how to do it? n Walk me through this process.  Please!

<add name="MyJetConn" connectionString="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:MyTestProject\\testdatasource.accdb; Persist Security Info=False;" providerName="System.Data.OleDb" />
0
 

Author Comment

by:assaultkitty
ID: 37752677
I am trying to pin point my problem.  I hope I am on the right track.  Can you help me to correct this problem?

<add name="MyJetConn" connectionString="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:MyTestProject\testdatasource.accdb; Persist Security Info=False;" providerName="System.Data.OleDb" />

 [DataSource("System.Data.OleDb", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\testdatasource.accdb","MyDataTable", DataAccessMethod.Sequential)]
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 37752740
Those are not valid file names for the Data Source values.
0
 

Author Comment

by:assaultkitty
ID: 37752746
Ok what are the valid file names?  Can you show me why they are not valid?
0
 

Author Comment

by:assaultkitty
ID: 37752753
Remember I am not an expert.  Please explain to me.  I have done the program thus far.  I do not think you will be giving me the answer.  You are too vague.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 37752946
C:MyTestProject\testdatasource.accdb
C:\\testdatasource.accdb

The back slashes are in the wrong place.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now