MSpec, what should I put in my [Subject()] attributes? - tdd

I've been using MSpec for a little while and I really like it. I've found that to get ReSharper to recognize my specifications, I need to use a SubjectAttribute.
I'm wondering though, what's the best thing to put in the [Subject()] attributes?
If I'm doing BDD, then I don't know the type under test so [Subject(typeof(thingy))] seems premature. Could be added later I suppose once the code is written.
So that leaves the text version, [Subject("some text")]. But what's the best thing to put there?
Whatever I do, it doesn't seem to affect the output I get in ReSharper. I suppose to some extent this is down to personal preference, but I wondered if there was any convention here?

You don't need to apply SubjectAttribute to have ReSharper recognize contexts and specifications, a class containing an It field will suffice. However, if you want ReSharper to support custom naming conventions for MSpec types and fields (Because et al) you need to apply the SubjectAttribute:
Define custom naming conventions in ReSharper | Options |
Languages/Common section | Naming Style | Advanced Settings
When you add a User defined naming rule scroll down the list to see MSpec entities.
Enable MSpec annotations in ReSharper | Options | Code Inspection/Code Annotations section
Annotations + SubjectAttribute (even without custom naming rules) prevent ReSharper from marking MSpec's fields as unused. Alternatively, disable warning 169 in the project settings.
Subject serves as metadata describing you context, for example you can use the System Under Test (when writing a unit test), a string of your choice, or both. These information will be reported in the HTML and in the ReSharper output. It doesn't work as of now, I suspect this is a bug in the ReSharper runner for 6.0.
As with strings, you can basically put anything you want there. I would recommend using the subject to group your specs by feature.
Subject: Login
Contexts: When logging in with valid credentials, When logging in with invalid credentials, etc.
There's an example in my GitHub repository.

Related

How to filter Intellisense, Auto Completion, in Visual Studio C#, to show only members that the Project defined?

How to filter Intellisense, Auto Completion, in Visual Studio C#, to show only members that the Project defined, or that are contained in the assembly from which I am currently editing code. Or that are defined in the actual class/interface that I am completing code one, and not the parent class?
Very often when I want to invoke/call/use a member that I defined. I am currently in a habbit of navigating to the class which I want to invoke a function on, copy/remember the name, then complete the code.
The thing is that I would find it very useful (in reducing redundant hand movement), while coding, to be able to view only the functionality that is written by me. Because in the environment that I am writing each object has at least 200 built in members that appear in most intellisense suggestions. And these built in suggestions are not part of my Assembly or Project. they are from the Engine. Similarly C# itself defines all these ToString() like members for each System.Object of which everything is derived from. To find the User-Defined members amongst all these System and Engine defined members is a hassle.
I searched google and forum for answers, to no avail. Also I don't have the money for solutions, so I would appreciate if it would be a free solution.
I afraid the answer is negative.
For now, IntelliSense cannot suppress the display of built-in properties, methods, and so on from the root cause to only show the custom parameter methods, and so on.
However, since VS2017, IntelliSense has only added filters, which can only be filtered by fields, methods, classes, keywords and so on.But you cannot filter by customization or built-in.
Suggestion
I suggest you put the class name, method naming specification(add some fields to prompt the method's role such as function select_AllManagers). After that, you can type a few more keywords to narrow IntelliSense down.
In addition, if you still want to get this point, you could report it to DC forum to raise the Support Team's attention. Hope this could help you.

Advanced code style in Clion

I want to have google-style like code style checker that would automatically run within Clion.
However, what I found as solutions (predeclared code style for google and others, direct Editor settings and EditorConfig support in Clion help) are all rather primitive. For example, I want to use snake case with final underscore for class member fileds (e.g. my_class_member_) and usual snake case for function arguments (e.g. some_argument), and none of the suggested options would do the trick as far as I am concerned. Furthermore, some politics associated with endless loops and so are to be added, which is even more context-specific.
I consider creating cpplint.py-like script for this, but it is going to be very time-consuming and is likely to be run outside Clion. Are there any elegant ways to solve my problem?
Yeah, you able to do this! Look into Clion plug-in Clion-cpplint and use with cpplint.py script, provided by Google. You will get highlights on the fly when you are editing C++ source code.
You able to install add-on through Plugins tab in settings. In the end you will get something like:

Dotfuscator Seems Not Adhering To Renaming Exclusion RegEx

We have decided to use the Dotfuscator to obfuscate our code. Ours is a Windows Phone application and we are using Dotfuscator Windows Phone Edition Version 4.9.7000.29303. We learnt that System.Reflection.ObfuscationAttribute class is not available in Silverlight, so it is not possible to use exclusion attributes on some types we need to exclude. We are now planning to use Rename>Exclude tab in dotfuscator and exclude types with some specific suffixes. Before implementation we created a trial project and tested obfuscation on it. We found in our testing that the output is not adhering to execution rules. Though the preview window is showing expected result but output still includes those types which should have been excluded. Please see the screen shot of the Dotfuscator window below. Preview window on the left hand side of the arrow is correctly displaying the shaded type which would be excluded from obfuscation, but on the right hand side of the arrow, output of the same still obfuscated those types. What is happening?
I don't entirely understand what you're trying to accomplish with the regular expression, but as far as using attributes to control obfuscation, there is a library you can include.
The library to include is typically in
C:\Program Files(x86)\PreEmptive Solutions\Dotfuscator (version and edition)\Attributes\Windows Phone\PreEmptive.ObfuscationAttributes.dll
Here is an example on how to exclude something from renaming for instance:
[Obfuscation(Feature = "renaming", Exclude = true)]
public int Foo{get;set;}
You can find more details about it controlling obfuscation with attributes at this link and the general users guide is available here
If you want to go the regex route instead, you can also look at the documentation for creating custom rules. You'll have to provide a bit more info for me to understand what you're trying to do for me to be able to help though. Given your screenshot, everything appears to be what I'd expect.

FxCop Custom Rules for Custom Controls

In my project I am using custom controls instead of normal ASP.NET controls. We have build an architecture on .NET and are using its controls.
Now I need to write a custom rule to check for if some of windows controls are being used. Reason being, my team needs to be limited to only my custom controls that were designed to replace the windows controls.
Example: I need to search and if they are using System.Windows.Controls.Textbox.....I need it to be an error.
Can anyone please help me out with code?
I hope the problem is clear ..... in case of any further clarifications needed please let me know.
The logic for this sort of rule is fairly simple:
Check method bodies, visiting each constructor invocation to see if
the target class inherits from the base Control class.
If it does, verify that the target class is in your namespace or assembly (or however you can best identify it as "yours").
This is relatively simple. A much bigger problem is that the relevant contructors will usually be invoked in designer-generated code, which most folks tend to prefer ignoring when executing FxCop. To get your rule to work, you will need to include designer-generated code in your analyses.
The tool NDepend let's write custom code rules on .NET code much more easily than with FxCop. Disclaimer: I am one of the developer of the tool
With this tool you can write custom code rules over LINQ queries (what is named CQLinq). For example, the query you are asking for can be written this way with CQLinq:
// <Name>Don't use system controls</Name>
warnif count > 0
let systemControls = ThirdParty.Types.Where(
t => t.DeriveFrom("System.Windows.Forms.Control".AllowNoMatch()))
where systemControls.Count() > 0
from t in systemControls
let methodsThatCreateT = t.TypesUsingMe.ChildMethods().Where(m => m.CreateA(t))
select new { t, methodsThatCreateT }
While editing such code rule, instantly a browsable result is shown (in 3 milliseconds here). Double clicking any type or method in this result, jumps to its declaration in source code in Visual Studio:
200 default code rules are proposed. The tool is 100% integrated in Visual Studio 2012, 2010, and 2008. Default or custom code rules can be validated inside Visual Studio, and/or at Build Process time, in a generated HTML+javascript report.

How does intellisense work in Visual Studio?

I hope this is a valid question: how does intellisense work in VS2008? I'm after what is known about the algorithm it uses to find the suggestions, when exactly it pops up (the "." is just one obvious trigger), how its behavior can be modified if at all possible, etc.
To put this question into context: The main issue I'm trying to resolve is how to activate and deactivate intellisense in portions of the editor screen and how to modify where it searches to populate the suggestion box.
All information is welcome.
Take a look at this DIY Intellisense article on CodeProject.
It's more fun to reverse-engineer it, though. Let's consider the problem:
you need to identify the words of interest
you need to find the options possible
you need to present them
Now, the first step means you have to parse the code. You've got the C/C** keywords, you pre-parse the various function and class declarations, and load them into some kind of data structure. Then you parse the code and store the class, variable, etc names and put them in the same data structure.
The second step means you want a data structure which efficiently can search for a partial word and get all the words that have that prefix. You can do that with regular expressions, but that's not very efficient. An efficient data structure for that kind of search is a trie, which is discussed here on SO .
Once you have the list of possibilities, you just present it. You probably want to keep a reference to the root of the tree of possibilities so you can search them out in real time as someone types more letters.
Eclipse also has this feature and it is an open source project. Why not check out how Eclipse does it by actually looking at the code?
This question is too broad. Since there are a number of different languages the VS IDE supports out of the box AND there are N number of DSL and IDE enhancements that support alternative intellisense this implies a number of answers. If you are speaking about C# specifically then See the Tools | Options | Text Editor | C# | Intellisense area to see the available options of completion options. As far as the algorithm[s] used, you would be looking for the metadata of assemblies, copious caching of type members, MRU list for last member chosen for specific type, etc. If you have a more specific question, I'd suggest you clarify.
See the example of a DSL (ironpython) and its implementation here.
I haven't seen any text editor in VS that limits where IntelliSense shows up. It's all language specific. If your cursor is located at a point where IntelliSense might contribute to a valid token, that's when it will be used.
I believe there is some interaction with the project system being used, but that's as far as I know. I also believe there is a sample project system in the Visual Studio SDK, and that might give you an idea.
For such cases I sometimes use my own version of InteliSense that I developed for AutoHotKey when I want specific behavior. The point of this script is that it can be used with any editor, or basically any control accepting text. It works by recording text input and interpreting it upon syntax file.
You can perhaps use it as a base for the thing you want to achieve. I used ISense succesifully with several languages that don't have such thing, like Csound or even batch scripts. It will be possible to extend it to support C# using input monitoring in combination with Reflection.
Anyway, with AHK you can even control VS intelissense by "taking" the list of items it presents and filter it, or similar things. You may have some small problems with process boundaries but nothing that cant be fixed.
The intellisense ius generally, AFAIK, implemented using different methods. I read that Delphi is so fast that it implements isense by recompiling the project on each token and thats the reason C++ Builder didn't have isense as its compiling very slow.
As to your how to change where it looks question, short answer is, you can't. Intellisense for the most part is provided by reflection of assemblies included in your project ( and some other tricks with C++ ). What you are getting is a result of VS processing through all the assemblies you have included and all assemblies from the GAC.
That said, if you want to provide explicit intellisense results from a project you are working on, look into IVsContextualIntellisenseFilterProvider
Finally, for some insight into the behind the scenes process, check this blog post

Resources