Solved

Programmer needs help!  C#

Posted on 2012-03-21
5
432 Views
Last Modified: 2012-03-22
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
0
Comment
Question by:assaultkitty
  • 2
  • 2
5 Comments
 
LVL 15

Accepted Solution

by:
angus_young_acdc earned 250 total points
ID: 37752009
In your new project right click your solution, select Add -> Existing Item, select your class and the app config, and there you go.  They will then be added to your project.
0
 
LVL 3

Assisted Solution

by:Simplist
Simplist earned 250 total points
ID: 37752066
This will not work with the Express version since testdriven projects may not be supported.
http://msdn.microsoft.com/en-us/library/ms243192%28v=vs.100%29.aspx states you need Visual Studio Premium or Ultimate version.
If you got the appropriate development environment, adapt the location and names of the datafiles according to the references in the app.config (C:MyTestProject\testdatasource.accdb, c:\data.xlsx) or the other way around. Specify full paths. Is your path to testdatasource.accdb missing a \ ?
0
 
LVL 3

Expert Comment

by:Simplist
ID: 37752106
0
 

Author Comment

by:assaultkitty
ID: 37752513
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.
0
 

Author Comment

by:assaultkitty
ID: 37752683
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)]
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

919 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

19 Experts available now in Live!

Get 1:1 Help Now