assaultkitty
asked on
Walkthrough - using a Configuration File to Define a Data Source
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.visualstud io.testtoo ls" type="Microsoft.VisualStud io.TestToo ls.UnitTes ting.TestC onfigurati onSection, Microsoft.VisualStudio.Qua lityTools. UnitTestFr amework, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d 50a3a"/>
</configSections>
<connectionStrings>
<add name="MyJetConn" connectionString="Provider =Microsoft .Jet.OLEDB .4.0; Data Source=C:Libraries\Documen ts\testdat asource.ac cdb; Persist Security Info=False;" providerName="System.Data. OleDb" />
<add name="MyExcelConn" connectionString="Dsn=Exce l Files;dbq=Libraries\Docume nts\data.x lsx;defaul tdir=.; driverid=790;maxbuffersize =2048;page timeout=5" providerName="System.Data. Odbc" />
</connectionStrings>
<microsoft.visualstudio.te sttools>
<dataSources>
<add name="MyJetDataSource" connectionString="MyJetCon n" dataTableName="MyDataTable " dataAccessMethod="Sequenti al"/>
<add name="MyExcelDataSource" connectionString="MyExcelC onn" dataTableName="Sheet1$" dataAccessMethod="Sequenti al"/>
</dataSources>
</microsoft.visualstudio.t esttools>
</configuration>
public class UnitTest1
{
private TestContext context;
public TestContext TestContext
{
get { return context; }
set { context = value; }
}
[TestMethod()]
[DeploymentItem("MyTestPro ject\\test datasource .accdb")]
[DataSource("MyJetDataSour ce")]
public void MyTestMethod()
{
int a = Int32.Parse(context.DataRo w["Arg1"]. ToString() );
int b = Int32.Parse(context.DataRo w["Arg2"]. ToString() );
Assert.AreNotEqual(a, b, "A value was equal.");
}
[TestMethod()]
[DeploymentItem("MyTestPro ject\\data .xlsx")]
[DataSource("MyExcelDataSo urce")]
public void MyTestMethod2()
{
Assert.AreEqual(context.Da taRow["Val 1"], 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=b77a5c56193 4e089'. C:\Users\acer\Documents\Ba nk-Blackbo ard\Bank\T estProject 2\UnitTest 1.cs 22 13 TestProject2
Error 14 Cannot apply indexing with [] to an expression of type 'System.Data.DataRow' C:\Users\acer\Documents\Ba nk-Blackbo ard\Bank\T estProject 2\UnitTest 1.cs 22 33 TestProject2
Error 15 Cannot apply indexing with [] to an expression of type 'System.Data.DataRow' C:\Users\acer\Documents\Ba nk-Blackbo ard\Bank\T estProject 2\UnitTest 1.cs 23 33 TestProject2
Error 16 Cannot apply indexing with [] to an expression of type 'System.Data.DataRow' C:\Users\acer\Documents\Ba nk-Blackbo ard\Bank\T estProject 2\UnitTest 1.cs 32 29 TestProject2
Error 17 Cannot apply indexing with [] to an expression of type 'System.Data.DataRow' C:\Users\acer\Documents\Ba nk-Blackbo ard\Bank\T estProject 2\UnitTest 1.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=b77a5c56193 4e089'. C:\Users\acer\Documents\Ba nk-Blackbo ard\Bank\T estProject 2\UnitTest 1.cs 22 13 TestProject2
Error 14 Cannot apply indexing with [] to an expression of type 'System.Data.DataRow' C:\Users\acer\Documents\Ba nk-Blackbo ard\Bank\T estProject 2\UnitTest 1.cs 22 33 TestProject2
Error 15 Cannot apply indexing with [] to an expression of type 'System.Data.DataRow' C:\Users\acer\Documents\Ba nk-Blackbo ard\Bank\T estProject 2\UnitTest 1.cs 23 33 TestProject2
Error 16 Cannot apply indexing with [] to an expression of type 'System.Data.DataRow' C:\Users\acer\Documents\Ba nk-Blackbo ard\Bank\T estProject 2\UnitTest 1.cs 32 29 TestProject2
Error 17 Cannot apply indexing with [] to an expression of type 'System.Data.DataRow' C:\Users\acer\Documents\Ba nk-Blackbo ard\Bank\T estProject 2\UnitTest 1.cs 32 54 TestProject2
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="microsoft.visualstud
</configSections>
<connectionStrings>
<add name="MyJetConn" connectionString="Provider
<add name="MyExcelConn" connectionString="Dsn=Exce
</connectionStrings>
<microsoft.visualstudio.te
<dataSources>
<add name="MyJetDataSource" connectionString="MyJetCon
<add name="MyExcelDataSource" connectionString="MyExcelC
</dataSources>
</microsoft.visualstudio.t
</configuration>
public class UnitTest1
{
private TestContext context;
public TestContext TestContext
{
get { return context; }
set { context = value; }
}
[TestMethod()]
[DeploymentItem("MyTestPro
[DataSource("MyJetDataSour
public void MyTestMethod()
{
int a = Int32.Parse(context.DataRo
int b = Int32.Parse(context.DataRo
Assert.AreNotEqual(a, b, "A value was equal.");
}
[TestMethod()]
[DeploymentItem("MyTestPro
[DataSource("MyExcelDataSo
public void MyTestMethod2()
{
Assert.AreEqual(context.Da
}
}
}
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=b77a5c56193
Error 14 Cannot apply indexing with [] to an expression of type 'System.Data.DataRow' C:\Users\acer\Documents\Ba
Error 15 Cannot apply indexing with [] to an expression of type 'System.Data.DataRow' C:\Users\acer\Documents\Ba
Error 16 Cannot apply indexing with [] to an expression of type 'System.Data.DataRow' C:\Users\acer\Documents\Ba
Error 17 Cannot apply indexing with [] to an expression of type 'System.Data.DataRow' C:\Users\acer\Documents\Ba
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=b77a5c56193
Error 14 Cannot apply indexing with [] to an expression of type 'System.Data.DataRow' C:\Users\acer\Documents\Ba
Error 15 Cannot apply indexing with [] to an expression of type 'System.Data.DataRow' C:\Users\acer\Documents\Ba
Error 16 Cannot apply indexing with [] to an expression of type 'System.Data.DataRow' C:\Users\acer\Documents\Ba
Error 17 Cannot apply indexing with [] to an expression of type 'System.Data.DataRow' C:\Users\acer\Documents\Ba
ASKER
No. Can you explain? I am being with C# and I am having a lot of difficulty. Please elaborate. Thank you.
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.
The specific steps may vary depending on the Add Reference dialog that you are using.
ASKER
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.
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.
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.
ASKER
I have added the reference. I still have the same problem. Where do we go from here?
ASKER
int a = Int32.Parse(context.DataRo w["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=b77a5c56193 4e089'. C:\Users\Administrator\Doc uments\Att achments_2 012_03_20\ Bank_Black board\Bank _Blackboar d\Bank\Tes tProject2\ UnitTest1. cs 22 13 TestProject2
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=b77a5c56193
ASKER
Error two
int a = Int32.Parse(context.DataRo w["Arg1"]. ToString() );
int b = Int32.Parse(context.DataRo w["Arg2"]. ToString() );
Error 2 Cannot apply indexing with [] to an expression of type 'System.Data.DataRow' C:\Users\Administrator\Doc uments\Att achments_2 012_03_20\ Bank_Black board\Bank _Blackboar d\Bank\Tes tProject2\ UnitTest1. cs 22 33 TestProject2
int a = Int32.Parse(context.DataRo
int b = Int32.Parse(context.DataRo
Error 2 Cannot apply indexing with [] to an expression of type 'System.Data.DataRow' C:\Users\Administrator\Doc
ASKER
Error 3 Cannot apply indexing with [] to an expression of type 'System.Data.DataRow' C:\Users\Administrator\Doc uments\Att achments_2 012_03_20\ Bank_Black board\Bank _Blackboar d\Bank\Tes tProject2\ UnitTest1. cs 23 33 TestProject2
All of the context variable are highlighted.
All of the context variable are highlighted.
ASKER
TestProject1 -> C:\Users\Administrator\Doc uments\Att achments_2 012_03_20\ Bank_Black board\Bank _Blackboar d\Bank\Tes tProject1\ bin\Debug\ TestProjec t1.dll
------ Rebuild All started: Project: TestProject2, Configuration: Debug Any CPU ------
C:\Users\Administrator\Doc uments\Att achments_2 012_03_20\ Bank_Black board\Bank _Blackboar d\Bank\Tes tProject2\ 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=b77a5c56193 4e089'.
C:\Users\Administrator\Doc uments\Att achments_2 012_03_20\ Bank_Black board\Bank _Blackboar d\Bank\Tes tProject2\ UnitTest1. cs(22,33): error CS0021: Cannot apply indexing with [] to an expression of type 'System.Data.DataRow'
C:\Users\Administrator\Doc uments\Att achments_2 012_03_20\ Bank_Black board\Bank _Blackboar d\Bank\Tes tProject2\ UnitTest1. cs(23,33): error CS0021: Cannot apply indexing with [] to an expression of type 'System.Data.DataRow'
C:\Users\Administrator\Doc uments\Att achments_2 012_03_20\ Bank_Black board\Bank _Blackboar d\Bank\Tes tProject2\ UnitTest1. cs(32,29): error CS0021: Cannot apply indexing with [] to an expression of type 'System.Data.DataRow'
C:\Users\Administrator\Doc uments\Att achments_2 012_03_20\ Bank_Black board\Bank _Blackboar d\Bank\Tes tProject2\ UnitTest1. cs(32,54): error CS0021: Cannot apply indexing with [] to an expression of type 'System.Data.DataRow'
This is the output.
------ Rebuild All started: Project: TestProject2, Configuration: Debug Any CPU ------
C:\Users\Administrator\Doc
C:\Users\Administrator\Doc
C:\Users\Administrator\Doc
C:\Users\Administrator\Doc
C:\Users\Administrator\Doc
This is the output.
ASKER
These are the errors. I hope this helps.
Errors.docx
Errors.docx
ASKER
Fixed error number one added a reference to the Bank, TestProject1, and TestProject2. Have four errors.
ASKER
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.
ASKER
UTA049: TestProject1.UnitTest1.MyT estMethod has invalid DataSource attribute. Either DataSourceSettingName or ConnectionString and TableName must be specified and cannot be empty.
UTA049: TestProject1.UnitTest1.MyT estMethod2 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.Tes tTools.Uni tTesting;
namespace TestProject1
{
[TestClass]
public class UnitTest1
{
private TestContext context;
public TestContext TestContext
{
get { return context; }
set { context = value; }
}
[DeploymentItem("MyTestPro ject\\test datasource .accdb"), DeploymentItem("TestProjec t2\\testda tasource.l accdb"), DeploymentItem("TestProjec t2\\data.x lsx"), TestMethod()]
[DataSource("System.Data.O leDb", "Provider=Microsoft.Jet.OL EDB.4.0;Da ta Source=|DataDirectory|\\te stdatasour ce.laccdb; Jet OLEDB:Database Password=P@ssw)rd", "", DataAccessMethod.Sequentia l)]
public void MyTestMethod()
{
int a = Int32.Parse(context.DataRo w["Arg1"]. ToString() );
int b = Int32.Parse(context.DataRo w["Arg2"]. ToString() );
Assert.AreNotEqual(a, b, "A value was equal.");
}
[DeploymentItem("MyTestPro ject\\data .xlsx"), DeploymentItem("TestProjec t2\\testda tasource.l accdb"), TestMethod()]
[DataSource("System.Data.O leDb", "Provider=Microsoft.Jet.OL EDB.4.0;Da ta Source=|DataDirectory|\\te stdatasour ce.laccdb; Persist Security Info=True;Jet OLEDB:Database Password=P@ssw0rd", "", DataAccessMethod.Sequentia l)]
public void MyTestMethod2()
{
Assert.AreEqual(context.Da taRow["Val 1"], context.DataRow["Val2"]);
}
}
UTA049: TestProject1.UnitTest1.MyT
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.Tes
namespace TestProject1
{
[TestClass]
public class UnitTest1
{
private TestContext context;
public TestContext TestContext
{
get { return context; }
set { context = value; }
}
[DeploymentItem("MyTestPro
[DataSource("System.Data.O
public void MyTestMethod()
{
int a = Int32.Parse(context.DataRo
int b = Int32.Parse(context.DataRo
Assert.AreNotEqual(a, b, "A value was equal.");
}
[DeploymentItem("MyTestPro
[DataSource("System.Data.O
public void MyTestMethod2()
{
Assert.AreEqual(context.Da
}
}
You are using this constructor form for the DataSourceAttribute:
DataSourceAttribute Class
http://msdn.microsoft.com/en-us/library/ms243384.aspx
Invariant data provider name, such as System.Data.SqlClient.
A data provider-specific connection string.
The name of the data table.
tTools.Uni tTesting.D ataAccessM ethod
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.
DataSourceAttribute Class
http://msdn.microsoft.com/en-us/library/ms243384.aspx
providerInvariantName
Type: System.StringInvariant data provider name, such as System.Data.SqlClient.
connectionString
Type: System.StringA data provider-specific connection string.
tableName
Type: System.StringThe name of the data table.
dataAccessMethod
Type: Microsoft.VisualStudio.TesSpecifies 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.
ASKER
ASKER
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.visualstud io.testtoo ls" type="Microsoft.VisualStud io.TestToo ls.UnitTes ting.TestC onfigurati onSection, Microsoft.VisualStudio.Qua lityTools. UnitTestFr amework, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d 50a3a"/>
</configSections>
<connectionStrings>
<add name="MyJetConn" connectionString="Provider =Microsoft .Jet.OLEDB .4.0; Data Source=C:\testdatasource.a ccdb; Persist Security Info=False;" providerName="System.Data. OleDb" />
<add name="MyExcelConn" connectionString="Dsn=Exce l Files;dbq=C:data.xlsx;defa ultdir=.; driverid=790;maxbuffersize =2048;page timeout=5" providerName="System.Data. Odbc" />
</connectionStrings>
<microsoft.visualstudio.te sttools>
<dataSources>
<add name="MyJetDataSource" connectionString="MyJetCon n" dataTableName="MyDataTable " dataAccessMethod="Sequenti al"/>
<add name="MyExcelDataSource" connectionString="MyExcelC onn" dataTableName="Sheet1$" dataAccessMethod="Sequenti al"/>
</dataSources>
</microsoft.visualstudio.t esttools>
</configuration>
using BankAccountNS;
using Microsoft.VisualStudio.Tes tTools.Uni tTesting;
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(TestCont ext 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.Co nvert.ToDo uble(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(creditAccoun t, "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(creditAccoun t, "Was able to credit account.");
}
}
}
using System;
using Microsoft.VisualStudio.Tes tTools.Uni tTesting;
namespace TestProject1
{
[TestClass]
public class UnitTest1
{
private TestContext context;
public TestContext TestContext
{
get { return context; }
set { context = value; }
}
[DeploymentItem("MyTestPro ject\\test datasource .accdb"), DeploymentItem("TestProjec t2\\testda tasource.l accdb"), DeploymentItem("TestProjec t2\\data.x lsx"), TestMethod()]
[DataSource("System.Data.O leDb", "Provider=Microsoft.Jet.OL EDB.4.0;Da ta Source=|DataDirectory|\\te stdatasour ce.laccdb; Jet OLEDB:Database Password=P@ssw)rd", "", DataAccessMethod.Sequentia l)]
public void MyTestMethod()
{
int a = Int32.Parse(context.DataRo w["Arg1"]. ToString() );
int b = Int32.Parse(context.DataRo w["Arg2"]. ToString() );
Assert.AreNotEqual(a, b, "A value was equal.");
}
[DeploymentItem("MyTestPro ject\\data .xlsx"), DeploymentItem("TestProjec t2\\testda tasource.l accdb"), TestMethod()]
[DataSource("System.Data.O leDb", "Provider=Microsoft.Jet.OL EDB.4.0;Da ta Source=|DataDirectory|\\te stdatasour ce.laccdb; Persist Security Info=True;Jet OLEDB:Database Password=P@ssw0rd", "", DataAccessMethod.Sequentia l)]
public void MyTestMethod2()
{
Assert.AreEqual(context.Da taRow["Val 1"], context.DataRow["Val2"]);
}
}
}
I hope this helps you to help me!
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.visualstud
</configSections>
<connectionStrings>
<add name="MyJetConn" connectionString="Provider
<add name="MyExcelConn" connectionString="Dsn=Exce
</connectionStrings>
<microsoft.visualstudio.te
<dataSources>
<add name="MyJetDataSource" connectionString="MyJetCon
<add name="MyExcelDataSource" connectionString="MyExcelC
</dataSources>
</microsoft.visualstudio.t
</configuration>
using BankAccountNS;
using Microsoft.VisualStudio.Tes
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(TestCont
//{
//}
//
//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.Co
}
/// <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(creditAccoun
}
/// <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(creditAccoun
}
}
}
using System;
using Microsoft.VisualStudio.Tes
namespace TestProject1
{
[TestClass]
public class UnitTest1
{
private TestContext context;
public TestContext TestContext
{
get { return context; }
set { context = value; }
}
[DeploymentItem("MyTestPro
[DataSource("System.Data.O
public void MyTestMethod()
{
int a = Int32.Parse(context.DataRo
int b = Int32.Parse(context.DataRo
Assert.AreNotEqual(a, b, "A value was equal.");
}
[DeploymentItem("MyTestPro
[DataSource("System.Data.O
public void MyTestMethod2()
{
Assert.AreEqual(context.Da
}
}
}
I hope this helps you to help me!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I am not done with this problem. I have to get some sleep. I will start work on this problem tomorrow.
ASKER
I am back and I need help. I will be in touch soon. Thanks expert!
ASKER
configuration string
add name="MyJetConn" connectionString=""System. Data.OleDb "; Data Source=C:\testdatasource.a ccdb; Persist Security Info=False;" providerName="System.Data. OleDb" />
Is this your expected result.
add name="MyJetConn" connectionString=""System.
Is this your expected result.
Are you still talking about the DataSource attribute?
ASKER
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.Te stTools.Un itTesting. TestConfig uration' threw an exception.
An error occurred creating the configuration section handler for microsoft.visualstudio.tes ttools: Could not load file or assembly 'Microsoft.VisualStudio.Qu alityTools .UnitTestF ramework, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d 50a3a' or one of its dependencies. The system cannot find the file specified. (C:\Users\acer\Documents\V isual Studio 2010\Projects\DataDrivenTe st\bin\Deb ug\DataDri venTest.DL L.config line 4)
Could not load file or assembly 'Microsoft.VisualStudio.Qu alityTools .UnitTestF ramework, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d 50a3a' 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.visualstud io.testtoo ls" type="Microsoft.VisualStud io.TestToo ls.UnitTes ting.TestC onfigurati onSection, Microsoft.VisualStudio.Qua lityTools. UnitTestFr amework, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d 50a3a"/>
</configSections>
<connectionStrings>
<add name="MyJetConn" connectionString="Provider =Microsoft .Jet.OLEDB .4.0; Data Source=C:\testdatasource.a ccdb; Persist Security Info=False;" providerName="System.Data. OleDb" />
<add name="MyExcelConn" connectionString="Dsn=Exce l Files;dbq=C:\data.xlsx;def aultdir=.; driverid=790;maxbuffersize =2048;page timeout=5" providerName="System.Data. Odbc" />
</connectionStrings>
<microsoft.visualstudio.te sttools>
<dataSources>
<add name="MyJetDataSource" connectionString="MyJetCon n" dataTableName="MyDataTable " dataAccessMethod="Sequenti al"/>
<add name="MyExcelDataSource" connectionString="MyExcelC onn" dataTableName="Sheet1$" dataAccessMethod="Sequenti al"/>
</dataSources>
</microsoft.visualstudio.t esttools>
</configuration>
Unit test
using System;
using Microsoft.VisualStudio.Tes tTools.Uni tTesting;
namespace TestProject1
{
[TestClass]
public class UnitTest1
{
private TestContext context;
public TestContext TestContext
{
get { return context; }
set { context = value; }
}
[TestMethod()]
[DeploymentItem("MyTestPro ject\\test datasource .accdb")]
[DataSource("MyJetDataSour ce")]
public void MyTestMethod()
{
int a = Int32.Parse(context.DataRo w["Arg1"]. ToString() );
int b = Int32.Parse(context.DataRo w["Arg2"]. ToString() );
Assert.AreNotEqual(a, b, "A value was equal.");
}
[TestMethod()]
[DeploymentItem("MyTestPro ject\\data .xlsx")]
[DataSource("MyExcelDataSo urce")]
public void MyTestMethod2()
{
Assert.AreEqual(context.Da taRow["Val 1"], context.DataRow["Val2"]);
}
}
}
Can you help me with the exception from the run test?
Unit Test Adapter threw exception:
The type initializer for 'Microsoft.VisualStudio.Te
An error occurred creating the configuration section handler for microsoft.visualstudio.tes
Could not load file or assembly 'Microsoft.VisualStudio.Qu
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.visualstud
</configSections>
<connectionStrings>
<add name="MyJetConn" connectionString="Provider
<add name="MyExcelConn" connectionString="Dsn=Exce
</connectionStrings>
<microsoft.visualstudio.te
<dataSources>
<add name="MyJetDataSource" connectionString="MyJetCon
<add name="MyExcelDataSource" connectionString="MyExcelC
</dataSources>
</microsoft.visualstudio.t
</configuration>
Unit test
using System;
using Microsoft.VisualStudio.Tes
namespace TestProject1
{
[TestClass]
public class UnitTest1
{
private TestContext context;
public TestContext TestContext
{
get { return context; }
set { context = value; }
}
[TestMethod()]
[DeploymentItem("MyTestPro
[DataSource("MyJetDataSour
public void MyTestMethod()
{
int a = Int32.Parse(context.DataRo
int b = Int32.Parse(context.DataRo
Assert.AreNotEqual(a, b, "A value was equal.");
}
[TestMethod()]
[DeploymentItem("MyTestPro
[DataSource("MyExcelDataSo
public void MyTestMethod2()
{
Assert.AreEqual(context.Da
}
}
}
Can you help me with the exception from the run test?
Do you have a reference in the unit test project to your project that you are trying to test (DataDrivenTest.DLL)?
ASKER
I have added it. Now I have an error.
error.docx
error.docx
ASKER
Sorry. I loaded the Metaload file. Thanks.
ASKER
I still have the exception fail after the run test on MyTestMethod()
ASKER
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.Tes tTools.Uni tTesting;
namespace TestProject1
{
[TestClass]
public class UnitTest1
{
private TestContext context;
public TestContext TestContext
{
get { return context; }
set { context = value; }
}
[DeploymentItem("testdatas ource.lacc db"), DeploymentItem("testdataso urce.accdb "), TestMethod()]
[DataSource("System.Data.O leDb", "Provider=Microsoft.Jet.OL EDB.4.0;Da ta Source=\"C:\\testdatasourc e.laccdb", "MyDataTable", DataAccessMethod.Sequentia l)]
public void MyTestMethod()
{
int a = Int32.Parse(TestContext.Da taRow["Arg 1"].ToStri ng());
int b = Int32.Parse(TestContext.Da taRow["Arg 2"].ToStri ng());
Assert.AreNotEqual(a, b, "A value was equal.");
}
[TestMethod()]
[DeploymentItem("MyTestPro ject\\data .xlsx")]
[DataSource("MyExcelDataSo urce")]
public void MyTestMethod2()
{
Assert.AreEqual(context.Da taRow["Val 1"], context.DataRow["Val2"]);
}
}
}
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="microsoft.visualstud io.testtoo ls" type="Microsoft.VisualStud io.TestToo ls.UnitTes ting.TestC onfigurati onSection, Microsoft.VisualStudio.Qua lityTools. UnitTestFr amework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d 50a3a"/>
<!--<section name="microsoft.visualstud io.testtoo ls" type="Microsoft.VisualStud io.TestToo ls.UnitTes ting.TestC onfigurati onSection, Microsoft.VisualStudio.Qua lityTools. UnitTestFr amework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d 50a3a" />-->
</configSections>
<connectionStrings>
<add name="MyJetConn" connectionString="Provider =Microsoft .Jet.OLEDB .4.0; Data Source=C:MyTestProject\tes tdatasourc e.accdb; Persist Security Info=False;" providerName="System.Data. OleDb" />
<add name="MyExcelConn" connectionString="Dsn=Exce l Files;dbq=C:\data.xlsx;def aultdir=.; driverid=790;maxbuffersize =2048;page timeout=5" providerName="System.Data. Odbc" />
</connectionStrings>
<microsoft.visualstudio.te sttools>
<dataSources>
<add name="MyJetDataSource" connectionString="MyJetCon n" dataTableName="MyDataTable " dataAccessMethod="Sequenti al"/>
<add name="MyExcelDataSource" connectionString="MyExcelC onn" dataTableName="Sheet1$" dataAccessMethod="Sequenti al"/>
</dataSources>
</microsoft.visualstudio.t esttools>
</configuration>
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.Tes
namespace TestProject1
{
[TestClass]
public class UnitTest1
{
private TestContext context;
public TestContext TestContext
{
get { return context; }
set { context = value; }
}
[DeploymentItem("testdatas
[DataSource("System.Data.O
public void MyTestMethod()
{
int a = Int32.Parse(TestContext.Da
int b = Int32.Parse(TestContext.Da
Assert.AreNotEqual(a, b, "A value was equal.");
}
[TestMethod()]
[DeploymentItem("MyTestPro
[DataSource("MyExcelDataSo
public void MyTestMethod2()
{
Assert.AreEqual(context.Da
}
}
}
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="microsoft.visualstud
<!--<section name="microsoft.visualstud
</configSections>
<connectionStrings>
<add name="MyJetConn" connectionString="Provider
<add name="MyExcelConn" connectionString="Dsn=Exce
</connectionStrings>
<microsoft.visualstudio.te
<dataSources>
<add name="MyJetDataSource" connectionString="MyJetCon
<add name="MyExcelDataSource" connectionString="MyExcelC
</dataSources>
</microsoft.visualstudio.t
</configuration>
ASKER
Can someone help me with this problem? It is urgent? Thank you!
ASKER
this is the entire project. It is named datadriventest. Can someone help me?
Projects.zip
Projects.zip
ASKER
Hi Experts,
I have asked for help more than 12 hours ago. I have received no response. Can I get some help?
Projects.zip
I have asked for help more than 12 hours ago. I have received no response. Can I get some help?
Projects.zip
There should be an option to Request Attention. I can't always be available to answer questions (I do have to sleep after all).
What version of Visual Studio .NET are you working with? What is the target framework version for the Unit Test project?
ASKER
I am working with Visual Studio 2010. I am using target framework 4.0 from the testproject.
There error states, "Could not load file or assembly 'Microsoft.VisualStudio.Qu alityTools .UnitTestF ramework, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d 50a3a' 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.visualstud io.testtoo ls" type="Microsoft.VisualStud io.TestToo ls.UnitTes ting.TestC onfigurati onSection, Microsoft.VisualStudio.Qua lityTools. UnitTestFr amework, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d 50a3a"/>
</configSections>
<connectionStrings>
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.visualstud
</configSections>
<connectionStrings>
ASKER
<section name="microsoft.visualstud io.testtoo ls" type="Microsoft.VisualStud io.TestToo ls.UnitTes ting.TestC onfigurati onSection, Microsoft.VisualStudio.Qua lityTools. UnitTestFr amework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d 50a3a"/>
This is the line I already have the Version in there. OK I am listening.
This is the line I already have the Version in there. OK I am listening.
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.
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.
ASKER
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.
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.
Too many problems, so little time...
I believe that error is indicating that your connection string is incorrect for the data source.
I believe that error is indicating that your connection string is incorrect for the data source.
ASKER
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\\te stdatasour ce.accdb; Persist Security Info=False;" providerName="System.Data. OleDb" />
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
ASKER
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\tes tdatasourc e.accdb; Persist Security Info=False;" providerName="System.Data. OleDb" />
[DataSource("System.Data.O leDb", "Provider=Microsoft.Jet.OL EDB.4.0;Da ta Source=C:\\testdatasource. accdb","My DataTable" , DataAccessMethod.Sequentia l)]
<add name="MyJetConn" connectionString="Provider
[DataSource("System.Data.O
Those are not valid file names for the Data Source values.
ASKER
Ok what are the valid file names? Can you show me why they are not valid?
ASKER
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.
C:MyTestProject\testdataso urce.accdb
C:\\testdatasource.accdb
The back slashes are in the wrong place.
C:\\testdatasource.accdb
The back slashes are in the wrong place.
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=b77a5c56193
Do you know how to add references to a project?