Skip to content

Instantly share code, notes, and snippets.

// this is a way to test Generic Repo that uses EF. Notice, I'm not advocating for generic repos.
using FluentAssertions;
using Microsoft.EntityFrameworkCore;
public static class MyDebug
{
public static List<string> Sql {get; set; } = new();
public static void Capture(string query)
{
if (query.Contains("Execute"))
@ctrl-alt-d
ctrl-alt-d / Ef Mock
Created June 14, 2023 07:21
Mocking EF in the wrong way
namespace efsetp;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.ChangeTracking;
using Microsoft.EntityFrameworkCore.ChangeTracking.Internal;
using Microsoft.EntityFrameworkCore.Metadata;
using Moq;
public class Customer
{
public int CustomerId { get; set; }
@ctrl-alt-d
ctrl-alt-d / index.razor
Created March 2, 2021 14:40
Blazor server sending 500 upates per second
@page "/"
Tics per second: <input type="range" min="1" max="500" @bind="@CurrentValue" class="slider" id="myRange"> @CurrentValue
<br/><br/>
<div style="width:500px; height:10px; background-color: blue; position: relative;">
<div class="ball" style="@position_txt"></div>
</div>
<br/><br/>
<span>@DateTime.Now.ToString("HH:mm:ss")</span>
<span>Number of renders: @nRenders.ToString("N0")</span>
<br/><br/>
@ctrl-alt-d
ctrl-alt-d / MyGrid.razor
Created March 29, 2020 21:15
Cache for data grid component
[Parameter]
public IEnumerable<object> DataSource {set; get; }
private IEnumerable<object> Cache {set; get; } = null;
List<MyColumn> Columns = new List<MyColumn>();
public void AddColumn(MyColumn column)
{
var seg = DataSource;
Cache ??= DataSource.ToList();
DataSource = Cache;