By typing a + TAB + TAB (or aaa + TAB for long) you end up with an empty failing test method body.
// Arrange
$end$
// Act
// Assert
throw new NotImplementedException();By typing fa + TAB + TAB (or fact + TAB for long) you end up with an empty failing test method.
The part be_a_test_case is selected and ready to be renamed.
Once you renamed your test method and pressed Enter, the cursor jump under // Arrange to keep it as productive as possible.
[Fact]
public void Should_be_a_test_case()
{
// Arrange
// Act
// Assert
throw new NotImplementedException();
}For an async test case, by typing af + TAB + TAB (or afact + TAB for long) you end up with an empty failing test method that return an async Task.
The same selection/cursor location behaviors applies.
[Fact]
public async Task Should_be_a_test_case()
{
// Arrange
// Act
// Assert
throw new NotImplementedException();
}I think that this is by far my favorite snippet.
If you define your field following the private readonly ISomeService _fieldName; and inject it in the controller like this public MyController(ISomeService fieldName){}, this snippet is for you!
public class MyClass
{
private readonly ISomeService _fieldName;
public MyClass(ISomeService fieldName){
// Place your cursor here
}
}From there, copy (ctrl+c) fieldName, place your cursor in the constructor body and type g + TAB + TAB (or guard + TAB for long) then paste (ctrl+v). You should endup with the following in less than a second:
public class MyClass
{
private readonly ISomeService _fieldName;
public MyClass(ISomeService fieldName){
_fieldName = fieldName ?? throw new ArgumentNullException(nameof(fieldName));
}
}The complete sequence (this should take ±2sec):
dbl-clickORctrl+clickfieldNamectrl+cclickinside the constructor body- Type
g - Hit
TABtwice ctrl+vENTER
Create a guard clause for an injected dependency.
if ($paramName$ == null) { throw new ArgumentNullException(nameof($paramName$)); }Create a guard clause for an injected dependency using the 2017 construct. This snippet offers two parameters: the property name and the parameter name.
$propName$ = $paramName$ ?? throw new ArgumentNullException(nameof($paramName$));Create a guard clause for an injected string dependency.
if (string.IsNullOrWhiteSpace($paramName$)) { throw new ArgumentNullException(nameof($paramName$)); }Create a failing XUnit test method named Should_be_tested. Shortcut: sbt.
[Fact]
public void Should_be_tested()
{
throw new NotImplementedException();
}Here are a few snippets that works great when implementing a Vertical Slice using the AutoMapper, FluentValidation, and MediatR stack.
All of those snippets should be used inside another class like:
public class MyUseCaseOrMyRazorPage
{
use the snippet here
}Creates all of the classes that are needed for a vertical slice command scenario (that does not return a value).
Generated classes:
- Command
- MapperProfile
- Validator
- Handler
Creates all of the classes that are needed for a vertical slice command scenario that returns a value.
Generated classes:
- Command
- Result
- MapperProfile
- Validator
- Handler
Creates all of the classes that are needed for a vertical slice query scenario.
Generated classes:
- Query
- Result
- MapperProfile
- Validator
- Handler
Creates all of the classes that are needed for a vertical slice query and command scenario inside a Razor Page (like an Edit page).
Generated classes:
- Query
- Command
- CommandResult
- MapperProfile
- QueryValidator
- CommandValidator
- QueryHandler
- CommandHandler
Creates all of the classes that are needed for a vertical slice query-only scenario inside a Razor Page (like an Index page).
Generated classes:
- Query
- Result
- MapperProfile
- Validator
- Handler
Allow to create a jQuery ready JavaScript module.
; (function ($, window, document, undefined) {
"use strict"
$(function () {
// DOM READY CODE HERE...
~end~
});
}(jQuery, window, document));