vrijdag 7 oktober 2016

C# > September > DUH! Moments


  • When working with I/O, Streams, Writers, etc. ALWAYS use 'using{}'
  • In regex the '?' makes the preceding item optional:
    • Or: '?' in regex means '0 or 1'
    • An? (matches both A and An)
    • 23(rd)? (matches both 23 and 23rd)
  • In SpecFlow: when using regex step definition bindings you can create step definition methods with multiple parameters easily by having multiple (.*)s in the regex.
  • C#/.NET syntax for pattern matching:
    • string pattern = "[regex pattern]"
    • string input = "[input]"
    • Match match = Regex.Match(input, pattern);
    • AssertTrue(match.Success) etc.
  • Useful methods of DateTime objects:
    • myDateTime.AddDays(int days)
    • myDateTime.AddMonths(int months)
    • etc.
  • In Visual Studio: when debugging the immediate window is an amazing section where you can type statements which will be immediately executed and the value shown.
  • A class containing [Fact]-s for xunit.net should be public
  • ?? operator
    • if/else operator with nullable argument
  • LINQ:
    • var query = from element in collection select element.attribute
    • var query = collection.Select(element => element.attribute)
  • In regex:
    • '+' means '1 or more'
    • '$' means 'end of string or end of line'
    • '\d' means 'digit'
  • Working with the JIRA REST API and the JIRA Zephyr API (ZAPI) I've been making my very first steps in web-based APIs. So there are a LOT of "DUH!" moments. The most newbie one so far:
    • We have GET requests, and POST requests.
      • GET requests:
        • Have no body
        • Arguments to the request are passed via the URL.
          • Example: /api/latest/resource?argumentName=argumentValue
      • POST requests:
        • (Can) have a body
        • Arguments to the requests are typically passed via a body (such as JSON)
    • If you don't follow these rules you get fancy error messages such as:
      • "Cannot send a content-body with this verb-type".
    • The different calls and what they mean:
      • GET: read
      • POST: create
      • PUT: update
      • DELETE: delete
      • (apparently there is PATCH as well - no idea what it is)

Geen opmerkingen:

Een reactie posten