|
strPrint variable in DrawString() has record to print. How can I know it is suppose to print 1 page or more then 1 page. please let me know. each page should print 86 lines and each line consist of 134 characters.
Best Regards,
Chandan Kumar
|
|
|
|
|
I am using NMock for creating mock objects. I have found a weird behavior of the expectations set on the object. Here is my code. (This code is just to explain the problem, and not used in production)
public class AccountServices
{
ICurrencyServices currencyService = null;
public AccountServices(ICurrencyServices services)
{
currencyService = services;
}
public string Total()
{
return "10" + currencyService.GetTotal();
}
}
public class CurrencyServices : ICurrencyServices
{
public string GetTotal()
{
return "10";
}
}
public interface ICurrencyServices
{
string GetTotal();
}
I am testing Total() method by mocking ICurrencyServices and injecting via constructor to AccountServices . Here goes my test method
[Test]
public void TestTotal()
{
Mockery mock = new Mockery();
ICurrencyServices currency = mock.NewMock<icurrencyservices>();
Expect.Once.On(currency).Method("GetTotal").Will(Return.Value("100"));
AccountServices services = new AccountServices(currency);
Assert.AreEqual("10100", services.Total());
}</icurrencyservices>
This works well. But when I add one more assert just down to the last assert
AccountServices services = new AccountServices(currency);
Assert.AreEqual("10100", services.Total());
Assert.AreEqual("10100", services.Total()); I am getting the following error.
"unexpected invocation of currencyservices.GetTotal()" . This problem will be solved if I add one more expectation before the last assert. It looks like each time I need to add the expectation before doing anything that calls "GetTotal ". Any idea why it works like this ? Why don't the expected value persist until the scope ends ?
|
|
|
|
|
Mocks are different than stubs. I'm not familiar with NMock (I use RhinoMocks myself), but the way it works is that
Expect.Once.On(currency).Method("GetTotal")
Set up your expection that GetTotal be called exactly once. Since you did
Assert.AreEqual("10100", services.Total());
Assert.AreEqual("10100", services.Total());
Calling it 2x is violating the expectation. If that's not what you desired, either change Expect.Once to Expect.Twice (again, not sure of the NMock syntax), or use a stub in place of the mock.
Life, family, faith: Give me a visit.
From my latest post: "How differently the psalmist saw it! How blessed -- how truly happy with real joy! -- is the man who delights in the Law of the Lord."
Judah Himango
|
|
|
|
|
Thanks for the reply. Problem sorted. Expect.Once was making problem. I changed that to Expect.AtLeastOnce . BTW, what scenarios do you use a stub, and what are it's advantages over mock ?
Thanks again
|
|
|
|
|
In short, use stubs for canned results. Use mocks for verifying interactions (e.g. setting expectations). With stubs, it looks just like a real object:
myStub.Foo = 5; compared to
Expect.Call(myMock.Foo).Return(5);
See Martin Fowler's Mocks Aren't Stubs[^] article. MSDN had a good article about the difference between strict mocks, dynamic mocks, and stubs some time ago.
Life, family, faith: Give me a visit.
From my latest post: "How differently the psalmist saw it! How blessed -- how truly happy with real joy! -- is the man who delights in the Law of the Lord."
Judah Himango
|
|
|
|
|
Thanks again. I have very mild usage of NMock, recently started. I have found for mocking interfaces are only used. Say I have a class which needs to be mocked ? Is there a way to go with this ?
Thanks
|
|
|
|
|
N a v a n e e t h wrote: Say I have a class which needs to be mocked ? Is there a way to go with this ?
Partly. Most mock frameworks, such as RhinoMocks, can mock abstract classes and the virtual members of non-sealed classes. Unfortunately, this doesn't work out well because, while C# classes are unsealed by default (good), methods and properties are non-virtual by default (bad). This means most classes you won't be able to mock.
Here at work, we almost always use interfaces. If a class A has a dependency on class B, we change the dependency to be an interface for easy testing and mock injection.
Now, there's one thing you ought to know. There is an extremely powerful mocking framework available -- more powerful than your NMock or my RhinoMocks, called TypeMock.NET. IIRC, TypeMock actually rewrites your IL during the testing phase, allowing you to do anything: mock sealed classes, mock static classes, mock non-virtual methods, mock anything. There's a free community edition available with paid commercial support: TypeMock.com[^]
Life, family, faith: Give me a visit.
From my latest post: "How differently the psalmist saw it! How blessed -- how truly happy with real joy! -- is the man who delights in the Law of the Lord."
Judah Himango
|
|
|
|
|
Thanks. I will give TypeMock a try. Thanks again
|
|
|
|
|
Hello you guys
I'm trying to design a program which can
enumerate a list of processes and you can
suspend a process by clicking RMB (right-mouse button)
and choose Suspend.
I know it is possible, but how?
Note: I tried to use the class Process in .Net framework
but it only has (Start(), Kill()) methods.
|
|
|
|
|
Oh! I forgot.
I also want to know how to Resume a process after
suspending it.
thanks.
|
|
|
|
|
I guess without agreement among processes themselves you can't do that.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Ok I know that.
but I want the way to do it.
|
|
|
|
|
There's the ye olde method SuspendThread link[^] and the similar ResumeThread
You can use DllImport to use them, check here[^] for more info on that.
You will also need the process handle for the functions, but you can get that straight out of the process class.
It might not be entirely safe though, strange things could happen, 'specially in some multi-threaded application. Who knows what may happen.
My current favourite word is: I'm starting to run out of fav. words!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
Ok, I'll try that.
thanks.
|
|
|
|
|
I am having a class as below
My settings file is as below
using System;
using System.Windows.Forms;
using System.Drawing;
using System.ComponentModel;
using System.Configuration;
namespace
Core
{
public class FormSettings : ApplicationSettingsBase
{
private static FormSettings _frmSettings = new FormSettings();
[
UserScopedSetting()]
[
DefaultSettingValueAttribute("0, 0")]
public Point FormLocation
{
get { return (Point)(this["FormLocation"]); }
set { this["FormLocation"] = value; }
}
[
UserScopedSetting()]
[
DefaultSettingValueAttribute("0,0")]
public Size FormSize
{
get { return (Size)this["FormSize"]; }
set { this["FormSize"] = value; }
}
[
UserScopedSetting()]
[
DefaultSettingValueAttribute("225, 200")]
public Size RHSPanelSize
{
get {return (Size)this["RHSPanelSize"]; }
set { this["RHSPanelSize"] = value;}
}
[
UserScopedSetting()]
[
DefaultSettingValueAttribute("Vertical")]
public Orientation TabOrientation
{
get { return (Orientation)this["TabOrientation"]; }
set { this["TabOrientation"] = value; }
}
public static Outpost.Core.FormSettings MyFormSettings
{
get { return _frmSettings; }
}
public static void SaveOrientation(string p, Orientation orientation)
{
MyFormSettings.SettingsKey = p.TrimEnd();
Outpost.Core.
FormSettings theSettings = (FormSettings)MyFormSettings;
theSettings.TabOrientation = orientation;
MyFormSettings.Save();
}
public static Orientation GetOrientation(string p)
{
MyFormSettings.SettingsKey = p.TrimEnd();
Outpost.Core.
FormSettings theSettings = (FormSettings)MyFormSettings;
return theSettings.TabOrientation;
}
}
}
And from my control having a tab,i am calling the method
this._dashboardPage.Orientation = Core.FormSettings.GetOrientation(this._dashboardPage.Name);
I dont seem to get the actual value,But i only get the default.I see the config and the correct values were saved.
What am i doing wrong???
Please help
Thanks
A
|
|
|
|
|
I want to implement a REST web service using VS 2005 & 3.0 framework.are any plugins required for the same?
(WCF service template is not available in VS2005.)
if not how do i create a service file for the same?
|
|
|
|
|
It's called .Net 3.0
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
You'll need the WCF/WPF extensions for VS2005[^]. Be warned, these tools area bit flaky. It is best if you move to VS2008
Don't be overcome by evil, but overcome evil with good
|
|
|
|
|
why can't i import these dlls through 'add reference'? it makes some error when i do that.
once, i saw a code and the programmer was using them within his codes. i mean he was not imported them through 'add reference', he was using them with following codes:
class CLocker
{
[DllImport("user32.dll")] static extern int GetThreadDesktop(int dwThread);
[DllImport("kernel32.dll")] static extern bool CreateProcess(string lpApplicationName, string lpCommandLine, IntPtr lpProcessAttributes, IntPtr lpThreadAttributes, bool bInheritHandles, int dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory, ref STARTUPINFO lpStartupInfo, ref PROCESS_INFORMATION lpProcessInformation);
}
and finally my question is how did he understand that he has to identify those 'CreateProcees(...)' and 'GetThreadDesktop(...)' methods with those kind of parameters?
for this question, i pasted just two of methods, there are some other methods like this,too.
|
|
|
|
|
Sajjad Izadi wrote: why can't i import these dlls through 'add reference'?
Because they are not .NET assemblies.
Sajjad Izadi wrote: finally my question is how did he understand that he has to identify those 'CreateProcees(...)' and 'GetThreadDesktop(...)' methods with those kind of parameters?
www.Pinvoke.net[^] may help
|
|
|
|
|
|
You asked this yesterday! Did you delete all your code and start over?
|
|
|
|
|
|
vinaykskvs wrote: Its very urgent..
Now you've done it...
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
How wide is this sine wave? Because if your drawing from 0-720 degrees, then your wasting time because the wave repeats every 360.
Also, if your wave doesn't change (or doesn't change very often) then it might be better to draw the wave onto a separate bitmap and then just draw the bitmap.
GDI+ is slow, mostly because it seems to do everything with transparency/alpha and if you have AA or smoothing its going to go very slow. So plotting your points is going to be a killer - what with all the separate lines being drawn, calculations to get a smooth curve, smoothing to make the actual line look nice etc. But if you only plot the points once (on to a Bitmap) and then just draw the image, it should be much faster.
EDIT: Oh yeah, and if your problem was that it ran slowly and the curve looked crappy, then you would have been much better saying that in your topic, and telling us what you already tried. Possibly saying thanks for the help in the other topic to keep the other members happy. They do love to complain y'know.
My current favourite word is: I'm starting to run out of fav. words!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|