Skip to content

Instantly share code, notes, and snippets.

@matlus
matlus / ModelBuilder.cs
Created October 5, 2023 21:02
A Generic ModelBuilder
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Reflection;
namespace ModelBuilderInTestingExample;
public sealed class ModelBuilder<T> where T : class
{
private readonly Dictionary<string, object?> _propertiesAssignedUsingSet = new Dictionary<string, object?>(StringComparer.OrdinalIgnoreCase);
@matlus
matlus / Shiv_VS2022_FontAndColors.vssettings
Created February 22, 2022 23:48
Font and Colors Settings for VS 2022
<UserSettings><ApplicationIdentity version="17.0"/><ToolsOptions><ToolsOptionsCategory name="Environment" RegisteredName="Environment"/></ToolsOptions><Category name="Environment_Group" RegisteredName="Environment_Group"><Category name="Environment_FontsAndColors" Category="{1EDA5DD4-927A-43a7-810E-7FD247D0DA1D}" Package="{DA9FB551-C724-11d0-AE1F-00A0C90FFFC3}" RegisteredName="Environment_FontsAndColors" PackageName="Visual Studio Environment Package"><PropertyValue name="Version">2</PropertyValue><FontsAndColors Version="2.0"><Theme Id="{1DED0138-47CE-435E-84EF-9EC1F439B749}"/><Categories><Category GUID="{FA937F7B-C0D2-46B8-9F10-A7A92642B384}" FontIsDefault="Yes"><Items><Item Name="Artboard Background" Foreground="0x02000000" Background="0x02000000" BoldFont="No"/></Items></Category><Category GUID="{58E96763-1D3B-4E05-B6BA-FF7115FD0B7B}" FontName="Fira Code" FontSize="10" CharSet="1" FontIsDefault="No"><Items><Item Name="Plain Text" Foreground="0x00DCDCDC" Background="0x00191919" BoldFont="No"/></Items></Cat
/*
* 1. The local variable "schema" in the Main() method should be called xmlSchema
* 2. The method GetSchemaDocumentFromFile() should be called GetXmlSchemaFromFile()
* 3. There should be only one argument to method GetPpapiSchemaDocumentFromFile() and it should be called schemaFilePathAndName.
* There is no need for this method to have to know what applicationRootFolder means and how to constructor a full file path
* and name ofthe file it needs. The caller should be responsible for that.
* 4. The method AddDataElementToSchemaIfNotPresent() is modifying the document. To show your intent (make it obvious the document
* is going to be potentially modified) should do one of the following
* a. Either make the argument a "ref" argument
* b. Return the modified document from this method.
@matlus
matlus / SYWTBACR - Xml Schema Exercise
Last active October 12, 2020 17:08
SYWTBACR - Xml Schema Exercise
internal static class Program
{
static void Main(string[] args)
{
/*
* We have an XM Document and now we're attempting to validate the schema of
* this document against an Xml Schema document. The next line of code is
* simply attempting to retrieve the Xml Schema document.
* The applicationRootFolder argument is determined at runtime (dependant upon the runtime context; Console app or Web App etc.)
* The fileName argument comes from the config file. The concatenation of the 2 is the full path and file name
@matlus
matlus / gist:904d59046e92513ee9c80339be54f75b
Last active March 26, 2022 15:12
Movie Service Azure DevOps Build Pipeline YAML
# ASP.NET Core (.NET Framework)
# Build and test ASP.NET Core projects targeting the full .NET Framework.
# Add steps that publish symbols, save build artifacts, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core
trigger:
- master
pool:
vmImage: 'windows-latest'
internal static class Randomizer
{
private static int[] s_punctuationACIICodes = { 33, 35, 36, 37, 38, 40, 41, 42, 43, 44, 45, 46, 47, 58, 59, 60, 61, 62, 63, 64, 91, 92, 93, 94, 95, 123, 124, 125, 126 };
private static RNGCryptoServiceProvider rngCrypto = new RNGCryptoServiceProvider();
private static int GetRandomNumber()
{
var buffer = new byte[4];
rngCrypto.GetBytes(buffer);
@matlus
matlus / OneToManyMapImplementedTests
Last active May 8, 2019 13:00
OneToManyMap Implement Tests
[TestClass]
public class OneToManyMapDictionaryTests
{
private static IOneToManyMap<TKey, TValue> InitializeOneToManyMap<TKey, TValue>(TKey key, TValue[] values)
{
var oneToManyMap = new OneToManyMapDictionary<TKey, TValue>();
oneToManyMap.AddOneToManyMapping(key, values);
return oneToManyMap;
}
@matlus
matlus / OneToManyMapTestsSkeleton.cs
Last active May 8, 2019 13:02
OneToManyMap Test methods Skeleton
[TestClass]
public class OneToManyMapDictionaryTests
{
private static IOneToManyMap<TKey, TValue> InitializeOneToManyMap<TKey, TValue>(TKey key, TValue[] values)
{
var oneToManyMap = new OneToManyMapDictionary<TKey, TValue>();
oneToManyMap.AddOneToManyMapping(key, values);
return oneToManyMap;
}
<UserSettings><ApplicationIdentity version="16.0"/><ToolsOptions><ToolsOptionsCategory name="Environment" RegisteredName="Environment"><ToolsOptionsSubCategory name="General" RegisteredName="General" PackageName="Visual Studio Environment Package">
<PropertyValue name="AnimationSpeed">7</PropertyValue>
<PropertyValue name="AutoAdjustExperience">true</PropertyValue>
<PropertyValue name="AutohidePinActiveTabOnly">false</PropertyValue>
<PropertyValue name="CloseButtonActiveTabOnly">true</PropertyValue>
<PropertyValue name="MRUListContainsNItems">10</PropertyValue>
<PropertyValue name="ShowStatusBar">true</PropertyValue>
<PropertyValue name="WindowMenuContainsNItems">10</PropertyValue>
</ToolsOptionsSubCategory><ToolsOptionsSubCategory name="ProjectsAndSolution" RegisteredName="ProjectsAndSolution" PackageName="Visual Studio Environment Package"><PropertyValue name="ProjectsLocation">%vsspv_user_appdata%\Source\Repos</PropertyValue><PropertyValue name="PromptForRenameSymbol">true</P
@matlus
matlus / Startup.cs
Created March 10, 2019 16:21
ASP.NET Core (2.2) Web API by hand
/*
* Create a new Empty ASP.NET Core project
* Replace the entire Startup class (not the namespace) with the code below
*/
public class Startup
{
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)