Had a few occasions where a Partial mock was calling the real method even though an expectation had been defined.
The reason was that the method being called was not marked as Virtual and so not being overridden by the mock repository.
This blog is a record of some development issues I have faced. There may be something of use!
Had a few occasions where a Partial mock was calling the real method even though an expectation had been defined.
The reason was that the method being called was not marked as Virtual and so not being overridden by the mock repository.
See article here to encrypt or decrypt section of web.config file.
XML Method comments are not being displayed by intellisense for methods of classes other than those in the same project.
Any referenced DLL must have the XML file which contains the comments in the same directory as the DLL itself.
Very interesting article here: CodeProject:AspNetService detailing how to simulate a windows service running completely within Aps.Net using cache item call backs.
If the PC does not have the .NET SDK installed then the configuration tool will not be available via Control Panel -> Admin. Tools. Instead a command line tool CasPol.exe must be used:
The command line tool exists in C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\
The command for setting Intranet as full trust is:
CasPol.exe -q -m -ag All_Code -zone Intranet FullTrust
When using the Edit functionality of a DataGridView it is easy to fall into the trap of selecting the wrong row to edit when running in a multi-user environment.
When user clicks row to edit you must store the ID of the row (not its index), then just prior to data-bind find the index of the selected ID in the data-source and set the EditIndex, this means if another user adds or removes rows in between the the current user clicking edit the correct row will be selected.
Query to get job title of staff or null if staff not assign a job-title:
SELECT CORE_Staff.ID, CORE_Staff.JobTitleID, CORE_JobTitle.Name
FROM CORE_Staff LEFT JOIN CORE_JobTitle
ON CORE_JobTitle.ID = CORE_Staff.JobTitleID
where (CORE_JobTitle.Name='Driver') or (CORE_JobTitle.Name is null)
Had a problem where I was creating a partial mock then calling a method of the partial mock which was returning 0 (zero).
The base method was not being called even though no expectations had been setup.
The reason for this was that the ReplayAll (and VerifyAll) methods of Rhino Mocks was not being called.
Original code:
_interestBiz = _mocks.PartialMock<InterestBiz>();
int baseDay = _interestBiz.GetBaseDaysFromAccount(account);
Assert.AreEqual(365, baseDay, "Incorrect base days");
Fixed code:
_interestBiz = _mocks.PartialMock<InterestBiz>();
using (_mocks.Record())
{
}
using (_mocks.Playback())
{
int baseDay = _interestBiz.GetBaseDaysFromAccount(account);
Assert.AreEqual(365, baseDay, "Incorrect base days");
So even though no expectations were set Rhino Mocks needs to no this.
Using ThreadSafeQueue class as list of items to process.
Class used as a worker, takes list as parameter, creates a thread to run in.
public class MyWorker
{
private Thread _myThread;
public Thread WorkerThread
{
get { return _myThread; }
set { _myThread = value; }
}
ThreadSafeQueue<int> _listOfNumbers;
public string NumbersProcess = string.Empty;
int total=0;
public MyWorker(ThreadSafeQueue<int> listOfNumbers)
{
_listOfNumbers = listOfNumbers;
_myThread = new Thread(new ThreadStart(this.DoProcess));
}
public void DoProcess()
{
int _localInt=0;
do
{
if (_listOfNumbers.TryDequeue(out _localInt))
{
total = total + _localInt;
NumbersProcess = NumbersProcess + _localInt.ToString() + ", ";
}
} while ((!_listOfNumbers.NoMoreItems) ||
(_listOfNumbers.NoMoreItems) && (_listOfNumbers.Count > 0));
}
}
Calling process creates 5 workers then populates list, then waits for workers to finish processing:
//Queue to hold numbers to process
ThreadSafeQueue<int> listOfInts = new ThreadSafeQueue<int>();
//5 worker objects (threads)
MyWorker[] workers = new MyWorker[5];
for (int i = 0; i < workers.Length; i++)
{
workers[i] = new MyWorker(listOfInts);
workers[i].WorkerThread.Start();
}
//Populate list to process
for (int i = 0; i < 1000; i++)
{
listOfInts.Enqueue(i);
}
//Flag that no more items will be added to queue
listOfInts.NoMoreItems = true;
//Wait for workers to finish then display details
foreach (MyWorker worker in workers)
{
worker.WorkerThread.Join(); //Wait for worker to finish processing.
tbxDetail.Text=tbxDetail.Text+string.Format("Numbers processsed {0} \n",worker.NumbersProcess);
}
tbxDetail.Text = tbxDetail.Text + string.Format("\n\n");
See full discussion here
public myClass() : base()
class myClass
{
public myClass()
{
//No parameters
}
public myClass(string param1) : this()
{
//No parameters will be called before me!
}
}
Getting huge amount of "A first chance exception" messages when running web-site under IDE for first time (after a rebuild).
These were being reported because programmer had turned off 'Just my code' within Tools->Options->Debugging->General
Date format is 'YYYY-MM-DD'
e.g.
select * from orders where Date='2008-04-22'
from Activity a where a.Date between '2008-01-01' and '2008-02-29'
Had apparently strange goings on with IIS & Asp.Net.
Delivered new mylibrary.dll. User renamed mylibrary.dll to "old mylibrary.dll", copied in new mylibrary.dll. Got error saying 'old mylibrary.dll' could not be loaded into manifest.
After deleting the 'old mylibrary.dll' files the web site loaded ok.
After a discussion we came to the conclusion that IIS loads all the DLL files in the BIN directory irrespective of references within Web.Config.
The site then throws exception when two dlls contain the same Assembly-name - this also makes sense.
So what appeared to be strange behaviour came down to not thinking logically!
There is a bug with the AJAX calendar extender in that the style of the popup calendar are not applied if the text-box /calendar extender are hidden when a page first loads.
e.g. Panel with Details on is only shown once valid record found; if the first calendar extender on the page is within this hidden Details panel the calendar will not be displayed correctly when Details does become visible:
To fix this have a hidden calendar extender at top of the page:
<!-- Workaround for Calendar not displaying correctly - if hidden when page first loads -->
<div style="display: none"><asp:TextBox runat="server" ID="textbox1" /><cc1:CalendarExtender ID="ceTextBox1" runat="server" TargetControlID="textbox1" /></div>
Calendar is then displayed correctly:
Run CRRedist2005_x86.msi (taken from C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\BootStrapper\Packages\CrystalReports\)
Copy C:\Inetpub\wwwroot\aspnet_client to root of website)
Report (design-time) connection was SQL-Native changed to be SQLOLEDB.
CrystalDecisions.Shared.TableLogOnInfo tliCurrent;
foreach (CrystalDecisions.CrystalReports.Engine.Table tbCurrent in crSource.ReportDocument.Database.Tables)
{
tliCurrent = tbCurrent.LogOnInfo;
tliCurrent.ConnectionInfo.ServerName = server;
tliCurrent.ConnectionInfo.UserID = username;
tliCurrent.ConnectionInfo.Password = password;
tliCurrent.ConnectionInfo.DatabaseName = dbname;
tbCurrent.ApplyLogOnInfo(tliCurrent);
}
The toolbar options were not working because a post-back was being generated that performs the functionality - the assigning of the report was within a !IsPostBack block. As the report is not held in state it must be reloaded during post back.
Was testing catching NHibernate.StaleObjectStateException (exception where one user updates a record which another user then attempts to update without getting newer version).
Was getting 'Failed to initialise lazy..." when reloading record on associated collection due to a timeout and also appeared to be locking the server (no queries could be run on tables involved in failed update)
It came down to the transaction not being Rolled-back when exception thrown - so obviously DB still in transaction.