Solved

Programmer needs help!  C#

Posted on 2012-03-21
5
431 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
Comment Utility
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
Comment Utility
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
Comment Utility
0
 

Author Comment

by:assaultkitty
Comment Utility
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
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

771 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

11 Experts available now in Live!

Get 1:1 Help Now