Skip to content

Instantly share code, notes, and snippets.

@nadais
nadais / RemoveFinalElse.cs
Last active October 27, 2022 10:01
Removed final else
namespace Example;
public class ApiKeyMiddleware
{
private readonly RequestDelegate _next;
private const string APIKEY = "XApiKey";
public ApiKeyMiddleware(RequestDelegate next)
{
@nadais
nadais / ExampleIfEarlyExit.cs
Last active October 27, 2022 09:02
Early exit if
namespace Example;
public class ApiKeyMiddleware
{
private readonly RequestDelegate _next;
private const string APIKEY = "XApiKey";
public ApiKeyMiddleware(RequestDelegate next)
{
@nadais
nadais / ExampleIf.cs
Last active October 27, 2022 08:56
Example to refactor on not use else keyword
namespace Example;
public class ApiKeyMiddleware
{
private readonly RequestDelegate _next;
private const string APIKEY = "XApiKey";
public ApiKeyMiddleware(RequestDelegate next)
{
@nadais
nadais / DateTimeTestExampleHardcoded.cs
Created October 14, 2022 09:39
Date Time Hardcoded example tests
using Xunit;
namespace DateTimeProvider.Test;
public class DateTimeExample
{
[Fact]
public void ShouldReturnGoodMorning_WhenCurrentTimeIsMorning()
{
var dateTimeExample = new DateTimeHardcodedExample();
@nadais
nadais / IDateTimeProvider.cs
Created October 13, 2022 11:41
IDateTimeProvider
namespace DateTimeProvider;
public interface IDateTimeProvider
{
public DateTime Now { get; }
}
@nadais
nadais / DateTimeWithProviderTests.cs
Last active October 13, 2022 12:11
Tests Date Time with Provider
using System;
using NSubstitute;
using Xunit;
namespace DateTimeProvider.Test;
public class DateTimeDependencyInjectionExampleTest
{
private readonly IDateTimeProvider _dateTimeProvider = Substitute.For<IDateTimeProvider>();
@nadais
nadais / DateTimeExampleWithProvider.cs
Last active October 13, 2022 12:09
Get current time with provider
namespace DateTimeProvider;
public class DateTimeDependencyInjectionExample
{
private readonly IDateTimeProvider _dateTimeProvider;
public DateTimeDependencyInjectionExample(IDateTimeProvider dateTimeProvider)
{
_dateTimeProvider = dateTimeProvider;
}
@nadais
nadais / DateTimeExample.cs
Last active October 14, 2022 09:38
Date Time Example hardcoded Date
public string GetCurrentTimeMessage()
{
var currentTime = DateTime.Now;
return currentTime.Hour switch
{
>= 8 and < 12 => "Good morning!",
< 18 => "Good afternoon!",
_ => "Good evening!"
};
}
@nadais
nadais / CNAME
Created May 7, 2022 17:31
Example CNAME for custom domain medium article
example-custom-domain.tk