How would you test this
-
I have a presenter(int a MVP architecture). The initialization function gets some data from the database. First I populate the comboboxes and then i populate each control with data
IList payments = _dbOp.GetListOfItems();
_view.SetCbPaidtoAccount_DataSource(paidToItems, "Text", "PaymentId");etc...
OrderItem orderItem =_dbOp.GetItem(orderId)
if(item!=null)
PopulateControlsFromItem(orderItem);private void PopulateControlsFromItem(orderItem)
{
_view.SetPaymentType_Value=orderItem.paimentId;
etc...
}My question is.. how would you test the PopulateControlsFromItem method?
-
I have a presenter(int a MVP architecture). The initialization function gets some data from the database. First I populate the comboboxes and then i populate each control with data
IList payments = _dbOp.GetListOfItems();
_view.SetCbPaidtoAccount_DataSource(paidToItems, "Text", "PaymentId");etc...
OrderItem orderItem =_dbOp.GetItem(orderId)
if(item!=null)
PopulateControlsFromItem(orderItem);private void PopulateControlsFromItem(orderItem)
{
_view.SetPaymentType_Value=orderItem.paimentId;
etc...
}My question is.. how would you test the PopulateControlsFromItem method?
razvan_dme wrote:
how would you test the PopulateControlsFromItem method?
It is a private method and you are wondering how to test it, right ? Looks like you have a design issue. Look at the SRP[^] and refactor your class which will make it test friendly. If you think it is in a good structure, try mocking
_dbOp.GetListOfItems()
and other codes and test presenter initialization. But it's not a good approach though.All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions
-
razvan_dme wrote:
how would you test the PopulateControlsFromItem method?
It is a private method and you are wondering how to test it, right ? Looks like you have a design issue. Look at the SRP[^] and refactor your class which will make it test friendly. If you think it is in a good structure, try mocking
_dbOp.GetListOfItems()
and other codes and test presenter initialization. But it's not a good approach though.All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions
Ok, in the initialization function i'm getting data from database and then i'm setting this data to my controls, so that means I have broken the SRP, even though the purpose of my method is to fill controls with data taken from the database? I'm doing the same thing with the method PopulateControlsFromItem - firstly i get info from the database and then i'm filling the controls from view with data. I could get rid of this method and place the code in the initialization function, but the code would look messy. Can you please give me a suggestion of how I should refactor my presenter class?
-
Ok, in the initialization function i'm getting data from database and then i'm setting this data to my controls, so that means I have broken the SRP, even though the purpose of my method is to fill controls with data taken from the database? I'm doing the same thing with the method PopulateControlsFromItem - firstly i get info from the database and then i'm filling the controls from view with data. I could get rid of this method and place the code in the initialization function, but the code would look messy. Can you please give me a suggestion of how I should refactor my presenter class?
razvan_dme wrote:
Can you please give me a suggestion of how I should refactor my presenter class?
It's very tough to do as I haven't seen the whole implementation. As "PopulateControlsFromItem" is a part of presenter initialization, testing presenter initialization would cover this method also. Then assert all the expected initializations are happened. AFAIK, you don't write unit tests for each and every method, you write unit tests for testing a particular functionality. Here it is presenter initialization. Hope it's clear
All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions
-
razvan_dme wrote:
Can you please give me a suggestion of how I should refactor my presenter class?
It's very tough to do as I haven't seen the whole implementation. As "PopulateControlsFromItem" is a part of presenter initialization, testing presenter initialization would cover this method also. Then assert all the expected initializations are happened. AFAIK, you don't write unit tests for each and every method, you write unit tests for testing a particular functionality. Here it is presenter initialization. Hope it's clear
All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions
Do you happen to know an open source project so that I can see a view of how MVP architecture is handled and tested?
-
I have a presenter(int a MVP architecture). The initialization function gets some data from the database. First I populate the comboboxes and then i populate each control with data
IList payments = _dbOp.GetListOfItems();
_view.SetCbPaidtoAccount_DataSource(paidToItems, "Text", "PaymentId");etc...
OrderItem orderItem =_dbOp.GetItem(orderId)
if(item!=null)
PopulateControlsFromItem(orderItem);private void PopulateControlsFromItem(orderItem)
{
_view.SetPaymentType_Value=orderItem.paimentId;
etc...
}My question is.. how would you test the PopulateControlsFromItem method?
If you have a private member that really needs testing, make it internal and use (off the top of my head) [assembly:internalsvisibleto("MyStuff.Tests")]
Mark Churchill Director Dunn & Churchill Free Download:
Diamond Binding: The simple, powerful, reliable, and effective data layer toolkit for Visual Studio. -
Do you happen to know an open source project so that I can see a view of how MVP architecture is handled and tested?
I have seen StructureMap[^] which is created by Jeremy D Miller. It's a dependency injection framework which helps to create testable applications. Here[^] is a good MVP implementation with steps to test it. It's in ASP.NET.
All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions