DataPortal_Create

DataPortal_Create

Old forum URL: forums.lhotka.net/forums/t/11972.aspx


tom posted on Thursday, May 09, 2013

I am trying to code a unit test for one of our business objects but I had a question about the way I am calling the dataprotal create method.  Here is a code snippets.  Should I not use a criteria class?  It passes in another business object that is inherited form the csla framework.

         [Serializable()]
        private class Criteria
        {
            public string RecordNo = string.Empty;
            public Person LoggedInPerson;
            public Criteria(string recordNo, Person LoggedInPerson)
            {
                this.RecordNo = recordNo;
                LoggedInPerson = LoggedInPerson;
            }
        }

        [RunLocal()]
        protected void DataPortal_Create(object criteria)
        {
            Criteria crit = (Criteria)criteria;

            //...

            ValidationRules.CheckRules();

        }

JonnyBee replied on Thursday, May 09, 2013

Which version of CSLA do you use? 

For Csla 4.x you should use CriteriaBase as the base class for your Criteria object and use "managed properties" for properties/values. 

This is to ensure that your code will work on all platforms and in N-tier deployment. 

tom replied on Thursday, May 09, 2013

I am using the csla 3.x

tom replied on Friday, May 10, 2013

Here is my code that I am using to test.  what can I do better here?  Does this look right?

         /// <summary>
        ///A test for DataPortal_Create
        ///</summary>
        [TestMethod()]
        [DeploymentItem("Cit.Library.dll")]
        public void DataPortal_CreateTest()
        {
            //Cit expected = null; // TODO: Initialize to an appropriate value

            Cit_Accessor target = new Cit_Accessor();
            object criteria = new Cit_Accessor.Criteria(1, null);

            target.DataPortal_Create(criteria);
            //Assert.AreEqual(expected, actual);

            //Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }

 

JonnyBee replied on Sunday, May 12, 2013

Well - anyway you are likely to do an integration test here and it depends on what you REALLY want to test. 

Lets just look at what DataPortal_Create does.

  1. Initialize field values 
  2. Optionally set which RuleSet to use
  3. Check rules (and may also run async rules) 

And starting in CSLA 4.5 the DataPortal_Create may also return a Task and be called asynchronously. 
The process of setting Initial values may also require  variables from Csla.ApplicationContext. 

So the test for DataPortal_Create should:

Copyright (c) Marimer LLC