Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How would you test this

How would you test this

Scheduled Pinned Locked Moved C#
architecturequestiondatabase
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Razvan Dimescu
    wrote on last edited by
    #1

    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?

    N M 2 Replies Last reply
    0
    • R Razvan Dimescu

      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?

      N Offline
      N Offline
      N a v a n e e t h
      wrote on last edited by
      #2

      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

      R 1 Reply Last reply
      0
      • N N a v a n e e t h

        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

        R Offline
        R Offline
        Razvan Dimescu
        wrote on last edited by
        #3

        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?

        N 1 Reply Last reply
        0
        • R Razvan Dimescu

          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?

          N Offline
          N Offline
          N a v a n e e t h
          wrote on last edited by
          #4

          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

          R 1 Reply Last reply
          0
          • N N a v a n e e t h

            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

            R Offline
            R Offline
            Razvan Dimescu
            wrote on last edited by
            #5

            Do you happen to know an open source project so that I can see a view of how MVP architecture is handled and tested?

            N 1 Reply Last reply
            0
            • R Razvan Dimescu

              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?

              M Offline
              M Offline
              Mark Churchill
              wrote on last edited by
              #6

              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.

              1 Reply Last reply
              0
              • R Razvan Dimescu

                Do you happen to know an open source project so that I can see a view of how MVP architecture is handled and tested?

                N Offline
                N Offline
                N a v a n e e t h
                wrote on last edited by
                #7

                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

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups