I have not been able to find the solution of this problem anywhere:
I am building a class PrivateHelper that provides methods to access
private members and invoke private methods, to be used for testing.
In a particular test case, an array is passed to the Method Under Test,
and then that MUT performs a ReDim on the array. The test code then
needs to check the array, but the effect of the ReDim statement does
not propagate to the test code. As long as no ReDim is done, there are
no problems and all changes to the array are visible for the test code.
This is a simplified sketch of how I have done (The PrivateHelper class
is left out):
Sub testCase()
Dim testArray = New Byte() {1, 1}
'setup methodInfo for method "changeArra y" in class myObject
methodInfo.Invo ke(myObject, New Object() {testArray})
'check if testArray(0) = 2 THIS CHECK FAILS
End Sub
Class myObject
Sub changeArray(ByR ef testArray As Byte())
ReDim testArray(3)
testArray(0) = 2
End Sub
End Class
I am not allowed to do any changes in the myObject class. Is there a
way around this problem? 2 2064
"Fredrik Strandberg" <be***********@ hotmail.com> schrieb I have not been able to find the solution of this problem anywhere:
I am building a class PrivateHelper that provides methods to access private members and invoke private methods, to be used for testing.
In a particular test case, an array is passed to the Method Under Test, and then that MUT performs a ReDim on the array. The test code then needs to check the array, but the effect of the ReDim statement does not propagate to the test code. As long as no ReDim is done, there are no problems and all changes to the array are visible for the test code.
This is a simplified sketch of how I have done (The PrivateHelper class is left out):
Sub testCase() Dim testArray = New Byte() {1, 1} 'setup methodInfo for method "changeArra y" in class myObject methodInfo.Invo ke(myObject, New Object() {testArray}) 'check if testArray(0) = 2 THIS CHECK FAILS End Sub
Class myObject Sub changeArray(ByR ef testArray As Byte()) ReDim testArray(3) testArray(0) = 2 End Sub End Class
I am not allowed to do any changes in the myObject class. Is there a way around this problem?
Sub testCase()
Dim testArray = New Byte() {1, 1}
'setup methodInfo for method "changeArra y" in class myObject
dim params as object()
params = new object(){testar ray}
methodInfo.Invo ke(myObject, New Object() {testArray})
testarray = directcast(para ms(0), byte())
End Sub
Before, the new Array has been returned to the object array which is the
container for the parameters. The problem was that you didn't store a
reference to the object array, thus you weren't able to access the new
values (the reference to the new array created by Redim) in the
object array after Invoke returned.
Armin
Thanks a lot, solved all my problems! Splendid! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Wayne Wengert |
last post by:
I am trying to add one column to an existing array (code below). The ReDim
command gives the error:
-----------------------------------------------
Microsoft VBScript runtime error '800a0009'
Subscript out of range
/ListCGShowsGrouped.asp, line 58
------------------------------------------------
|
by: |
last post by:
Is it correct to think that after reducing the populated array's size from
say, 10 to 5 with
redim preserve myArray(i)
an attempt to access an element above the fifth does not cause a
compillation error "array out of script", but returns whatever heppened to
be written in that memory address (in particular it might return the correct
values of those elements before re-dimentioning)?
This seems to be the case in my code, yet I wanted to...
|
by: trevorelbourne |
last post by:
Hi,
I am having trouble accessing the elements of an array using
reflection. This is the code I am having trouble with:
FieldInfo Fields = Obj.GetType().GetFields();
foreach (FieldInfo fi in Fields)
{
Object Temp = fi.GetValue(Obj);
if (Temp.GetType().IsArray)
|
by: Adrian |
last post by:
Hi
In VB 6 I would declare an array in the general part to make it visible to
all parts then once I know how elements I had I would redim it with the
amount thus
Dim testarray() as string
.......
.......
|
by: Paul |
last post by:
Off the cuff, does anyone know if arraylist is more efficeint at adding
items to an array than redim preserve?
Paul
<begin loop>
Dim c As Integer = SomeArray.GetUpperBound(0) + 1
ReDim Preserve SomeArray(c)
SomeArray(c) = SomeObject
<end loop>
| |
by: Tom Jastrzebski |
last post by:
Hello,
I was just testing VB.Net on Framework.Net 2.0 performance when I run into
the this problem.
This trivial code attached below executed hundreds, if not thousand times
faster in VB 6.0 than in .Net environment, under VS 2005 Beta 2. Does anyone
have any idea whether this will be addressed in the final release?
Thanks,
Tomasz
|
by: Anil Gupte |
last post by:
I am having a problem using Multidim arrays. I want to create an array
which as I understand it is dimensioned as:
dim xyz (rows,columns) as String
I want to populate it with rows from a table in a database. I don't know
how many rows I am getting so of course I have to Redim inside the loop that
does this.
Unfortunately, the error message and documentation say: "In a
|
by: Freddy Coal |
last post by:
Hi, I don't know how redim an array, My problem whit an example:
I define my array
Dim Ary as array
I put three elements inside my array
Ary = Split("one,two,three", ",")
|
by: eBob.com |
last post by:
I was changing some code in a multi-threaded application today and noticed
that it was not locking where it really needed to be locking. The Sub was
already working with an array so I just stuck a SyncLock ArrayName.SyncRoot
at the beginning of the Sub and an End SyncLock at the end. But this caused
the application to produce no output (an Excel spreadsheet)! After some
screwing around, sorry ... I mean experimenting, I noticed that the...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |