|
I think AccpacObject.OpenView returns a object of type interface and you have to cast it to class type.
|
|
|
|
|
On Pete's recommendation I'm having a play with MoQ. Just for S&G I have an IPerson which defines FirstName, LastName, and DateOfBirth and a Suspect class which implements IPerson.
Now, I want to (for arguments sake) "test" something on this class, namely that if I set FirstName to something, it returns what what it was setup with:
var mockery = new Mock[Suspect]();
mockery.Expect(x => x.FirstName).Returns("Martin");
Assert.AreEqual("Martin", mockery.Object.FirstName);
The test fails because mockery.Object.FirstName returns null.
However this test (based on the interface) passes:
var mockery = new Mock[IPerson]();
mockery.Expect(x => x.FirstName).Returns("Martin");
Assert.AreEqual("Martin", mockery.Object.FirstName);
Why does this pass? What am I missing? Why can't I mock concrete classes, rather than interfaces, especially if a class doesn't implement an interface?
*Note - Ignore the square brackets, they're supposed to be < and > symbols but they ain't working for me!
|
|
|
|
|
martin_hughes wrote: Why can't I mock concrete classes
Try this:
"I've seen better looking asphalt functions!"
Or in a high-pitched whiny voice:
"Look at meeeeee! I'm concreteeeeeete! Neener, neener!"
"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
|
|
|
|
|
We like to call it tarmac over here :p
|
|
|
|
|
Ahhh!!!
What is this 'var' you speak of?
*SpacixOne runs and hides from the possible JScript.NET*
-Spacix
All your skynet questions[ ^] belong to solved
I dislike the black-and-white voting system on questions/answers.
|
|
|
|
|
In case you're being serious (and for the benefit of anybody who happens on this thread who isn't up on .NET 3.5), the var keyword is used to return a strongly typed object where the compiler infers the object from the type of variable. This allows you to do something like this:
var myClass = from p in something
where p.MyItem == 1
select new { p.MyItem, 1, true, p.IsThisCleverOrNot };
|
|
|
|
|
But it's better to make fun of JScript.NET aka the worlds craziest thing to come from .NET
Well... debatable with J#
-Spacix
All your skynet questions[ ^] belong to solved
I dislike the black-and-white voting system on questions/answers.
|
|
|
|
|
Martin - the whole point of mock objects is to create portions of code that are there for testing purposes using Test Driven Development techniques. Basically this means that the mock object will be replaced by a concrete implementation *at a later stage*. Consequently, you test your object against the interface and not the concrete implementation, i.e. it really makes no sense at this stage.
|
|
|
|
|
Yeahhhhh........ but.
Wouldn't you come across a situation where you have a big old object which is a black box for a whole bunch of other stuff, this thing is great, works brilliantly and you can rely on the results. In a testing environment you want the ability to say ok, I have this super-dooper object, given input x I know it will return y, but I don't want to instantiate it for testing purposes (maybe it really goes and affects a database or contacts a webservice or something) I just want to say here's a simulation (or mock) of that object and use that to test/create new functionality in my app?
|
|
|
|
|
Well - in order to do this, you'd end up mocking the object itself. So, you'd create a public interface that "wrapped" this object and then you call this.
|
|
|
|
|
Ah well that makes sense, and may just come in handy later today...
|
|
|
|
|
You can click the < and > buttons to have CP insert them for you.
Cheers,
Vikram.
The hands that help are holier than the lips that pray.
|
|
|
|
|
It depends on what mocking framework you use.
Some use runtime subclassing + implementing interfaces.
Others are more hardcore and relies on .NET profiling API to intercept the jitter and add their own code to any (sealed / non virtual members) concrete class / static functions etc.
While it is true that it is wise to use interfaces when practising TDD, its not that uncommon that you get a codebase that is not created using TDD and thus you might be forced to create tests that uses those concrete classes.
In such case you are either forced to do some (alot) refactoring of the codebase before you start writing tests, or you can use a mock framework that are able to mock those concrete classes.
And that is just a matter of taste / religion.
Im personally against the concept of altering sealed / non virtual methods because there is a reason they were designed that way in the first place.
However, I can see the benefit of it in cases where you have an existing codebase..
But Im a bit too paranoid to trust that the mangled code will work correctlt just because it wasnt intended to be modified.
---
Also, your example is not how it is intended to be used.
You are supposed to use the mocks when interacting with other, non mocked components.
eg:
//EDIT CP code blocks are crazy today...
var mockery = new Mock[IPerson]();
mockery.Expect(x => x.FirstName).Returns("Martin");
FooComponent foo = new FooComponent();
var res = foo.DoStuff(123,444,55,mockery);
assert.AreEqual(res , 123 , "incorrect value from foo.DoStuff");
//if this fails, then the FooComponent did not interact with the mock as expected
assert.xxxx ( whatever way you test if the mock methods was called );
This way you can see if your test subject interacts correctly with the mock.
In this kind of case, it _can_ be useful to mock concrete classes.
To force it to return something instead of running its own code.
Just so you can see that your test subject interacts with the mock.
modified on Friday, May 23, 2008 6:50 AM
|
|
|
|
|
Thanks -
Roger Alsing wrote: var mockery = new Mock[IPerson]();
mockery.Expect(x => x.FirstName).Returns("Martin");
FooComponent foo = new FooComponent();
var res = foo.DoStuff(123,444,55,mockery);
I basically ripped the example from the MoQ Quick Start to ask the question, so I blame them
|
|
|
|
|
I am printing a line1 but on the next line i want to print Line2 so how can i add blank line/or space so it can print like this. Is there any method in C# I don't want to hardcode the margins
Line1
Line2
Line3
e.Graphics.DrawString("Line1",font,Brushes.Black,e.Margin);
Thanks
|
|
|
|
|
Add a "\n" at the spot in the line where you want it to break.
"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
|
|
|
|
|
e.Graphics.DrawString("Line1\r\nLine2",font,Brushes.Black,e.Margin);
Should do it, you might want to use Environment.Newline instead of \r\n though. And if you more than a few lines, i suggest you use a StringBuilder to make the string before drawing it it.
And if your string goes beyond the area in e.Margin then it simply won't be drawn (at least it shouldn't)
My current favourite word is: I'm starting to run out of fav. words!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
You need to adjust the value in e.Margin to point to the next line for each item. Use MeasureString to get the size of the string you want to print (and add a bit so that the lines of text don't run together).
|
|
|
|
|
Thanks guys atleast somwhat it works but the problem is after printing text i want to added a horizontal Line so how could i determine to a start a new line now.
Can anymore show me some examples
StringBuilder sb = new StringBuilder();
if (CokeNameChecked)
{
sb.AppendLine("Name: " + CokeName);
}
if (PersonNameChecked)
{
sb.AppendLine("Subtopic: " + Person.Name);
}
e.Graphics.DrawString(sb.ToString(), _headingFont, Brushes.Black, e.MarginBounds);
e.Graphics.DrawLine(Pens.Black,e.MarginBounds);
}
|
|
|
|
|
As I said before - use MeasureString to find out how big your string is, i.e. what's the bounding rectangle.
|
|
|
|
|
instead of \n or \r\n, use Environment.NewLine
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
I need to create my own set of Windows Forms controls. These are inherited from the standard .NET controls, but all these controls share some methods with the same iumplementation (like subscribing for notifications, some initializations, ...).
So in C++, I'd implement this with multiple inheritance, but since this is not possible in C# and interfaces can't implement any methods, I'm stuck with duplicating the code for every control I create.
Is there any to get around these limitations?
|
|
|
|
|
hai ,
i have a problem when deploying my c# windows application 1.1 with
msde 2000 . every thing works fine but when i execute sql query script it trows an error that incorrect syntax near go and when i remove
go keyword from script file it throws error create view or proc will be the first statement of the query
i tried this code but it does not works
string statements=loadmainfestresource("install.Dbuninstall.sql");
statements.Replace("go",";");
statements = String.Format(statements,this.databasename());
return statements.Split(';');
loadmanifestresource is my function to load emmbede resource
my other question is that can i use attach or de attach file method to this.
if yes how to apply this after install and before install events
Pls give the whole deployment steps
sincierly
modified on Thursday, May 22, 2008 3:20 PM
|
|
|
|
|
Hi! I think I have some answers...
First question:
The GO keyword is special - it is used only in SQL Query Analyzer or similar tools. It tells the tool that the statement batch is complete and should be executed. After that, it continues wit the next statement. It is not passed on to SQL Server (MSDE), and SQL Server doesn't understand it.
If you want to run scripts saved from the query analyzer, you have to parse the scripts yourself (making sure you don't mess up if a string contains a "GO" somewhere), split them into batches and run the batches individually.
You can't just remove the lines containing GO, as (like the second error you get tells you), each "create procedure" or similar statement must be the first in a batch (i.e. must be run in separate SQL commands from your program).
Second question:
IF you had googled for five seconds before asking this, you would have found this rather exhaustive article right here on CodeProject:
Hands on how to configure the MSDE[^]
It should contain all the information you need, and then some...
EDIT: It also tells you how to use osql - which you could call from a CMD file called the PostBuildEvent in your installer - either to attach a database or run query analyzer script files or do both.
--
Peter
modified on Thursday, May 22, 2008 4:14 PM
|
|
|
|
|
i am asking that i have to run sqlscript file that is generated by enterprize manager after installing msde on after_install event of
installer class .
when iam trying this all works fine but when scripts runs throws an error
that incorrect syntax near keyword go and even when i replace it buy ";"
and split it by ';'
can u have some code for deploying application with msde toolkit
i know how to attach or de-attach database but my question is that where
to keep those sql files while attaching and de attaching
|
|
|
|