|
I'm talking about a fully fledged message queue, not some baked into a framework one. A full Message Queue should guarantee delivery when it is possible to do so. You might want to have a read of this article[^] on MSMQ for an interesting take on things.
This space for rent
|
|
|
|
|
That's a very interesting question ... got my vote.
Let me ask a question that, in this context, may be/seem naive. Isn't the kind of mutually-assured-notification you describe only possible with some "outside entity" like a server, to maintain the message queue ?
My object B, located wherever, sends a message to its "address" for your object A: absent response from A, what else can B know other than A has not responded. Is it an error in my App that I believe the message was sent, but it was not sent ? Did the facility I sent the message to fail ? Did the sender get the message, but never sent it ? Was the message sent, but not received because A's reception facility failed ? Did A get the message, but has not responded ? Did A send a response, but A's sender failed ? Did B's receiver fail ?
"Who's on First"
Okay, my App closes down, the message to A, and the fact it is not responded, to is saved; now, I re-open my App, B is instantiated, and B sees that it has a message sent to A in its un-responded-to queue ... and ?
Now, throw in the issue of the reliability of the third-party entity ... and your headed into quis custodiet custodes territy.
«In art as in science there is no delight without the detail ... Let me repeat that unless these are thoroughly understood and remembered, all “general ideas” (so easily acquired, so profitably resold) must necessarily remain but worn passports allowing their bearers short cuts from one area of ignorance to another.» Vladimir Nabokov, commentary on translation of “Eugene Onegin.”
|
|
|
|
|
The scenario can be seen from many points of view. I added a small example to show the problem. It is a design question where to implement the responsibility for the information getting to its addressee.
|
|
|
|
|
Bernhard Hiller wrote: We have to take care of a flock of sheep. A shepherding drone is hovering over the area and searching for wolves. After detection of a wolf, it will notify the dogs and tell them where the wolves are etc. In most case there is one drone and one dog, but sometimes there may be many. With some trees around, the connection between the drone and the network may get disrupted.
An alternative solution is the dogs querying the drone's LastWolfDetected property in short intervals. Or the drones sending the LastWolfDetected message to a server, and the dogs query the server.
Anyway, the dogs must be informed reliably. If (may the sheep be so unlucky, and the wolves so lucky, and the dogs confused) I were the shepherd here, and had the resources, and the means, I would like:
1. the server: keeps a time-stamped log of all contacts with every drone, every dog; a integral part of these logs is a list of all periods of time when a connection check (perhaps every #n minutes) fails. Hopefully this check could be some kind of lightweight "ping."
when the drone signals the server that a wolf is spotted, the message goes into an "alert queue" ... if the server fails to respond immediately to acknowledge the alert message, the drone repeats sending the message frequently which is also packaged with a log of previous tries, or time-stamped with when the first message was sent.
so, the server, receiving the alert can know from the message if it had been sent previously, when it was sent, etc.
the server maintains a parallel logging facility for the active dogs.
2. the drones: if it is possible for them to contact the dogs directly, and the dogs can signal the server that they received an alert message from a drone, then, the dogs ... assuming they can respond to gps co-ordinates ... can go immediately to the area where the alert was raised, as well as signalling the server they are in action.
The idea here being redundancy, and if the server is down, the dogs can still be called into action by the drones. If the drones are down, perhaps the server could direct the dogs to enter "reconnoiter mode" ? Could the dogs also raise an alert ... consider the dogs could smell a wolf ?
Of course, this is all wool-gathering.
«In art as in science there is no delight without the detail ... Let me repeat that unless these are thoroughly understood and remembered, all “general ideas” (so easily acquired, so profitably resold) must necessarily remain but worn passports allowing their bearers short cuts from one area of ignorance to another.» Vladimir Nabokov, commentary on translation of “Eugene Onegin.”
modified 3-Mar-16 8:11am.
|
|
|
|
|
|
That's what Pete suggested above.
|
|
|
|
|
Great minds think alike!
|
|
|
|
|
Hi All,
I am new to Unit Testing. Need your help in understanding how to use reflection in unit test case.i am using N-Unit Framework for writing unit test.
How to write unit test case for function "GetStudentinfo" in which private field "Studentresult" is updating. How to check this list value in unit test in order to compare expected and actual value using Assertions.
class Updatestdinfo
{
private enum Result
{
Firstclass,
secondclass
}
private List<int, Result > Studentresult = new List<int, Result >();
public void GetStudentinfo()
{
Studentresult[0] = Result.secondclass;
}
}
I tried to use reflection [gettype, getmethod] inorder to get the ENum type so that i can define list to initialize the expected value which can be used in Assert method. But its not returning the type of object. How can i resolve this?
modified 2-Mar-16 0:31am.
|
|
|
|
|
In the .Net world, a test class can inherit from the class under test.
[TestFixture]
public class UpdatestdinfoTests : Updatestdinfo
Change the access modifiers from private to protected , and voila, it works. No reflection required.
|
|
|
|
|
Thanks for your fast reply.
You are suggesting me to change the access modifier from private to protected.But i don't want to change the design of code for unit testing purpose.So how can i proceed?
Regards,
Mala
modified 3-Mar-16 1:33am.
|
|
|
|
|
Take a look at
Michael C. Feathers: Working Effectively with Legacy Code
|
|
|
|
|
May I suggest you read the discussion here: [^], and think about whether unti-testing of the private "details" of your objects is really a requirement.
But, if you have to do it, note that Microsoft's testing facility hands you tools like 'PrivateObject and 'PrivateType.
Without seeing your code where you try and test an 'Enum, I don't think much can be said except that, yes, it can be done.
«In art as in science there is no delight without the detail ... Let me repeat that unless these are thoroughly understood and remembered, all “general ideas” (so easily acquired, so profitably resold) must necessarily remain but worn passports allowing their bearers short cuts from one area of ignorance to another.» Vladimir Nabokov, commentary on translation of “Eugene Onegin.”
|
|
|
|
|
Thanks for the info.
Yes i wanted to check the private variable in unit testing as the method is having void as return type. So decided to check the variable values in order to do assertions.
I am able to get the private primitive data type [int, string] variables. but facing issue in accessing private custom data type i.e., user defined data types.
So please help me out.
|
|
|
|
|
/*I retrieve key value pairs for each of the conditions. The error is in the bolded. First condition returns longitude & latitude pairs. The third condition returns "State" and "WY" or "County"and "Buffalo", so that works fine. If it contains an "ID", it errors when the kvp consist of "value" = LocationID (corresponds to column name) that has empty string in uppercase "Value", because some are empty in the database */
public static tbl_Location ParseLocation(IOrderedDictionary values)
{
tbl_Location locFromValues = new tbl_Location();
foreach (DictionaryEntry value in values)
{
if (value.Key.Equals("Latitude") ||
value.Key.Equals("Longitude"))
{
double? valueAsNumber = null;
try { valueAsNumber = double.Parse(value.Value.ToString()); }
catch { }
locFromValues.GetType().GetProperty(value.Key.ToString()).SetValue(locFromValues, valueAsNumber);
}
else if (value.Key.ToString().Contains("ID"))
{
int? valueAsNumber = null;
try { valueAsNumber = int.Parse(value.Value.ToString()); }
catch { }
locFromValues.GetType().GetProperty(value.Key.ToString()).SetValue(locFromValues, valueAsNumber);
}
else
{
locFromValues.GetType().GetProperty(value.Key.ToString()).SetValue(locFromValues, value.Value);
}
}
return locFromValues;<pre lang="c#">
//I tried several ways for nullable int to take empty strings but it doesn't work, without adding another return in the catch. I have a return at the end of code block. Thank you.
|
|
|
|
|
Sam 9100 wrote: try { valueAsNumber = int.Parse(value.Value.ToString()); }
catch { }
That's a cardinal sin; an empty catch-block hides any error and acts as if nothing happened.
There's Int32.TryParse[^], which you might want to try;
if (!Int32.TryParse(Convert.ToString(value.Value), out valueAsNumber)
valueAsNumber = 0;
You could explicitly check for DBNull.Value and assign a value for empty-fields only, but the above would assume that everything that can't be converted to a number is equal to zero.
Do take into consideration that the example is non-localized and simplified; you might need to specify which culture you are expecting to validate the string correctly as a number.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Thank you for the reply Eddie. That code did not work either. I wish I could post screen shot for you. I inherited this project so here is more info to help.
This BLL code loops thru COLs and values with same values in the db. This particular field is datatype int that allows null. Due to key value pairs, the .Contains("ID") will show key=StatusID value=2004 (which works fine), or key=PostID value="". If empty strings, it shows null for int? Hence the "input string incorrect format" error.
int? valueAsNumber = null; shows null
During debug, the begin code and next step after this section wants it as an int. Here due to the key pair values, it does not like empty strings. But it allows null in db? It also says "to ignore exceptions to retain NULL when parsing" only in this section are the Catch blocks empty.
This is MVC, Entity Framework 6.1, C#, asp.net 4.5
I also tried if the value contains("ID") or Contains("") or == null, it didnt like it. The textbox expects an int returned
|
|
|
|
|
Eddie's right about the code smell of the try with an empty catch . Use int.TryParse to determine if there's a parsing error.
If value.Value is an empty string then the parsing will fail.
(Since you aren't getting a NullReferenceException on the .ToString() it means that value.Value isn't null .)
So what you should do first is to check value.Value for being empty.
public static tbl_Location ParseLocation(IOrderedDictionary values)
{
tbl_Location locFromValues = new tbl_Location();
Type locType = typeof(tbl_Location);
foreach (DictionaryEntry value in values)
{
string key = value.Key as string;
if (key == null)
throw new InvalidOperationException(string.Format("Key is not a string: {0}", value.Key);
string val = value.Value as string;
bool emptyValue = string.IsNullOrEmpty(val);
object storableValue = null;
if (key.Equals("Latitude") || key.Equals("Longitude"))
{
double parsed;
if (!emptyValue && double.TryParse(val, out parsed))
storableValue = parsed;
}
else if (key.Contains("ID"))
{
int parsed;
if (!emptyValue && int.TryParse(val, out parsed))
storableValue = parsed;
}
else
{
storableValue = val;
}
locType.GetProperty(key).SetValue(locFromValues, storableValue);
}
return locFromValues;
}
All of a sudden you mention TextBox .
The TextBox's .Text property expects a string value.
So where is the value from the PostID property of the tbl_Location get put into this TextBox 's .Text property you mention?
That is probably where the "null" from "parsing" the empty string gets displayed.
"Fairy tales do not tell children the dragons exist. Children already know that dragons exist. Fairy tales tell children the dragons can be killed."
- G.K. Chesterton
|
|
|
|
|
Sorry for the late reply, but thank you both for your help. There is more to it than this from what I investigate. However, I have replaced the empty catch block with the if else TryParse. It is cleaner and better. What this is supposed to do is retrieve matching data from gridviewOne and gridviewTwo, and displaying results in gridviewResults with a new ID. The db is returning the ID to the BLL class (above), but it does not return all the way to the view forms. So the actual error has been resolved, but a prior change (undocumented) occurred where an ID was overridden so the next error I generate is object null reference error. My CO brought me in to fix the bug because no one knows what happened. But I appreciate your assistance and I will gladly post for more help as you guys are the best! Keep up the good work!
|
|
|
|
|
I am getting error in the bold line. i have column name as paword but its showing column name doesnt belong to the table
public Userdetails GetUserDetailsByEmailID(String EmailID)
{
Userdetails userInfobyEmailID = null;
NpgsqlParameter[] parameters = new NpgsqlParameter[] {
new NpgsqlParameter("@email", EmailID)
};
using (DataTable table = Helper.ExecuteParamerizedSelectCommand("forgetpassword", CommandType.StoredProcedure, parameters))
{
if (table.Rows.Count > 0)
{
userInfobyEmailID = new Userdetails();
foreach (DataRow row in table.Rows)
{
userInfobyEmailID.paword = Utilities.Decrypt(row["paword"].ToString());
}
}
return userInfobyEmailID;
}
}
|
|
|
|
|
Are you certain that is the correct spelling of the column name?
|
|
|
|
|
no in table also name is same
|
|
|
|
|
I find that hard to believe. Show the exact details of what gets posted into your DataTable from the stored procedure.
|
|
|
|
|
Also, please do not post the same question in a forum and QA.
|
|
|
|
|
Did you miss all those replies to your last question where we suggested you read up on how to securely handle passwords in your application? Or did you just choose to ignore them?
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
The passwords are well hidden in a field with unknown name...
|
|
|
|
|