-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Notification rule index #1229
Notification rule index #1229
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -110,101 +110,230 @@ public void InsertOptionalDataVisitor_PersistsAll() | |
OptionallyEmittedData.FlattenedMessages); | ||
} | ||
|
||
[Fact] | ||
public void InsertOptionalDataVisitorTests_FlattensGlobalMessageString() | ||
{ | ||
string ruleId = nameof(ruleId); | ||
string globalMessageId = nameof(globalMessageId); | ||
string globalMessageValue = nameof(globalMessageValue); | ||
private const int RuleIndex = 0; | ||
private const string RuleId = nameof(RuleId); | ||
private const string NotificationId = nameof(NotificationId); | ||
|
||
private const string SharedMessageId = nameof(SharedMessageId); | ||
private const string SharedKeyRuleMessageValue = nameof(SharedKeyRuleMessageValue); | ||
private const string SharedKeyGlobalMessageValue = nameof(UniqueGlobalMessageValue); | ||
|
||
private const string UniqueRuleMessageId = nameof(UniqueRuleMessageId); | ||
private const string UniqueRuleMessageValue = nameof(UniqueRuleMessageValue); | ||
|
||
private const string UniqueGlobalMessageId = nameof(UniqueGlobalMessageId); | ||
private const string UniqueGlobalMessageValue = nameof(UniqueGlobalMessageValue); | ||
|
||
private static Run CreateBasicRunForMessageStringLookupTesting() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Love the method name. #Closed |
||
{ | ||
// Returns a run object that defines unique string instances both | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This is a good comment. Ultra-nit: IMO it is a method summary comment so it belongs outside the method body. (I am not suggested XML docs.) #Closed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Considering how good the method name is, you probably considered it self-documenting, and considered this more of an implementation comment. I can get on board with that. In reply to: 249608056 [](ancestors = 249608056) |
||
// for an individual rule and in the global strings object. Also | ||
// defines values for a key that is shared between the rule object | ||
// and the global table. Used for evaluating string look-up semantics. | ||
var run = new Run | ||
{ | ||
Results = new List<Result> | ||
{ | ||
new Result | ||
{ | ||
RuleId = ruleId, | ||
RuleIndex = 0, | ||
Message = new Message | ||
{ | ||
MessageId = globalMessageId | ||
} | ||
} | ||
}, | ||
Results = new List<Result> { }, // add non-null collections for convenience | ||
Invocations = new List<Invocation> { new Invocation { } }, | ||
Resources = new Resources | ||
{ | ||
MessageStrings = new Dictionary<string, string> | ||
{ | ||
[globalMessageId] = globalMessageValue | ||
[UniqueGlobalMessageId] = UniqueGlobalMessageValue, | ||
[SharedMessageId] = SharedKeyGlobalMessageValue | ||
}, | ||
Rules = new List<Rule> | ||
{ | ||
new Rule | ||
{ | ||
Id = ruleId | ||
Id = RuleId, | ||
MessageStrings = new Dictionary<string, string> | ||
{ | ||
[UniqueRuleMessageId] = UniqueRuleMessageValue, | ||
[SharedMessageId] = SharedKeyRuleMessageValue | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
|
||
run.Invocations[0].ToolNotifications = new List<Notification>(); | ||
run.Invocations[0].ConfigurationNotifications = new List<Notification>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Object initialization syntax FTW. On Line 136 above:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doing this introduces 6 new lines of vertical space, which is why I avoided it. Why doesn't this provoke your 'chunking' need? :) I did take the note, btw In reply to: 249608580 [](ancestors = 249608580) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Everything is a tradeoff. The question is, what do I get back from those 6 lines? For me, in this case, the answers are:
In reply to: 249836127 [](ancestors = 249836127,249608580) |
||
|
||
return run; | ||
} | ||
|
||
[Fact] | ||
public void InsertOptionalDataVisitorTests_FlattensMessageStringsInResult() | ||
{ | ||
Run run = CreateBasicRunForMessageStringLookupTesting(); | ||
|
||
run.Results.Add( | ||
new Result | ||
{ | ||
RuleId = RuleId, | ||
RuleIndex = RuleIndex, | ||
Message = new Message | ||
{ | ||
MessageId = UniqueGlobalMessageId | ||
} | ||
}); | ||
|
||
run.Results.Add( | ||
new Result | ||
{ | ||
RuleId = RuleId, | ||
RuleIndex = RuleIndex, | ||
Message = new Message | ||
{ | ||
MessageId = UniqueRuleMessageId | ||
} | ||
}); | ||
|
||
|
||
run.Results.Add( | ||
new Result | ||
{ | ||
RuleId = RuleId, | ||
RuleIndex = RuleIndex, | ||
Message = new Message | ||
{ | ||
MessageId = SharedMessageId | ||
} | ||
}); | ||
|
||
|
||
var visitor = new InsertOptionalDataVisitor(OptionallyEmittedData.FlattenedMessages); | ||
visitor.Visit(run); | ||
|
||
run.Results[0].Message.Text.Should().Be(UniqueGlobalMessageValue); | ||
run.Results[1].Message.Text.Should().Be(UniqueRuleMessageValue); | ||
|
||
// Prefer rule-specific value in the event of a message id collision | ||
run.Results[2].Message.Text.Should().Be(SharedKeyRuleMessageValue); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, perfect test. #ByDesign |
||
|
||
[Fact] | ||
public void InsertOptionalDataVisitorTests_FlattensMessageStringsInNotification() | ||
{ | ||
Run run = CreateBasicRunForMessageStringLookupTesting(); | ||
|
||
IList<Notification> toolNotifications = run.Invocations[0].ToolNotifications; | ||
IList<Notification> configurationNotifications = run.Invocations[0].ConfigurationNotifications; | ||
|
||
// Shared message id with no overriding rule id | ||
toolNotifications.Add( | ||
new Notification | ||
{ | ||
Id = NotificationId, | ||
Message = new Message { MessageId = SharedMessageId} | ||
}); | ||
configurationNotifications.Add(toolNotifications[0]); | ||
|
||
// Shared message id with an overriding rule id. This message | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
How about this for the first sentence: "Notification that refers to a rule that contains a message with the same id as the specified notification message id." The second sentence still works. #Resolved |
||
// should still be retrieved from the global strings table. | ||
toolNotifications.Add( | ||
new Notification | ||
{ | ||
Id = NotificationId, | ||
RuleIndex = RuleIndex, | ||
Message = new Message { MessageId = SharedMessageId } | ||
}); | ||
configurationNotifications.Add(toolNotifications[1]); | ||
|
||
toolNotifications.Add( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Comment: "Notification that refers to a rule that does not contain a message with the same id as the specified notification id. In this case it is no surprise that the message comes from the global string table." ... and then I think the test reads most naturally if you reverse the order of notifications 1 and 2. #Resolved |
||
new Notification | ||
{ | ||
Id = NotificationId, | ||
RuleIndex = RuleIndex, | ||
Message = new Message { MessageId = UniqueGlobalMessageId } | ||
}); | ||
configurationNotifications.Add(toolNotifications[2]); | ||
|
||
|
||
var visitor = new InsertOptionalDataVisitor(OptionallyEmittedData.FlattenedMessages); | ||
visitor.Visit(run); | ||
|
||
run.Results[0].Message.Text.Should().Be(globalMessageValue); | ||
toolNotifications[0].Message.Text.Should().Be(SharedKeyGlobalMessageValue); | ||
configurationNotifications[0].Message.Text.Should().Be(SharedKeyGlobalMessageValue); | ||
|
||
toolNotifications[1].Message.Text.Should().Be(SharedKeyGlobalMessageValue); | ||
configurationNotifications[1].Message.Text.Should().Be(SharedKeyGlobalMessageValue); | ||
|
||
toolNotifications[2].Message.Text.Should().Be(UniqueGlobalMessageValue); | ||
configurationNotifications[2].Message.Text.Should().Be(UniqueGlobalMessageValue); | ||
} | ||
|
||
|
||
[Fact] | ||
public void InsertOptionalDataVisitorTests_FlattensFixMessage() | ||
public void InsertOptionalDataVisitorTests_FlattensMessageStringsInFix() | ||
{ | ||
string ruleId = nameof(ruleId); | ||
string globalMessageId = nameof(globalMessageId); | ||
string globalMessageValue = nameof(globalMessageValue); | ||
Run run = CreateBasicRunForMessageStringLookupTesting(); | ||
|
||
var run = new Run | ||
{ | ||
Results = new List<Result> | ||
run.Results.Add( | ||
new Result | ||
{ | ||
new Result | ||
RuleId = RuleId, | ||
RuleIndex = RuleIndex, | ||
Message = new Message | ||
{ | ||
Text = "Some testing occurred." | ||
}, | ||
Fixes = new List<Fix> | ||
{ | ||
RuleId = ruleId, | ||
RuleIndex = 0, | ||
Message = new Message | ||
new Fix | ||
{ | ||
Text = "Some testing occurred." | ||
Description = new Message | ||
{ | ||
MessageId = UniqueGlobalMessageId | ||
} | ||
}, | ||
Fixes = new List<Fix> | ||
new Fix | ||
{ | ||
new Fix | ||
Description = new Message | ||
{ | ||
Description = new Message | ||
{ | ||
MessageId = globalMessageId | ||
} | ||
MessageId = UniqueRuleMessageId | ||
} | ||
}, | ||
new Fix | ||
{ | ||
Description = new Message | ||
{ | ||
MessageId = SharedMessageId | ||
} | ||
} | ||
} | ||
}, | ||
Resources = new Resources | ||
}); | ||
run.Results.Add( | ||
new Result | ||
{ | ||
MessageStrings = new Dictionary<string, string> | ||
RuleId = "RuleWithNoRulesMetadata", | ||
Message = new Message | ||
{ | ||
[globalMessageId] = globalMessageValue | ||
Text = "Some testing occurred." | ||
}, | ||
Rules = new List<Rule> | ||
Fixes = new List<Fix> | ||
{ | ||
new Rule | ||
new Fix | ||
{ | ||
Id = ruleId | ||
Description = new Message | ||
{ | ||
MessageId = SharedMessageId | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
}); | ||
|
||
var visitor = new InsertOptionalDataVisitor(OptionallyEmittedData.FlattenedMessages); | ||
visitor.Visit(run); | ||
|
||
run.Results[0].Fixes[0].Description.Text.Should().Be(globalMessageValue); | ||
run.Results[0].Fixes[0].Description.Text.Should().Be(UniqueGlobalMessageValue); | ||
run.Results[0].Fixes[1].Description.Text.Should().Be(UniqueRuleMessageValue); | ||
|
||
// Prefer rule-specific value in the event of a message id collision | ||
run.Results[0].Fixes[2].Description.Text.Should().Be(SharedKeyRuleMessageValue); | ||
|
||
// Prefer global value in the event of no rules metadata | ||
run.Results[1].Fixes[0].Description.Text.Should().Be(SharedKeyGlobalMessageValue); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Another perfect test. #Closed |
||
|
||
[Fact] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume this is a copy/paste error and you intended
nameof(SharedKeyGlobalMessageValue)
. Now I have to figure out why it doesn't make your tests fail. #ClosedThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. The test succeeds because it just requires the rule-scoped value to be different from the global-scoped value, so you can tell which you have. Should still fix so the next schlub doesn't have to figure it out.
In reply to: 249607878 [](ancestors = 249607878)