Wednesday, September 4, 2013

Structuremap 202 errors..... The two most powerful lines for fixing 202 type errors in Structure map.

 If you are using strcutrue map you are familiar with 202 errors.

If you've seen my list of them and their causes it's a big help in fixing them.

Either way here are two powerful lines for diagnosing what's wrong.


#1:

Debug.WriteLine( ObjectFactory.WhatDoIHave() );






Writes out everything loaded by Structure map... like this:

....
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

ICodeDAL (JCDCHelper.DBCodes.Interfaces.ICodeDAL) JCDCHelper.DBCodes.DataObjects.CodeDAL, JCDCHelper.DBCodes, Version=3.1.2.2, Culture=neutral, PublicKeyToken=null JCDCHelper.DBCodes.DataObjects.CodeDAL, JCDCHelper.DBCodes, Version=3.1.2.2, Culture=neutral, PublicKeyToken=null

Scoped as: PerRequest

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

ISpamisCodeDAL (JCDCHelper.DBCodes.Interfaces.ISpamisCodeDAL) JCDCHelper.DBCodes.DataObjects.SpamisCodeDAL, JCDCHelper.DBCodes, Version=3.1.2.2, Culture=neutral, PublicKeyToken=null JCDCHelper.DBCodes.DataObjects.SpamisCodeDAL, JCDCHelper.DBCodes, Version=3.1.2.2, Culture=neutral, PublicKeyToken=null

Scoped as: PerRequest
....








and #2:
ObjectFactory.AssertConfigurationIsValid();





Looks for obvious errors and gives you better information to fix them... are you haunted by the words "Or one of it's dependencies" this is the tool for you.

Give them a try... Not magic bullets, but a huge help.

Good luck

Cal-

Wednesday, May 15, 2013

Thursday, April 18, 2013

JCDC 4 digit Version System (Versioning)

The 4 Digit Build Number Versioning System

Here is how I think  we should do the 4 digit build numbering system



A.B.C.D



A = Major version number, I.e. Each time you do a complete rewrite, increment this number.



B = Breaking Change Number. Each time you release a change that will require your users to change their code, increment this number.
       (For Nuget Packages, we increment this package only for the one that's altered manually, If package A causes a change in package B, but B does not cause a change to package C, only A has a breaking change)



C = Production Build Number = Each time you release to prod, increment this number.
       (For Nuget Packages, we ignore this number)



D = Dev\QA Build Number Each time you build to go to QA increment this number.
       (For Nuget Packages, we only increment this number)




Offical JCDC Description:


Note: Follow these rules to increment the version numbers:

X.x.x.x - We increment the leftmost digit by one when we make major changes to the apps (such as from 2G to 3G)

x.X.x.x - We increment the second-to-the-left digit when we make significant changes to a JCDCHelper project that require code changes to the remaining JCDCHelper projects that depend on this one.

x.x.X.x - We increment the third-to-the-left digit when we make changes to a single JCDCHelper project that don’t require code changes to the other packages (but you still need to update the JCDCHelper projects that depend on this single project)


x.x.x.X - We increment the rightmost digit when we don’t make code changes to a single JCDCHelper project, only need to release that project.



Monday, April 15, 2013

NUGet error
 
I just used your solution copier tool (do eeet!) to get a working start on a jcdchelper project.  Now I’m trying to redo the nuget packages, but package manager console is giving me


Arithmetic operation resulted in an overflow.


Current Theory - You typed the Path with the wrong case when you had the tool rename the project, OR the tool itself renamed the project. so JCDC Heleper Becase JcdcHelper or something similar causeing the paths to be internally inconsistant in the project.


First attempt: edit the nuget.config file to fix teh capitalization error.

Second Attempt:
1 Delete all teh packages.config files, copy from a working project and modify by hand.

retest.


3rd attempt

if no joy, Manually remove all nuget stuff from all projects (ncludeing refereces) and rebuild it by hand. this worked for Jeffery

Thursday, February 28, 2013

Post build events in projects to copy CVs to main Bin folder



Here are examples of post build eventst hat we used to use to copy the output of one project into the binfolder of antoher... now we ususally use references correctly.





copy /y "$(TargetDir)$(TargetFileName)" "$(SolutionDir)\JCDCADServices\JCDCADServices.ADStudent\bin\$(TargetFileName)"

copy /y "$(TargetDir)$(TargetFileName)" "$(SolutionDir)\JCDCADServices\JCDCADServices.ADStaff\bin\$(TargetFileName)"

Friday, February 8, 2013

Examples/ Cheatsheet of several common Unit Test sceneriao with Rhinomocks at JCDC

Examples/ Cheatsheet of several common Unit Test sceneriao with Rhinomocks at JCDC
//This test is to demonstrate "return values" from bll by taking different branches
[Test]
public void BllMethod1_TestFirstBranchByPassingSam()
{

     //*** Arrange***    
     SearchCallPersonVM criteria = new SearchCallPersonVM(){FirstName = "Sam"};
     Int64 returnValue = 0;
     // Add Stubs for other DAL methods!    
     callPersonDALHdl.Stub(x => x.DalMethod1(criteria)).IgnoreArguments().Return(100);

    
     //*** Act ***    
     returnValue = callPersonBLLHdl.BllMethod1(criteria);

    
     //*** Assert ***     
     Assert.AreEqual(returnValue,1);
}




[Test]
public void BllMethod1_TestSecondBranchByPassingMad()
{

     //*** Arrange***    

     SearchCallPersonVM criteria = new SearchCallPersonVM(){FirstName = "Mad"};
    
     Int64 returnValue = 0;
     // Add Stubs for other DAL methods!    
     callPersonDALHdl.Stub(x => x.DalMethod2(criteria)).IgnoreArguments().Return(100);



     //*** Act ***    
     returnValue = callPersonBLLHdl.BllMethod1(criteria);



     //*** Assert ***     
     Assert.AreEqual(returnValue, 2);
}




[Test]
public void BllMethod1_VerifyDalMethod1IsCalled()
{

     //*** Arrange***    
     SearchCallPersonVM criteria = new SearchCallPersonVM() { FirstName = "Sam" };

    
     // Add Stubs for other DAL methods!    
     callPersonDALHdl.Stub(x => x.DalMethod1(criteria)).IgnoreArguments().Return(100);

     //*** Act ***    
     callPersonBLLHdl.BllMethod1(criteria);

     //*** Assert ***     
     callPersonDALHdl.AssertWasCalled(x => x.DalMethod1(null),a=>a.IgnoreArguments());
}




[Test]

public void BllMethod1_VerifyDalMethod2IsCalled()
{

     //*** Arrange***    
     SearchCallPersonVM criteria = new SearchCallPersonVM() { FirstName = "Mad" };
    
     // Add Stubs for other DAL methods!    
     callPersonDALHdl.Stub(x => x.DalMethod2(criteria)).IgnoreArguments().Return(100);

    
     //*** Act ***    
     callPersonBLLHdl.BllMethod1(criteria);


     //*** Assert ***     
     callPersonDALHdl.AssertWasCalled(x => x.DalMethod2(null), a => a.IgnoreArguments());
}





// Demonstrating how to check for expected exceptions
[Test, ExpectedException(typeof(RulesException))]  // Decorate like this to check for a single specific exception
public void BllMethod1_RulesException()
{

      //*** Arrange***         
      SearchCallPersonVM criteria = new SearchCallPersonVM() { FirstName = "" };
      //*** Act ***    
      callPersonBLLHdl.BllMethod1(criteria);
}




//Demonstrating "With what parameters the dal call was made"
[Test]
public void BllMethod1_TestingDalParamtersWereCorrectlyPassedIn()
{

     //*** Arrange***    
     SearchCallPersonVM criteria = new SearchCallPersonVM() { FirstName = "Sam" };


     // Add Stubs for other DAL methods!    
     callPersonDALHdl.Stub(x => x.DalMethod2(criteria)).IgnoreArguments().Return(100);

    
     //*** Act ***    
     callPersonBLLHdl.BllMethod1(criteria);

     IList<object[]> args = callPersonDALHdl.GetArgumentsForCallsMadeOn(db => db.DalMethod1(Arg<SearchCallPersonVM>.Is.Anything));    


     SearchCallPersonVM finalVal =
          new SearchCallPersonVM();


     if (args != null && args.Count > 0)    
     {
          finalVal = (SearchCallPersonVM)(args[0][0]);
     }

    
     // assert.areequal(obj,obj) is not working well since we did not override the equal method         
     Assert.AreEqual(finalVal.FirstName, "Sam");    
     Assert.AreEqual(finalVal.LastName, "Brown");
}





//Demonstrating "How to check the number of times a method was called"
[Test]
public void BllMethod2_RepeatCalls()
{

     //*** Arrange***    
     SearchCallPersonVM criteria = new SearchCallPersonVM() { FirstName = "Mad" };


     // Add Stubs for other DAL methods!    
     callPersonDALHdl.Stub(x => x.DalMethod2(criteria)).IgnoreArguments().Return(100);



     //*** Act ***    
     callPersonBLLHdl.BllMethod2(criteria);



     //*** Assert ***     
     callPersonDALHdl.AssertWasCalled(c => c.DalMethod1(null), options => options.IgnoreArguments().Repeat.Times(4));
}




[Test]

public void BllMethod3_MultipleRulesException()
{

     //*** Arrange***    
     SearchCallPersonVM criteria = new SearchCallPersonVM(){FirstName = "John"};
     try    
     {
           //*** Act ***         
           callPersonBLLHdl.BllMethod3(criteria);
     }
     catch(RulesException ex)    
     {

          if (ex.GetType() == typeof(RulesException))         
         {
               ErrorInfo[] errors = ((RulesException)ex).Errors.ToArray();
               Assert.AreEqual(errors[0].ErrorMessage,
"Name cannot be John");    
          }
  }



//Get the arguments that were passed into internal DAL method.
[Test]
public void TestMethod1_criteriaWithPropertyOfCtrIdGreaterThan0()
{

     // Test created by powershell on 02/15/2013 14:32:30//*** Arrange***
     StaffProfilesRptVM TestCriteria = new StaffProfilesRptVM() { CtrId = 15 };




     //*** BLL and DAL Stubs ***
     mockSelfTestDALHdl.Stub(x => x.DDLForStaff(TestCriteria)).IgnoreArguments().Return(new List<DDLDispValueCV>(){});



     //*** Act ***
     selfTestBLLHdl.TestMethod1(TestCriteria);

    
     IList<object[]> args = mockSelfTestDALHdl.GetArgumentsForCallsMadeOn(db => db.DDLForStaff(Arg<StaffProfilesRptVM>.Is.Anything));StaffProfilesRptVM finalVal = new StaffProfilesRptVM();


     if (args != null && args.Count > 0)
     {
          finalVal = (StaffProfilesRptVM)(args[0][0]);
     }



      //*** Assert ***


     Assert.AreEqual(finalVal.CtrId, 22);// Even though i set the ctr_id as 15, it should be called with 22, if i entered this if cluase.
     }


}

Wednesday, January 9, 2013

NHibernate.NonUniqueObjectException inserting a unique class , but it says it's already in the session

Okay,

So I'm inserting new records, Retreived by ADO and inserting with Nhibernate, cause that's how it done here at JCDC. I'm getting NHibernate.NonUniqueObjectException for no discernible reason.





Well, there is a reason. Nhibernate has lots of weird rules about the map it uses to keep track of changes to the state before .commit is called. When you're updating with objects not retrieved by NHibernate, sometimes it gets squirrely. Wish I had better details but there it is, look at the link above and follow the link there to Aiendes explanation for more details (not better really just more).

But here is how I fixed it, I got ahold of the NH session object and merged the object i'm inserting before I inserted it, and voilia, it stopped throwing an exception.





public void InsertDedHist( DedHistCV userInput )
{

 if( IdList.Contains( userInput ) )
 {

     throw new Exception("BUG FOUND!!!!");
 }

 else 
 { 
     IdList.Add( userInput ); 
  }
 

 try 
 { 
     Trace.WriteLine("");
     DedHistEO temp = new DedHistEO();
     temp.InjectFrom( userInput );
     DedHistEO mergedEo = (DedHistEO)JcdcDb.GetSession().Merge( temp );
     DedHistEO userInput2 = JcdcDb.Insert<DedHistEO>( mergedEo );
 }

 catch ( Exception ex )
 {

  throw;
 }
}