Link to home
Start Free TrialLog in
Avatar of assaultkitty
assaultkitty

asked on

Programmer needs help! C#

I am doing a walkthrough with msdn.  I need help configuring this file.  Can someone help me?  This is the DateDrivenTest.cs.  This is not an assignment.  

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"]);
        }
    }
}

This is 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=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>


I just need to know how to connect the two files to this program.  

Can you help me?
testdatasource.accdb
data.xlsx
ASKER CERTIFIED SOLUTION
Avatar of angus_young_acdc
angus_young_acdc
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of assaultkitty
assaultkitty

ASKER

This is in the unit test.  

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

Can you explain what is wrong with this statement or show me?  In the video, he does not show how to connect specifically with is issue.   Is the solution?

Data Source="C:testdatasource.accb"
or
Data Source=\"C:testdatasource.accb"
or
Data Source="C:MyTestProject\testdatasource.accdb"

I am very new to this programming with C#.  So, please talk me through.
I am trying to pin point my problem.  I hope I am on the right track.  Can you help me to correct this problem? there is a connection problem so how do I fix this.

app.config

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

unit test

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