Skip to content

Instantly share code, notes, and snippets.

@danielplawgo
danielplawgo / GetByIdTests1.cs
Created November 21, 2018 04:54
Fluent Assertions - przyjemne asserty w testach
public class GetByIdTests : BaseTest
{
protected Mock<IProductRepository> Repository { get; private set; }
protected ProductLogic Create()
{
Repository = new Mock<IProductRepository>();
return new ProductLogic(new Lazy<IProductRepository>(() => Repository.Object));
}
@danielplawgo
danielplawgo / BaseTests.cs
Created November 27, 2018 05:53
Effort - testy Entity Framework
public class BaseTests : RepositoryTests
{
protected ProductRepository Create(string path = null)
{
var context = CreateContext(path);
return new ProductRepository(new Lazy<DataContext>(() => context));
}
}
@danielplawgo
danielplawgo / BaseTest.cs
Created December 4, 2018 05:27
FluentAssertions.Mvc - assercie dla ASP.NET MVC
public class BaseTest
{
protected Mock<IProductLogic> Logic { get; set; }
protected Mock<IMapper> Mapper { get; set; }
protected virtual ProductsController Create()
{
Logic = new Mock<IProductLogic>();
@danielplawgo
danielplawgo / CsvFormatter1.cs
Created December 5, 2018 07:07
Jak zastąpić rozbudowanego switch w aplikacji
public class CsvFormatter : ICsvFormatter
{
public void Export(Report report)
{
Console.WriteLine($"CsvFormatter.Export: {report.Name}");
}
}
public interface ICsvFormatter
{
@danielplawgo
danielplawgo / Category.cs
Created December 17, 2018 04:24
CsvHelper - praca z plikami csv
public class Category
{
public int Id { get; set; }
public string Name { get; set; }
}
@danielplawgo
danielplawgo / Category.cs
Created December 28, 2018 05:57
Entity Framework, Automapper oraz projekcja
public class Category
{
public int Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public virtual ICollection<Product> Products { get; set; }
}
@danielplawgo
danielplawgo / Product.cs
Created January 18, 2019 14:46
Postman - testowanie API
public class Product
{
public int Id { get; set; }
public string Name { get; set; }
public string Category { get; set; }
public decimal Price { get; set; }
}
@danielplawgo
danielplawgo / HomeController.cs
Created January 25, 2019 11:50
Grupowanie wiadomości w nLogu w ramach żądania HTTP
public class HomeController : Controller
{
private static ILogger _logger = NLog.LogManager.GetCurrentClassLogger();
public ActionResult Index()
{
_logger.Info("Home.Index started.");
Random random = new Random();
var value = random.Next(1, 3);
@danielplawgo
danielplawgo / DownloadViewModel.cs
Created February 3, 2019 09:00
Topshelf - tworzenie usługi systemowej
public class DownloadViewModel
{
[Required]
public string Url { get; set; }
}
@danielplawgo
danielplawgo / DataContext1.cs
Created February 11, 2019 13:58
Audit z Entity Framework Plus
public class DataContext : DbContext
{
public DataContext()
: base("Name=DefaultConnection")
{
}
public DbSet<Category> Categories { get; set; }