Skip to content

Instantly share code, notes, and snippets.

View emanuelefirmani's full-sized avatar

Emanuele Firmani emanuelefirmani

View GitHub Profile
namespace MyNamespace;
internal static class Rules
{
internal static IEnumerable<string> EmptyErrorList { get; } = Array.Empty<string>();
internal delegate IEnumerable<string> Validator<T>(T value);
internal static Validator<T> ParentOrChildren<T>(Validator<T> parent, IEnumerable<Validator<T>> children) =>
value =>
{
@emanuelefirmani
emanuelefirmani / code.cs
Created May 22, 2023 21:29
Simple linear skippable state maching
using Context = System.Collections.Generic.Dictionary<string, object>;
using ExecFunc = System.Func<System.Collections.Generic.Dictionary<string, object>, System.Collections.Generic.Dictionary<string, object>>;
namespace CeacEvaluationSelector.Web.Test;
internal enum WfSteps
{
Initial,
Step1,
Step2,
using Autofac;
using FluentAssertions;
using Xunit;
namespace GenericLogger
{
public interface ILogger<T>
{
delegate ILogger<T> Factory(MyParameter parameter);
}
using Autofac;
using FluentAssertions;
using Xunit;
namespace GenericLogger
{
public interface ILogger<T> { }
public class Logger<T> : ILogger<T>
{
public string Parameter { get; }
/// <summary>
/// This test verifies that UoW commits changes in a transaction.
/// Test is carried on by:
/// - running a transaction with exclusive lock on table LastUpdatingLog with the base.SqlConnection
/// - running the sut.Update (which opens another write transaction)
/// - execute SELECTs using another connection (with NoLock for checking uncommitted values)
/// The sut can commit its transaction only after first transaction is committed
/// </summary>
[Fact]
public void should_save_in_transaction()
using System;
using System.Reflection;
using Autofac;
using Autofac.Features.OwnedInstances;
using FluentAssertions;
using KPMG.ITS.ERP.ETL.Customer;
using KPMG.ITS.ERP.ETL.DB;
using KPMG.ITS.ERP.ETL.UpdatingLog;
using Xunit;
@emanuelefirmani
emanuelefirmani / RestSharp deserialization
Last active May 8, 2020 06:12
RestSharp JsonDeserializer is not correctly deserializing the response. Here is a comparison with Newtonsoft
using System.Linq;
using RestSharp;
using RestSharp.Serialization.Json;
using Xunit;
namespace JsonSerialization
{
public class UnitTest1
{
private const string json = @"{""panes"":{""filter"":{""records"":[{""data"":{""customernumber"":""10002""}}]}}}";
private IEnumerable<string> FormatNonFunctional(List<string> shoppingList)
{
var index = 0;
var result = new List<string>();
_outp.WriteLine(shoppingList.Count.ToString());
return shoppingList.Select(item => (index++).ToString() + item.Capitalize());
}