|
I'm confused by the title, if you had been writing this system using TDD you would not have the issue because you would have designed your classes with testability in mind.
Also it's not Architecture vs TDD they aren't conflicting by any means I practice TDD and have found it a good way to design you generally end up with objects that are loosely coupled and because of the code coverage gained you can perform constant refactoring leading to an architecture that evolves more easier
|
|
|
|
|
The issue I'm having is that I am unable to use the testing technology that is available to enable me to adequately test the system by isolating each layer.
To be forced to have to use interfaces where there really is no need has a 'smell' to it.
The system wasn't Test Driven Design, it was designed using normal OOP techniques and it is only trying to use Test Driven Development techniques that I have run into problems.
I have found one solution and that is TypeMock which will happily mock a class that has an abstract base class the only downside being the cost.
Having spent a fair amount of time looking at Mock 'products' it seems to me that for the most part you end up having to sacrifice legitimate design choices or alter code so that it can cause performance penalities (such as marking methods/properties as virtual) in order to be able to test.
I haven't come up with any answers and am more than happy to hear other peoples opinions about this.
|
|
|
|
|
Mock objects are designed to be used up front. Attempting to apply them at the end of a development is pretty much a futile issue.
|
|
|
|
|
Can you please elaborate on why?
In a well designed system with good separation of concerns it should be easy to use Mock objects, is it not simply that generally the technology we have in .Net to support mock objects is not up to the task?
|
|
|
|
|
Lowest of the Low wrote: In a well designed system with good separation of concerns it should be easy to use Mock objects,
Well - if you've used techniques such as Inversion of Control then, yes, Mock objects should be fairly easy to use. However, most systems are developed against timescales where good practices like this go out the window. Those that don't tend to have been developed with TDD up front, so the actual mocking has been done well beforehand.
|
|
|
|
|
Lowest of the Low wrote: or I have to mark the methods and properties of the base class as virtual and cause a performance problem.
What kind of application are you building?
I'm willing to bet money that you will not notice any difference at all if you go virtual unless you are building some extremely processor intensive algorithm stuff.
Anyway, there are other mock frameworks that allow you to do what you want.
(eg, Typemock , but that one is commercial)
There are also two kinds of mock usage:
1) You use the mock as a stub just to return test data for you.
Eg, you want your DAL class to return some dummy list of customers to your business layer.
2) You do interaction tests, you want to see that classes communicate correctly.
Eg, you might want to test that a business class calls your logger class under certain conditions.
(http://martinfowler.com/articles/mocksArentStubs.html)
The first case is is easy to do with mockframeworks that requires virtual or interfaces.
Since if you need a stub you need to create some sort of interface anyway..
So in this aspect Pete is completely right.
In the 2nd case, you want to make sure that a certain call flow occurss under a certain condition.
In this case you do need to have actual code that interacts, and the mock framework should simply ensure that certain methods were or were not called.
This can also be done with virtual/iface mocks, but they are not always enough, eg, they can not ensure that a static method was called.
So in this aspect you are better off using a mock framework that can intercept any type of call.
(One could argue that static methods are ugly and you should design your api so that you do not need to test if a static/private/non virtual method was called, but that is a whole different story )
|
|
|
|
|
The application is fairly standard, its a web application broken down into 3 layers Presentation, Business Logic and DataAccess.
Within the data access layer we have an abstract base class that encapsulates standard db access and then we have concrete classes to encapsulate the data access for different parts of the application to different databases. Within the Business logic layer a class will use a specific concrete classes to perform their data access.
Inside the business logic layer we have an abstract class that again encapsulates standard functionality used by the concrete classes representing entities.
I'm only using mock objects in relation to testing the business logic layer and am using a mixture of the 2 types of mock you describe (not in the same test).
I have been using the community edition of TypeMock and it does exactly what I want but the problem is that I am unable to use code coverage inside VSTS with the community edition and it is doubtful that the company will pay for the licence which is why I have had to look into other Mock frameworks which has lead me to run into the issue of not being able to mock.
In relation to your type 1 mock how would you go about using an interface when the class you are attempting to mock is unique within the app? Or am I just being dense here and you would simply replace the class interface with an explict interface and implement that in the class? Even if you do this it just 'feels' wrong having to create interfaces where a concrete class would work (from an application point of view)
I would value your thoughts.
|
|
|
|
|
Ok but in such case, you won't suffer from any perf problems at all if you mark your methods/props as virtual
The overhead of virtual calls is non existing when you bring html rendering and database access into the picture.
Lowest of the Low wrote: In relation to your type 1 mock how would you go about using an interface when the class you are attempting to mock is unique within the app? Or am I just being dense here and you would simply replace the class interface with an explict interface and implement that in the class? Even if you do this it just 'feels' wrong having to create interfaces where a concrete class would work (from an application point of view)
Well if you use them as stubs because your concrete class is not yet written (kind of the purpose of stubs)
Then you would create an interface, maybe not because the app absolutely needs it in the end, but because _you_ need it to be able to continue to work before the stubbed class is actually implemented...
The interfaces adds value in form of testability which make you able to develop faster and you get an app that is easier to maintain, even if they don't add much value inside the executing application itself.
modified on Monday, June 9, 2008 8:01 AM
|
|
|
|
|
class A
{
public:
...
AddTo(CList &L);
private:
}
For the bad, A is couple with CList.
For the good, A knows the knowledge to fill CList. But I think it's not necesary for A to know CList.
Is it better to write a gobal function, like:
bool FillList(CList &L, const class &A);
|
|
|
|
|
Why do you want to write a function for that ? CList probably has a function to do that (are you talking about MFC CList?). If not, then you should put this function in CList.
|
|
|
|
|
For polymophism,
class A {
public:
virtual void Fill(CList &L);
}
class B : pubic A
{
public:
virtual void Fill(CList &L);
}
class C : pubic A
{
public:
virtual void Fill(CList &L);
}
If I get a object refereced by A *p , I may call p->FillList(L) .
In another sense, the object knows what to add to the list, it's a reason to add such a memeber function.
The bad thing is that they are coupled.
|
|
|
|
|
The list handles perfeclty adding polymorphic objects to itself. So, what's the problem ? Why do you absolutely want to have a function in class A ? That doesn't make a lot of sense to me. Of course, your list should store pointers to A, then you can add B or C objects to the list and keep the power of polymorphism.
|
|
|
|
|
I haven't say it clearly.
The case is that class B or C has a lot a members to add to the list.
class B : public class A
{
public:
virtual void AddToList(CList &L);
private:
long m_var1;
long m_var2;
long m_var3;
}
|
|
|
|
|
followait wrote: The case is that class B or C has a lot a members to add to the list.
Ooookayy. That was not clear at all from the begining: you don't want to add the object itself to the list but the object should add some elements in the list. In that case, I would make it a member function of the class.
|
|
|
|
|
Class A only needs to have a method AddToList.
I am visualizing from example that List is going to contain only pointer of Class A. Then base class object can point derived class object so basically this method not need to make virtual.
Even though if list is going to have copy of object then need to implement copy constructor & assignment operator in each derived class to make appropriate copy.
But from my point of view class responsibilities should not be mixed up it should be some controller class responsibility to collect object in list rather then Class A itself. So writing a separate method in any other class is better from design-wise. Or make a another class derived by CList and create a method e.g say: "CollectDataInList(A *a)" or have this method in class which is containing CList object.
Akash
|
|
|
|
|
Hi People,
I have an ACE placed on a user control.
If no matching results are found for the criteria supplied I display --> No match found. Please select the item that matches your field of expertise.
This is a bit late and maybe less intuitive.
What I would like is to place a non selectable item in the result list at the very bottom. It would say --> Please select the item that matches your field of expertise.
The result list would then look like this below.
Finance
Clerk
Developer
Trader
Retail
etc
--------------------
Please select the item that matches your field of expertise
Is this possible at all?
Many thanks
|
|
|
|
|
wantToLearn wrote: Is this possible at all?
Yes.
|
|
|
|
|
We are developing a smart client application which consists of shell application with Deck workspace.
Hence we are showing all the UI elements (views) in an overlapped manner. In a particular view, we have an explorer bar which loads group of text editors and combo box editors controls and Save/Cancel buttons. I have given the tab order in a sequence (0 1 2…). But while traversing through that particular view, have noticed that after cancel button the tab order going to next view instead of focusing the initial field in the same view (page).
Thank you.
Regards,
Divya
|
|
|
|
|
Welcome to CodeProject
Take some time to look through the forum list and try to find one that more specifically matches your problem. It seems your problem has nothing to do with Design or Architecture. Many of the forums are specific to languages and/or platforms and it seems that is the problem you are dealing with, how the tab control works and perhaps the IDE you are working with.
led mike
|
|
|
|
|
Hi,
How can I design a business use case diagram?
I know how to design a use case diagram, but what is business use case diagram?
I'd searched the web, but I did't give my answer.
Best wishes
|
|
|
|
|
|
Uses case fundamentally has two kinds: business use case & system use case.
Both have same way of presentation and almost same templates.
If you have wrote use cases more towards to defines yours system or in other words interaction between different systems or interaction with system and human then they are more towards system use case. (e.g presenting available menus and their interaction).
Business use cases are more towards to define business (e.g presenting available menu and their broad view of features)
You should take another try to search material into web, lots of material available
Akash
|
|
|
|
|
Hi Gurus,
I'm trying to create a website with scalability in mind but I'm a little stuck with ASP.NET authentication (Forms Authentication) because I simply don't know much about its internals. I wonder how high traffic websites like myspace.com handle authentication. Most pages in my application are public (i.e. accessible to anyone authenticated or not), only a few pages are only available to authenticated users. I'm basically trying to find answers to those questions:
- As far as I understand from the documentation, ASP.NET Forms Authentication authenticates every request, ie. checks for the authentication cookie and if found it extracts the authentication ticket and decrypts it, is my understanding correct? And if so, can't this potentially affect performance esp. the decryption part? Is this needed for renewing the authentication cookies? (as I believe the ticket issuance time is saved inside the ticket so probably the cookie has to be decrypted anyway to get the ticket issuance time from the ticket then compare this to the current time and decide whether the cookie has to be renewed). If this is an absolute necessity (I'm talking about authenticating every request for the sake of cookie renewal), can we use an encryption algorithm with low overhead (in web.config, authentication element), still efficient? which encryption algorithm would you recommend in this case?
- Is there any way I could make ASP.NET only authenticate requests to protected pages (=pages that are only accessible to authenticated users), BTW, in my application I don't use roles I only make those pages accessible to any authenticated user. Actually I read somewhere that I could write the code needed to authenticate the user only in those protected pages but I wonder whether I will have to handle cookie renewal in this case (this is one thing that's automatically handled by ASP.NET forms authentication)
- Any ideas how I can get the last login with a persistent cookie? In my application I want to allow users to use the "remember me" option (which will send a persistent cookie to the user's computer), now the user doesn't log on explicitly anymore, so I can't put my code that saves the last login to the database in the login page hence it's not used by the user anymore, so how can I do this? I'm thinking about one way to do it but I'm a little worried about how this could impact performance, anyway, here's how .. in my application I need some user related data so I could probably get the data from the database whenever a user with a persistent cookie visits the site (probably FormsAuthentication_Authenticate is the most suitable place) and also write the last login to the database then cache the user data in ASP.NET's cache using the user login retrieved from the authentication cookie as the key with a sliding expiration (let's say something like 30 min or make it equal to the authentication session), if the user visits another page within this period (ie. before the data is removed from the cache), I get the data from the cache and all is ok, but if I can't find the data in the cache (ie, returns null) then I update the last login in the database and get the user data again from the database and cache it in ASP.NET's cache. What do you think about this solution? Do you have any better ideas? I know I could use sessions but I read somewhere that if you handle the session_start event the session is created anyway even if you don't have and data in the session which is not really a good idea (this mean that a session object will be created for all site users authenticated or not).
- what about security? Assume my encryption was broken by some hacker, can't the hacker insert a different user login in a ticket and encrypt it with my broken encryption key? In my application I'm using the user email address as the user login, so, probably a hacker can insert a random email address (from an email list for example) in the ticket and try to access the account of that user, if the user happens to have an account on the site, this will work. My question is that, is the cookie encryption the only way for protection? Because I believe it still can be broken no matter how good it is and in this case it can be a disaster as described above. I'm thinking about something to prevent this, I might probably add something like a random code in the users table in my database (let's call it a security code) and include that code along with the user login in the authentication ticket (separate it from the user login by some character like a pipe for example or put it in the userdata section in the authentication ticket) and whenever we get the data of this user from the users table, we check for the security code along with the user login, for example:
select userid, {other fields here} from users where userlogin = {user email retrieved from the authentication ticket} and SecurityCode = {security code retrieved from the authentication ticket}
Do you think this can be reliable?
Beside the questions above, if you have any resources on the internals of ASP.NET forms authentication, I'd be very grateful if you shared them with me. I've been searching the net for a couple of days but all I can find so far is only about how to use ASP.NET forms authentication in your applications e.g. how to configure it in web.config .. etc but nothing about its internals. I also tried to use .NET Reflector (specifically to disassemble FormsAuthenticationModule) and gained some understanding about how it works internally but not enough to figure it all out.
Sorry for my really long post!
Your help is really much appreciated ...
modified on Thursday, May 22, 2008 7:08 PM
|
|
|
|
|
I have seen people using this and I don't understand why or what is the main purpose.
is it just to hide some implementations details to define such a new class (XXXimpl) and that the main one only servs to provide access to the interface functions ?
Thank you in advance.
|
|
|
|
|
I would suspect that what you are looking at is a case of having an abstract base class and a concrete implementation class. This is one of the most over abused uses of OO you can find. Basically what happens here is somebody creates a base class for something that they are only going to do once and then creates a concrete implementation of it. For some reason, they think this is going to aid them in reuse.
|
|
|
|