Skip to content

Instantly share code, notes, and snippets.

Avatar

Kevin B Keboo

View GitHub Profile
@Keboo
Keboo / ConstructorTests.cs
Last active Sep 1, 2021
Automatic testing of constructor parameters
View ConstructorTests.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Moq;
using Xunit;
namespace Namespace
{
public interface IConstructorTest
@Keboo
Keboo / IHttpCall.cs
Last active Sep 22, 2020
In memory testing of HttpClient
View IHttpCall.cs
namespace Example.HttpClient.Tests
{
public interface IHttpCall
{
int InvocationsCount { get; }
}
}
@Keboo
Keboo / BrainTeaser.cs
Last active Sep 20, 2020
Null constructor brain teaser. Simply replace ??? with any type that will cause the unit test to pass. Code used xUnit.
View BrainTeaser.cs
[Fact]
public static void NullReturnFromConstructor()
{
//Any Nullable<T> will work
Assert.Throws<InvalidOperationException>(() => SudoMakeMeSandwich<???>());
}
private static T SudoMakeMeSandwich<T>() where T : new()
{
return new T() ?? throw new InvalidOperationException();
@Keboo
Keboo / README.md
Last active Jul 2, 2020
Brain Teaser: Collection fun
View README.md

Brain Teaser: Update the above code such that that unit tests pass. Do not update the content of the unit tests (however you are allowed to switch off of xUnit if you like).

@Keboo
Keboo / Program.cs
Created May 5, 2020
Some GC thoughts on making sure objects are cleaned up.
View Program.cs
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
namespace GC
{
/*
In dotnet core, finalizer does not appear to be called on shutdown
@Keboo
Keboo / Notes.md
Last active Apr 1, 2021
Presenting / Streaming notes
View Notes.md

Personal notes on presenting and streaming.

Before starting

  • Turn off un-needed software. Especially things with notifications: Slack, Skype, Teams, etc.
  • Turn on Focus Assist
  • When sharing your desktop, consider sharing a secondary screen rather than the primary screen. Many apps will post notifications to the primary screen so this will help cut down on accidently sharing out notifications.
  • Hide desktop icons
  • Consider resolution/DPI. Remember that for streaming, people watching may be on lower resolutions; don't stream above 1080p.
  • Hide task bar. Either set auto hide, or simply crop the shared section of your screen to omit it.
  • Consider if desktop background is appropriate.
@Keboo
Keboo / UnitTests
Created May 30, 2019
Create a delegate instance from its System.Type
View UnitTests
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Threading.Tasks;
namespace CreateDelegate
{
[TestClass]
View BindableBehavior.cs
public abstract class BindableBehavior<T> : Behavior<T> where T : BindableObject
{
protected override void OnAttachedTo(T bindable)
{
if (bindable != null)
{
this.InheritsBindingContextFrom(bindable);
}
base.OnAttachedTo(bindable);
}
@Keboo
Keboo / Person.cs
Last active Mar 12, 2019
AsyncLocal
View Person.cs
public class Person
{
public string Name { get; set; }
}
@Keboo
Keboo / Explanation.md
Last active Jan 31, 2019
Property brain teaser
View Explanation.md

If you look up the docs for how assignment works you will see the explanation that a = b = c is evaluated like a = (b = c). The key is this line from the docs: "The result of a simple assignment expression is the value assigned to the left operand." In this case the result of the (b = c) expression is the value in c which is "John". This then assigns "John" into a.