Solved

Programmer needs help!  C#

Posted on 2012-03-21
5
434 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
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.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

827 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