Skip to content

Instantly share code, notes, and snippets.

View bobbyg603's full-sized avatar
🚀
building dreams

Bobby Galli bobbyg603

🚀
building dreams
View GitHub Profile
//
// This sample project illustrates how to capture crashes (unhandled exceptions) in native Windows applications using BugSplat.
//
// The shared sample database 'Fred' is used in this example.
// You may view crashes for the Fred account by logging in at https://www.bugsplat.com:
// Account (Email Address): Fred@bugsplat.com
// Password: ***
//
// In order to assure that crashes sent to the BugSplat website yield exception stack traces with file/line # information,
// just rebuild this project. A Visual Studio post build event is configured to send the resulting .exe and .pdb files
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
import { HttpClient, HttpEvent, HttpEventType, HttpResponse, HttpUploadProgressEvent } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { NgxFileDropEntry } from '@bugsplat/ngx-file-drop';
import { bindCallback, catchError, filter, from, map, mergeMap, Observable, of, scan, switchMap, takeWhile } from 'rxjs';
import { AlertService } from 'src/app/alert/alert.service';
import { environment } from 'src/environments/environment';
import { v4 as uuid } from 'uuid';
import { FileUploadProgress } from './file-upload-progress';
import { UploadedFile } from './uploaded-file';
@bobbyg603
bobbyg603 / CreateMockedHttpMessageHandler.cs
Last active May 4, 2022 18:58
Mock HttpClient requests in .NET using Moq
private Mock<HttpMessageHandler> CreateMockHttpClientForAuthenticateSuccess(string xsrfToken = "abc123")
{
var response = new HttpResponseMessage();
response.Content = new StringContent("");
response.StatusCode = HttpStatusCode.OK;
response.Headers.Add("Set-Cookie", $"xsrf-token:{xsrfToken}; some-other-cookie:xyz321");
var handlerMock = new Mock<HttpMessageHandler>(MockBehavior.Strict);
handlerMock
.Protected()
.Setup<Task<HttpResponseMessage>>(
@bobbyg603
bobbyg603 / VerifyMockMessageHandler.cs
Last active May 4, 2022 19:01
Verify that a call to HttpClient happened correctly
var mockMessageHandler = CreateMockedHttpMessageHandler(response);
mockMessageHandler.Protected().Verify(
"SendAsync",
Times.Exactly(1),
ItExpr.Is<HttpRequestMessage>(req =>
req.Method == HttpMethod.Post && req.RequestUri == expectedUri
),
ItExpr.IsAny<CancellationToken>()
);
@bobbyg603
bobbyg603 / attachment.ts
Last active May 4, 2022 17:02
How to create a File from a Blob and attach it to a fetch request
function createAdditionalFile(): File {
const base64data =
'iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAADAFBMVEUAAACSbQD/AAD/tgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
@bobbyg603
bobbyg603 / MockedHttpClient.cs
Created May 4, 2022 18:22
Create an HttpClient that returns a statusCode, header, and StringContent when called with an expeted URI
private MockHttpMessageHandler CreateMockedHttpClient(string expectedUri, string xsrfToken, string responseContent = "")
{
var headers = new List<KeyValuePair<string, string>>() {
new KeyValuePair<string, string>(
"Set-Cookie",
"xsrf-token:abc123; some-other-cookie:xyz321"
)
};
var mockHttp = new MockHttpMessageHandler();
mockHttp
@bobbyg603
bobbyg603 / files.component.html
Last active May 9, 2022 00:34
File Uploads with Angular and Express
<section class="d-flex justify-content-between">
<h1>Files</h1>
</section>
<hr class="my-2">
<section>
<table class="table">
<tbody>
<tr *ngFor="let file of files">
<td>
<a [href]="file.url">{{file.name}}</a>
@bobbyg603
bobbyg603 / files.component.ts
Last active May 11, 2022 20:35
File Uploads with Angular and Express
import { Component, Input } from '@angular/core';
import { FilesTableEntry } from './files-table-entry';
@Component({
selector: 'app-files',
templateUrl: './files.component.html',
styleUrls: ['./files.component.scss']
})
export class FilesComponent {
@Input() files: FilesTableEntry[] | null = [
@bobbyg603
bobbyg603 / app.component.ts
Last active May 11, 2022 20:31
File Uploads with Angular and Express
import { HttpClient } from '@angular/common/http';
import { Component, OnInit } from '@angular/core';
import { Observable } from 'rxjs';
import { FilesTableEntry } from './files/files-table-entry';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})