Skip to content

Instantly share code, notes, and snippets.

View Powerz's full-sized avatar

Aleksei Zagoskin Powerz

View GitHub Profile
public class MyClassTests
{
public class Method1 : MyClassTestsBase
{
[Theory]
[AutoData]
public async Task Should_return_A_when_X(parameters)
{
//! Arrange
// ...
@Powerz
Powerz / EnumGenerator.cs
Created January 31, 2023 20:47
Random enum generator for AutoFixture.
using AutoFixture.Kernel;
/// <summary>
/// AutoFixture random generator for enums
/// </summary>
public class RandomEnumGenerator : ISpecimenBuilder
{
private static readonly Random _randomizer = Random.Shared;
@Powerz
Powerz / ObjectMerger.cs
Created January 12, 2023 22:03
Merges two anonymous objects.
using System.Dynamic;
public class ObjectMerger : IObjectMerger
{
/// <summary>
/// Merges two anonymous objects.
/// https://stackoverflow.com/questions/6754967/merging-anonymous-types
/// </summary>
public dynamic? Merge(object? item1, object? item2)
{
@Powerz
Powerz / CryptoService.cs
Created January 12, 2023 22:00
Encrypt and decrypt a string with a pass phrase.
using System.Security.Cryptography;
using System.Text;
/// <summary>
/// Encrypt and decrypt a string with a pass phrase.
/// // https://stackoverflow.com/questions/10168240/encrypting-decrypting-a-string-in-c-sharp
/// </summary>
public class CryptoService : ICryptoService
{
@Powerz
Powerz / AutoMapperTestsBase.cs
Created January 12, 2023 21:33
Base classes for testing AutoMapper profiles using Autofixture.
using AutoFixture;
using AutoMapper;
/// <summary>
/// Base class for AutoMapper tests (one profile).
/// </summary>
/// <typeparam name="TProfile">Mappings profile</typeparam>
public abstract class AutoMapperTestsBase<TProfile> where TProfile : Profile, new()
{
protected readonly Fixture Fixture;
@Powerz
Powerz / ResharperTemplates.DotSettings
Last active March 24, 2021 06:40
Resharper / Rider file templates for FluentMigrator and live templates for xUnit
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/PatternsAndTemplates/LiveTemplates/QuickList/=F0CA621CDF5AB24282D8CDC11C520997/Entry/=202E5F32AF467445AA17792D97AF1C26/@KeyIndexDefined">True</s:Boolean>
<s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/QuickList/=F0CA621CDF5AB24282D8CDC11C520997/Entry/=202E5F32AF467445AA17792D97AF1C26/EntryName/@EntryValue">ForwardOnlyMigration</s:String>
<s:Int64 x:Key="/Default/PatternsAndTemplates/LiveTemplates/QuickList/=F0CA621CDF5AB24282D8CDC11C520997/Entry/=202E5F32AF467445AA17792D97AF1C26/Position/@EntryValue">6</s:Int64>
<s:Int64 x:Key="/Default/PatternsAndTemplates/LiveTemplates/QuickList/=F0CA621CDF5AB24282D8CDC11C520997/Entry/=2CBD6971A7955044AD2624B84FB49E38/Position/@EntryValue">11</s:Int64>
<s:
@Powerz
Powerz / update-notification.sh
Created May 14, 2019 17:10
Push notifications for ASUS router with Merlin firmware
#!/bin/sh
### Do not change below
# Retrieve version
TMPVERS=$(nvram get webs_state_info)
echo "$TMPVERS" | grep 382
if [ $? -ne 0 ]; then
VERS=${TMPVERS:5:3}.${TMPVERS:8:10}
else
VERS=$TMPVERS
@Powerz
Powerz / .editorconfig
Created October 20, 2018 14:21
C# EditorConfig file (.editorconfig)
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference?view=vs-2017#formatting-conventions
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-naming-conventions?view=vs-2017
# https://github.com/dotnet/roslyn/blob/master/.editorconfig
# https://medium.com/@jonjam/c-code-style-using-editorconfig-9d38de65527d
# https://github.com/kentcb/EditorConfigReference/blob/master/.editorconfig
# https://github.com/RehanSaeed/EditorConfig/blob/master/.editorconfig
# https://www.jetbrains.com/help/rider/Using_EditorConfig.html
@Powerz
Powerz / EnumExtensions.cs
Last active January 12, 2023 21:49
Get enum description by enum member
using System.Collections.Concurrent;
using System.ComponentModel;
using System.Reflection;
public static class EnumExtensions
{
private static readonly ConcurrentDictionary<string, string> _descriptionsByEnumMemberName = new();
public static string GetDescription<T>(this T value) where T : Enum
{
@Powerz
Powerz / LoggingAdapter.cs
Created August 16, 2018 13:03
ILogger<T> for old ASP.NET (not Core)
// Bind ILoggerFactory to LoggerFactory
// Bind typeof(ILogger<>) to typeof(LoggingAdapter<>)
public class LoggingAdapter<T> : ILogger<T>
{
private readonly Microsoft.Extensions.Logging.ILogger _logger;
public LoggingAdapter(ILoggerFactory factory)
{
_logger = factory.CreateLogger<T>();