|
Hi,
If i want to test on event handler, how can i initialize the value to?
fyi,i'm using unit testing features in vsts2008
For example,
private void txtDate_KeyPress(object sender, KeyPressEventArgs e)
{
// Numbers, slash only
if ((e.KeyChar >= '0' && e.KeyChar <= '9') || (int) e.KeyChar == 8 || e.KeyChar == '/')
{
e.Handled = false;
}
else if ((int) e.KeyChar == 13)
{
txtMiles.Focus();
}
else
{
e.Handled = true;
}
}
(auto generated when i create unit testing)
[Test Method]
public void txtDate_KeyPressTest()
{
frmMileage_Accessor target = new frmMileage_Accessor(); // TODO: Initialize to an appropriate value
object sender = null; // TODO: Initialize to an appropriate value
KeyPressEventArgs e = null; // TODO: Initialize to an appropriate value
target.txtDate_KeyPress(sender, e);
}
modified on Friday, April 24, 2009 3:25 AM
|
|
|
|
|
User interface testing is a thorny subject to say the least. If you really want real in depth testing of your user interface then my advice to you is to head for model view controller pattern. That pattern's main goal is the separation of concerns between the three entities that give it its name.
More generally speaking you don't need a method to return some value in order to unit test it.
One possible way of asserting a result in your case would be to make a simple unit test that says if input key char is 13 then make sure that after the txtDate_KeyPress is called the txtMiles has focus.
then another unit test would asset that if the key char is between this and that, e.handled is true. or false.
the way you have it set up:
[Test Method]
public void txtDate_KeyPressTest()
{
frmMileage_Accessor target = new frmMileage_Accessor(); // TODO: Initialize to an appropriate value
object sender = null; // TODO: Initialize to an appropriate value
KeyPressEventArgs e = null; // TODO: Initialize to an appropriate value
target.txtDate_KeyPress(sender, e);
}
i would do something like this:
[Test Method]
public void txtDate_KeyPressTest_Enter()
{
//Arrange
frmMileage_Accessor target = new frmMileage_Accessor();
object sender = null; // Does not matter since you're not using this parameter
KeyPressEventArgs args = new KeyPressEventArgs((char)13);
//Act
target.txtDate_KeyPress(sender, args);
//Assert
Assert.IsTrue(target.txtMiles.Focused);
}
[Test Method]
public void txtDate_KeyPressTest_Number()
{
//Arrange
frmMileage_Accessor target = new frmMileage_Accessor();
object sender = null; // Does not matter since you're not using this parameter
KeyPressEventArgs args = new KeyPressEventArgs((char)50);
//Act
target.txtDate_KeyPress(sender, args);
//Assert
Assert.IsFalse(args.Handled);
}
...
etc.
also, consider using Char.IsDigit(e.KeyChar) instead of e.KeyChar >= '0' && e.KeyChar <= '9'. it's a bit more clear
Regards
|
|
|
|
|
Thanks for previous answer. How about the following?
private void btnSave_Click(object sender, EventArgs e)
{
// Save mileage data
int i;
sfdFiles.Filter = "Files (*.gas)|*.gas";
sfdFiles.DefaultExt = "gas";
sfdFiles.Title = "Save Mileage File";
if (sfdFiles.ShowDialog() == DialogResult.OK)
{
StreamWriter sw = new StreamWriter(sfdFiles.FileName);
this.Text = "Gas Mileage-" + sfdFiles.FileName;
sw.WriteLine(numValues);
for (i = 0; i < numValues; i++)
{
sw.WriteLine(dates[i]);
sw.WriteLine(odometer[i]);
sw.WriteLine(gallons[i]);
}
sw.Close();
}
}
[TestMethod()]
public void btnSave_ClickTest()
{
frmMileage_Accessor target = new frmMileage_Accessor(); // TODO: Initialize to an appropriate value
object sender = null; // TODO: Initialize to an appropriate value
EventArgs e = null; // TODO: Initialize to an appropriate value
target.btnSave_Click(sender, e);
//Assert.Inconclusive("A method that does not return a value cannot be verified.");
}
I should initialize value to EventArgs? I have problem to assign value to EventArgs. How is the correct answer look like?
|
|
|
|
|
you don't use that variable in your method body so i guess null would be as fine as anything else
|
|
|
|
|
How m i going to test this kind of function?
private void saverecord()
{
OleDbConnection savecon = new OleDbConnection(constring);
OleDbCommand savecom = new OleDbCommand("insert into Employee_Details values (?,?,?)", savecon);
OleDbParameter param;
param = savecom.Parameters.Add("@empcode", OleDbType.VarChar, 10);
param.Value = txtcode.Text;
param = savecom.Parameters.Add("@empname", OleDbType.VarChar, 25);
param.Value = txtname.Text;
param = savecom.Parameters.Add("@empjoin", OleDbType.Date);
param.Value = DateTime.Now.ToShortDateString();
savecon.Open();
int rows = savecom.ExecuteNonQuery();
MessageBox.Show(rows.ToString() + "rows affected");
btnref.PerformClick();
savecon.Close();
}
[TestMethod()]
public void saverecordTest()
{
Form1_Accessor target = new Form1_Accessor(); // TODO: Initialize to an appropriate value
target.saverecord();
//Assert.Inconclusive("A method that does not return a value cannot be verified.");
}
|
|
|
|
|
Hi,
I am trying to enable password recovery, with the following settings:
<membership defaultprovider="SqlMembershipProvider" userisonlinetimewindow="15">
<providers>
<clear />
<add name="SqlMembershipProvider">
type="System.Web.Security.SqlMembershipProvider"
connectionStringName="Gendac.Grintek.Abatis.DataAccess.Properties.Settings.PerimeterMainConnectionString"
applicationName="Abatis ClientUI"
enablePasswordRetrieval="true"
enablePasswordReset="true"
requiresQuestionAndAnswer="false"
requiresUniqueEmail="false"
passwordFormat="Encrypted"
minRequiredPasswordLength="3"
minRequiredNonalphanumericCharacters="0"/>
</add></providers>
</membership>
I know that I have to change the default machineKey, but I don't know how.
I think the machine key must be set in one of the files in C:\Windows\Microsoft.NET\Framework\v2.0.50727\CONFIG, but I don't know where and how.
Any help would be much appreciated.
This is my error:
You must specify a non-autogenerated machine key to store passwords in the encrypted format. Either specify a different passwordFormat, or change the machineKey configuration to use a non-autogenerated decryption key
Kind regards,
Higs
|
|
|
|
|
|
|
mostafatajamolian wrote: please give me code
Read the documentation[^] and try it yourself
I are troll
|
|
|
|
|
Well, you could do this using regular expressions, but personally I'd write a little function which iterates over the string and works it out (using StringBuilder) - that'd be quite a bit quicker.
Regards,
Rob Philpott.
|
|
|
|
|
easy...
string text = "abokf.okhj.jkoklk.";
string start = "ok";
string end = ".";
string replace = "D";
string answer = "abokD.okD.jkokD.";
console.WriteLine(answer);
of course you could optimise it...
console.WriteLine("abokD.okD.jkokD.");
...or perhaps you wanted something different
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
You sarcastic bunch!
This is a really difficult problem (if you have no experience and your IQ is smaller than your shoe size) so give the chap a break.
Just because it would take us less than a minute to complete (or two if we did it manually, rather than use built in members) doesn't mean we should take the piss out of really lazy students who want us to do thier homework for free.
So, the complete solution:
string s = "abokf.okhj.jkoklk.";
string startString = "ok";
string endString = ".";
string replacementString = "D";
while (ReplaceAllIncidencesOfDataDelimitedByTwoStringsWithAnotherStringForReallyLazyStudentsWithNoIdeaNoExperienceAndAnIQSmallerThanTheirShoeSize(ref s, startString, endString, replacementString))
{
}
Console.Writeline(s);
Obviously, you will need the method "ReplaceAllIncidencesOfDataDelimitedByTwoStringsWithAnotherStringForReallyLazyStudentsWithNoIdeaNoExperienceAndAnIQSmallerThanTheirShoeSize" and it is here, with all the others:
http://PleaseDoMyHomeworkForMe.com/ComputerProjects/UnbelievablySimple/Index.html
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced
|
|
|
|
|
|
I created an Animal class, then I created a Dog class and a Cat class that inherited from the Animal class. Then the Dog class ate my homework.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
|
Hi
Wonder if anyone out there can help me.
I have been working on retrieving data from xls files using ole and have had no problems until i received a file that is causing me considerable greif.
The file in question is 26k in size and is a simple headed workbook with 2 pages.
When I connect to the file and try to retreive schema info (using schema = GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" })) no table rows (pages) are found (ie schema.Rows is null).
If I open the file in Excel and click on the save button (without making any changes) the file grows by 10k in size and the data can then be retrieved without any problems!!???
Has anyone out there ever experienced an issue of this nature and if so, could you possibly explain what is making this happen.
Many thanks in advance to anyone who can help,
Steve
|
|
|
|
|
Now you begin to understand why most devs avoid Excel like the plague. We force the supplier to send us CSV files, this would mean you get 2 files for multiple pages.
Excel OLEDB connections are too fragile in my opinion, you have no control over the excel sheet, I could go on for many additional reasons not to use Excel. This is not helping you, sorry.
You may end up in the position where you need to read in each cell from each sheet.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I work with this:
conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables_Info, null);
check the excel version maybe it is related
Natza Mitzi
|
|
|
|
|
{"DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'UserId'."}
|
|
|
|
|
It looks like you have a control (e.g. GridView) for which you have specified a column with the DataItem UserId but the UserId does not exist in the object you are binding to the gridview. Check your gridview data source contains a UserId column/property.
|
|
|
|
|
The answer is the same as it was yesterday. And the day before.
You need to do three things:
- Read what people have said.
- Take action based upon it.
- Discover magical fairy la la land where your grade school code works.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
|
It means you're too stupid to use a computer. Put it in it's box, take it back to the store, and choose a different course.
Christian Graus
Driven to the arms of OSX by Vista.
"I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )
|
|
|
|
|
You really need to read the answers from your last post. And get a book about data binding!
|
|
|
|
|
It means the psychic link has failed to update your code to supply a UserId.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|