|
If the drag-n-drop is broken or missing, try writing the code yourself.
:josh:
My WPF Blog[^]
|
|
|
|
|
How do you Pass Data from a MDI Child form to its Parent form?
|
|
|
|
|
One common way is to create events in the child form and have the parent form register a listener
Another method is to have a singleton class somewhere that handles the data
You can always pass data through the message loop
Some people choose to write to files (Heck with XP you can even register a folder listener so you can only check the FS when there is an update)
You could write to a database and continuously poll it
You could make all of your members public
this.Parent will give you the parent of an MDI child form BTW
A man said to the universe:
"Sir I exist!"
"However," replied the Universe, "The fact has not created in me A sense of obligation."
-- Stephen Crane
|
|
|
|
|
i have image in the net
with path http://www.abc.com/aaa.jpg
how can download this image and store it in folder with my application
Palestine
|
|
|
|
|
Replace the url with your url and there you have it
// Prepare web request...
HttpWebRequest myRequest =
(HttpWebRequest)WebRequest.Create("http://www.noviway.com");
// We use POST ( we can also use GET )
myRequest.Method = "GET";
// Assign the response object of 'HttpWebRequest' to a 'HttpWebResponse' variable.
HttpWebResponse myHttpWebResponse= (HttpWebResponse)myRequest.GetResponse();
// Display the contents of the page to the console.
Stream streamResponse = myHttpWebResponse.GetResponseStream();
MemoryStream memStream = new MemoryStream();
byte[] readBuffer = new byte[256];
// Read from buffer
int count = streamResponse.Read( readBuffer, 0, 256 );
while (count > 0)
{
memStream.Write(readBuffer, 0, count);
// Read from buffer
count = streamResponse.Read( readBuffer, 0, 256);
}
byte[] originalBuffer = memStream.ToArray();
// Release the response object resources.
streamResponse.Close();
// Close response
myHttpWebResponse.Close();
Eran Aharonovich (eran.aharonovich@gmail.com )
Noviway
|
|
|
|
|
and how can i save images in file abc.jpg
Palestine
|
|
|
|
|
Just change the URL:
// Prepare web request...
HttpWebRequest myRequest =
(HttpWebRequest)WebRequest.Create("http://www.yoursite.com/abc.jpg");
Eran Aharonovich (eran.aharonovich@gmail.com )
Noviway
|
|
|
|
|
I'm trying to figure out the best way to write unit tests for a singleton class. Naturally, it has a private constructor and is accessed through a static method that returns the only ever instance. However, for unit testing purposes I want to be able to set some state up in advance, put in some mock objects and so on to test that in certain situations the correct exceptions are thrown or results given - all things that I can't really set up through the public interface of the class.
So, for the purposes of unit testing it would be useful to have more than one instance of the class available. Or perhaps there is another solution.
Does anyone have any ideas on how the singleton class might be effectively unit tested?
Scottish Developers events:
* .NET debugging, tracing and instrumentation by Duncan Edwards Jones and Code Coverage in .NET by Craig Murphy
* Developer Day Scotland: are you interested in speaking or attending?
My: Website | Blog
|
|
|
|
|
I would create a new instance through reflection since that can still call the private constructor.
Logifusion[^]
|
|
|
|
|
I think unit testing should be done through "normal" code and techniques, which means:
1) Don't add extra code to the original source and remove it after the test, because this way you aren't testing the orginal code.
2) Avoid using special weapons, such as reflection, platform invoke or special debug support. These just make your testing more complicated but less convincing.
If the private constructor is not supposed to be accessed, don't call it directly. No difference from any other private methods. You still can cover the constructor through your first call to Instance() method.
Best,
Jun
|
|
|
|
|
|
Jun Du wrote: Avoid using special weapons, such as reflection
I couldn't unit test without reflection. How do you otherwise test non-public methods, which, in my case, is almost everything; I always opt for internal rather than public, since public can be called by other assemblies. And if your code can be called by other assemblies, a whole new set of rules apply: try running your assembly under FXCop and have a look for yourself.
Reflection is a great tool for unit testing.
One thing I've found very helpful, which also has alleviated my reliance on reflection, is the InternalsVisibleToAttribute. Put this on your assembly to expose all internal members to your unit tester assembly. From there, you no longer need to use reflection to access internal members.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Messianic Instrumentals (with audio)
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
Judah Himango wrote: I couldn't unit test without reflection. How do you otherwise test non-public methods,
Non-public methods are not exposed to outsiders. How do you use them in your applications? Use them internally.
We should do the same thing in unit testing. Write some test cases, each of which is designed to test certain non-public methods, but through public interfaces or methods.
BTW, we usually don't test the compiler-generated code (designer code).
Best,
Jun
|
|
|
|
|
Jun Du wrote: How do you use them in your applications?
This is where I have to disagree. The very name "unit testing" means that you're testing a single unit, not the application. Unit testing is good for telling you how well a unit works by itself. Integration testing would tell you how things work together. It's not just about non-public methods, I could have classes that are internal and I believe they should be tested as well.
Logifusion[^]
|
|
|
|
|
Well, it all comes down to how we define what a unit is, a method, a class or a module? I often find class is a good candidate as a unit, but the granularity really is relative.
Also, it would be desirable to test a method in the context of an object, as the object state often has decisive effect on the method itself. Maybe that is one area where C++ differs than C.
Best,
Jun
|
|
|
|
|
Judah Himango wrote: One thing I've found very helpful, which also has alleviated my reliance on reflection, is the InternalsVisibleToAttribute. Put this on your assembly to expose all internal members to your unit tester assembly.
I see this is new in .NET 2.0. This would have been handy on a post-hoc unit testing assignment I worked on a few months back.
Kevin
|
|
|
|
|
Judah Himango wrote: One thing I've found very helpful, which also has alleviated my reliance on reflection, is the InternalsVisibleToAttribute. Put this on your assembly to expose all internal members to your unit tester assembly. From there, you no longer need to use reflection to access internal members.
I actually tried that - It looked extremely promising, however it didn't seem to work. It threw up a warning about not being able to find the assembly referenced in the Attrbute and when I tried to access it from the test class it still complained that it was private.
The assemblies are all strong named, so I'm guessing I'm just not doing something right when I give it the strong name of the "friend" assembly.
Scottish Developers events:
* .NET debugging, tracing and instrumentation by Duncan Edwards Jones and Code Coverage in .NET by Craig Murphy
* Developer Day Scotland: are you interested in speaking or attending?
My: Website | Blog
|
|
|
|
|
|
|
|
Colin Angus Mackay wrote: So, for the purposes of unit testing it would be useful to have more than one instance of the class available. Or perhaps there is another solution.
I'm not sure this solution will work for you, Colin, but one thing I've done for classes that are typically single instance only classes is something like this:
public class SomeClass()
{
private static SomeClass instance = new SomeClass();
private SomeClass()
{
}
public SomeClass Current
{
get
{
return instance;
}
}
}
This way, SomeClass can still implement interfaces necessary for using mocks (whereas static classes cannot implement interfaces), it can be instanciated (using reflection or Activator.CreateInstance), and is quite easier to test than a pure static class. In fact, I only use static classes for places that have totally, 100% "functional" functions; where each function relies only on itself or other functions in the same static class; no variables or shared state at all. If you find yourself requiring lots of state and shared data; go with an instance class, IMO.
If you need static access to the instance class and you need only 1 instance of the class, the above code works well.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Messianic Instrumentals (with audio)
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
You could inherit the singleton and put the [Test] blocks on the new class which does have a public method. Or you could wrap the public constructor of your singleton within #if DEBUG directives causing a compile time error on release mode if someone misused your class.
A man said to the universe:
"Sir I exist!"
"However," replied the Universe, "The fact has not created in me A sense of obligation."
-- Stephen Crane
|
|
|
|
|
all font have script with any language inclue in this font
how can get the script in some font with c# ??
Palestine
|
|
|
|
|
Could you please rephrase this in something closer to proper english?
Regards,
mav
--
Black holes are the places where god divided by 0...
|
|
|
|
|
when u open notepate and go to select font from menu
u can see (Script) and comboBox withh all language support in this font ??
i want to make comboBox that have a list with script .. as in the NotePad
how can get this Script with C#
Palestine
|
|
|
|