i opened an excel application using follwing code to load test data to run mstest cases
Public Class ExcelMatrixRead er
Public oXL As Excel.Applicati on
Public oWB As Excel.Workbook
Public oSheet As Excel.Worksheet
Public path As String
Public ExValuetoPass As String
Public Exexpected As String
Dim searchmethod As String
Dim scenariokey As String
Dim irow As Integer
Dim icol As Integer
Public Sub New(ByVal s As String)
path = s
End Sub
Private Sub NAR(ByVal o As Object)
Try
System.Runtime. InteropServices .Marshal.Releas eComObject(o)
Catch
Finally
o = Nothing
End Try
End Sub
Public Sub FindScenario(By Val classname As String, ByVal scenarioke As String)
'Try
oXL = CreateObject("E xcel.Applicatio n")
'oWB = oXL.Workbooks.O pen("C:\source\ Source\UnitTest s\Integration\S ecureSync\Test_ Data\IronMtn.St ringFormatter.T est.Data.xls")
oWB = oXL.Workbooks.O pen(path)
oSheet = oWB.Worksheets( classname)
scenariokey = scenarioke
'irow = 3
icol = 1
For irow = 1 To 20
searchmethod = Convert.ToStrin g(oSheet.Cells( irow, icol).Value)
If (searchmethod.E quals(scenariok ey)) Then ' if equal return -1
ExValuetoPass = Convert.ToStrin g(oSheet.Cells( irow, icol + 1).Value)
Exexpected = Convert.ToStrin g(oSheet.Cells( irow, icol + 2).Value)
'oXL.Quit()
End If
Next irow
'Catch ex As System.Runtime. InteropServices .COMException
oXL.Quit()
NAR(oSheet)
NAR(oWB)
NAR(oXL)
GC.Collect()
End Sub
End Class
here is the test case in mstest
<TestClass()> Public Class StringFormatter Test
Private Exobj As New TestData.ExcelM atrixReader("C: \source\Source\ UnitTests\Integ ration\SecureSy nc\Test_Data\Ir onMtn.StringFor matter.Test.Dat a.xls")
Private testContextInst ance As TestContext
'''<summary>
'''Gets or sets the test context which provides
'''information about and functionality for the current test run.
'''</summary>
Public Property TestContext() As TestContext
Get
Return testContextInst ance
End Get
Set(ByVal value As TestContext)
testContextInst ance = value
End Set
End Property
''''<summary>
''''A test for ToUSAPhoneForma t()
''''</summary>
<TestMethod() > _
Public Sub ToUSAPhoneForma tTest()
Dim valueToPass As String
Dim expected As Object
Dim actual As Object
Dim target As StringFormatter
' Scenario 1 : Passing Numbers with characters
exobj.FindScena rio("StringForm atter", "ToUSAPhoneForm atTest.Scenario 1")
valueToPass = exobj.ExValueto Pass
target = New StringFormatter (valueToPass)
expected = exobj.Exexpecte d
actual = target.ToUSAPho neFormat()
Assert.AreEqual (expected, actual, "StringFormatte r.ToUSAPhoneFor mat() Scenario 1 did not return the expected value.")
'' Scenario 2 : Passing Numbers
exobj.FindScena rio("StringForm atter", "ToUSAPhoneForm atTest.Scenario 2")
valueToPass = exobj.Exvalueto Pass
target = New StringFormatter (valueToPass)
expected = exobj.Exexpecte d
actual = target.ToUSAPho neFormat()
Assert.AreEqual (expected, actual, "StringFormatte r.ToUSAPhoneFor mat) Scenario 2 did not return the expected value.")
'' Scenario 3 : Passing Numbers and characters , number count less than 10
exobj.FindScena rio("StringForm atter", "ToUSAPhoneForm atTest.Scenario 3")
valueToPass = exobj.Exvalueto Pass
target = New StringFormatter (valueToPass)
expected = exobj.Exexpecte d
actual = target.ToUSAPho neFormat
Assert.AreEqual (expected, actual, "StringFormatte r.ToUSAPhoneFor mat() Scenario 3 did not return the expected value.")
End Sub
after running the application still the EXCEL.EXE is running in the task manager
can u please help me to overcome this problem
0 1474 Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Lorenzo Melato |
last post by:
Hi everyone,
I have a very strange problem.
If I open a .NET application from EXCEL using SHELL function, when I close
EXCEL, the EXCEL.EXE process remain active and I must close it by Task
manager.
If I open a normal application (I.E. Notepad.exe) in the same manner, I have
no problem.
|
by: Otie |
last post by:
I found the following under the GetObject help notes and in the
example for GetObject:
"This example uses the GetObject function to get a reference to a
specific Microsoft Excel worksheet (MyXL). It uses the worksheet's
Application property to make Microsoft Excel visible, to close it, and
so on. Using two API calls, the DetectExcel Sub...
|
by: Mr. Smith |
last post by:
Hello all,
My code can successfully open, write to, format and save several
worksheets in a workbook then save it by a given name, close and quit excel.
My problem is that if I try and do it again, Excel hangs. OR if I open
Excel again (say from a desktop icon) before I close Access, Excel
hangs. (this has happened for both 97 & 2000...
|
by: Matthew Wieder |
last post by:
I have the following requirements:
Build a stand-alone C# application that asks the user to click in a cell
in an Excel spreadsheet, and then displays the address of that cell in
the C# application. It seems simple enough, but the problem I'm
encountering is as follows:
In order for the user to select the cell from Excel, they must first...
|
by: Anthony |
last post by:
To me, creating Excel 2003 spreadsheets programmatically via VB.NET hasn't
really changed since the days of VB6.
That is, I'd do something similar to this
Code:
Dim ExcelApp As Excel.Application
Dim ExcelWB As Excel.Workbook
| |
by: alexia.bee |
last post by:
Hi all,
In some weird reason, excel instance won;t die if i remove the comment
from 4 lines of setting values into struct.
here is a snipcode
public System.Collections.Generic.List<frmMain.sDBTest>
LoadTestSet(string TestSetFile,
System.Collections.Generic.List<frmMain.sDBTestDBviewList)
|
by: Gunawan |
last post by:
Dear All,
I have create an excel (COM Object) using this code
Excel.Application xls = new Excel.Application();
but I can not remove it from memory although I have using close and quit
wb.Close(false, false, 0);
xls.Quit();
|
by: Doug Glancy |
last post by:
I got the following code from Francesco Balena's site, for disposing of Com
objects:
Sub SetNothing(Of T)(ByRef obj As T)
' Dispose of the object if possible
If obj IsNot Nothing AndAlso TypeOf obj Is IDisposable Then
DirectCast(obj, IDisposable).Dispose()
|
by: rlntemp-gng |
last post by:
RE: Access 2003/Excel 2003
Problem:
After I close the Access application completely, I go out to the Task
Manager and there is an Excel.exe object still sitting out there.
My Access application creates an Excel file (MyTestFile.XLS) just fine
per the code submitted here. This code closes the Excel file created
and close the Excel...
|
by: =?Utf-8?B?VGVycnkgSG9sbGFuZA==?= |
last post by:
I have a vb.net app that opens an excel worksheet, reads data and then closes
the sheet. Im noticing that the Excel process is still running after I have
closed and disposed of my excel objects.
The following code (Test1) demonstrates the essence of what I am doing.
When I check the processes while ruinning the method, I notice that the...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |