Skip to content

Instantly share code, notes, and snippets.

public class PdfGenerator
{
public async Task GeneratePdfAsync(string htmlContent)
{
// generate PDF from HTML content
}
}
public class MyClass
{
public class PdfGenerationCommandHandlerTests
{
[Fact]
public async Task Handle_ShouldGeneratePdf_WhenValidCommandProvided()
{
// Arrange
var command = new PdfGenerationCommand { HtmlContent = "<html><body><h1>Hello World!</h1></body></html>" };
var requestHandler = new Mock<IRequestHandler<PdfGenerationCommand, PdfGenerationResponse>>();
requestHandler.Setup(x => x.Handle(It.IsAny<PdfGenerationCommand>(), It.IsAny<CancellationToken>(), It.IsAny<IProgress<int>>()))
.ReturnsAsync(new PdfGenerationResponse { PdfContent = new byte[] { 1, 2, 3 }, DocumentId = "abc" });
public async Task GeneratePdfCommandHandler_Should_Generate_Pdf()
{
// Arrange
var htmlContent = "<html><body><h1>Test</h1></body></html>";
var pdfGenerator = new Mock<IPdfGenerator>();
pdfGenerator.Setup(x => x.GeneratePdfAsync(htmlContent))
.ReturnsAsync(new byte[] { 0x25, 0x50, 0x44, 0x46 });
var commandHandler = new GeneratePdfCommandHandler(pdfGenerator.Object);
public class PdfGenerationRequestHandler : IRequestHandler<PdfGenerationCommand, PdfGenerationResponse>
{
private readonly IPdfGenerator _pdfGenerator;
public PdfGenerationRequestHandler(IPdfGenerator pdfGenerator)
{
_pdfGenerator = pdfGenerator;
}
public async Task<PdfGenerationResponse> Handle(PdfGenerationCommand command, CancellationToken cancellationToken, IProgress<int> progress)
public class PdfGenerationCommand : ICommand
{
public string HtmlContent { get; set; }
}
public class PdfGenerationCommandHandler : CommandHandler<PdfGenerationCommand>
{
private readonly IPdfGenerator _pdfGenerator;
private CancellationTokenSource _cancellationTokenSource;
@TheFo2sh
TheFo2sh / OrderProcessing.ts
Last active November 21, 2020 18:11
OrderProcessing.ts
import * as R from 'Ramda';
namespace Main {
export interface Order {
Amount: number
Name: string
}
export interface Discount {
Apply: (amount: number) => number;
IsValid: (order: Order) => boolean;
}
using System;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
using Couchbase.Lite;
namespace ChannelQueue
{
class DocumentWriter : IDisposable
{
public class AvatarImageSource : StreamImageSource
{
public override bool IsEmpty => string.IsNullOrEmpty(Name);
protected override void OnPropertyChanged(string propertyName)
{
if (propertyName == NameProperty.PropertyName ||
propertyName == BackgroundProperty.PropertyName ||
namespace TimeTable.App.Views
{
public class TimeSlotDTO
{
public int Day { get; set; }
public double Start { get; set; }
public double End { get; set; }
public string Place { get; set; }
public string Course { get; set; }
public int Students { get; set; }
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using TimeTable.Core.Models;
using TimeTableServer.Context;
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860