Skip to content

Instantly share code, notes, and snippets.

@genlu
Last active April 27, 2021 14:52
Show Gist options
  • Select an option

  • Save genlu/dda3ff4b5ce04dae5e47eceec7256b72 to your computer and use it in GitHub Desktop.

Select an option

Save genlu/dda3ff4b5ce04dae5e47eceec7256b72 to your computer and use it in GitHub Desktop.
BlazorApp Demo Script
  1. With a small codebase, I've setup the demo to closely resemble the way many people approach their daily coding tasks, instead of grouping related features together and going through a checklist.

  2. Open MemoryGame solution (C#) in VS

    • quick intro on terms like solution/projects/references, and quickly go through the projcts
    • Show syntax/semantic coloring, hover tips, completions, etc. those are some of the basic features everyone expect from a modern IDE.
    • navigate through the code via go-to-def, find-all and find ref
  3. Start the game

    • Curerntly the implementation is very limited, only one kind of card and something seems wrong, we first need to figure out what's the problem.
  4. Close app and open unit test project

    • brief intro to testing
    • Show two existing test in test explorer
    • Test discovery also utilize Roslyn APIs
  5. Add a test to make sure we have matching pairs

    • uncomment HaveMatchingPairs but not [Fact] attribute
    • why the test doesn't show? Notice the warning
    • Run and it fails. Shouldn't use refrence equality for comparison
  6. Start LUT

    • Make sure to include only test project (workaround a LUT bug handling blazor project)
    • how it works
  7. Make CatCard implement IEquatable

    1. Implement interface
    2. Override Equals
    3. Overrride GetHashCode
    4. Now passing!
  8. Run again to check

    • Works great!
  9. Now add a few tests to cover more paths.

    1. Coverage looks better now
    2. Un-oh, one test failed, since we only have one kind of card. Now it's time to expand our game
  10. We need more cards

    1. We can simply copy/paste and create a DogCard, but what if we want to add more. Need to avoid duplicated code
    2. manually change CatCard to a abstract CardBase, fix all references, and then create CatCard and DogCard to implement it. Too many steps...
    3. Extarct base class!
      • Select all members for base and flag Anaimal as abstract
      • Fix interface
      • Now add Dog and Monkey. Test all passed now.
  11. Before sending out a pull request for review, I need to tidy things up

    • Refactorings:
      • extract method, wrap call chain, etc (see comments in model.cs)
    • Open error list and editconfig
      • CA2200
      • Fix naming issues
      • Change editorconfig to use K&R style
      • prefer var as error
      • Use switch expression (CardHelps.cs)
  12. Some potential customer suggested increasing variaty and number of card

    • Sure, just repeast last step and add a new type. (make sure not to add emoji to AllAnaimals helper!)
    • now the name Animal doesn't make sense anymore. We need to change it to Emoji.
    • Manual rename? Find/Replace? Let's use inline rename.
    • Don't forget the parameter name
  13. One last check, run the app again.

    • Hmm, where's the taco card...?
    • We forgot to update the emoji list
  14. Source generator

    • how does CG works?
    • exclude all existintg card related files, and add reference to CG project.
    • no errors. GoToDef and show emoji.txt
    • Run app
    • Add new emoji in txt file
    • run again

End of App demo

Optional: Show Roslyn

  • Open in VS:
    • ~200 projects
    • Count lines in roslyn: 5 million lines of source code
    • Find reference CompletionItem: 400+ references
    • show analyzers we use
    • show source generator we use for syntax
    • show number of tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment