Skip to content

Instantly share code, notes, and snippets.

View jpvelasco's full-sized avatar

Juan Pablo (JP) jpvelasco

View GitHub Profile
@jpvelasco
jpvelasco / YAMLBuildConfiguration.yml
Last active February 9, 2019 23:18
YAML based build configuration file for .NET 4.7.2 projects building in Azure Pipelines
# ASP.NET
# Build and test ASP.NET projects.
# Add steps that publish symbols, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/apps/aspnet/build-aspnet-4
trigger:
- master
pool:
vmImage: 'VS2017-Win2016'
@jpvelasco
jpvelasco / SQLDatabaseYAMLBuildConfiguration.yml
Last active May 8, 2022 08:19
SQL YAML Build Configuration for Azure Pipelines
# Adventure Works SQL Database Project Build Configuration
trigger:
- master
pool:
vmImage: 'VS2017-Win2016'
variables:
solution: '**/*.sln'
@jpvelasco
jpvelasco / UploadFileToBlobStorage.cs
Created July 13, 2017 06:27
Sample method that uploads a file from HTTP content into Azure blob storage
private void UploadFileContentsToBlobStorage(HttpContent httpContent)
{
byte[] fileContentBytes = httpContent.ReadAsByteArrayAsync().Result;
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobClient.GetContainerReference("mycontainer");
container.CreateIfNotExists(); container.SetPermissions(new BlobContainerPermissions
@jpvelasco
jpvelasco / UploadImage.cs
Last active July 13, 2017 06:18
Image upload web API endpoint controller
/// <summary> Uploads an image file </summary>
/// <returns>IHttpActionResult.</returns>
[Route("api/file")]
[HttpPost]
public IHttpActionResult UploadImage()
{
if (Request.Content.IsMimeMultipartContent() == false)
{
throw new UnsupportedMediaTypeException("unsupported media type", null);
}
@jpvelasco
jpvelasco / EFCoreSQLLiteInMemoryTest.cs
Last active March 24, 2017 07:11
Sample unit test using EF Core and SQL Lite In-Memory provider
[Fact]
public void GetClients_WhenCalledWithSqlLiteInMemoryDataContext_ReturnsExpectedResult()
{
var connection = new SqliteConnection("DataSource=:memory:");
connection.Open();
try
{
var sqlLiteDataContextOptions = new DbContextOptionsBuilder<EventDataContext>()
.UseSqlite(connection)
@jpvelasco
jpvelasco / EFCoreInMemoryTest.cs
Last active March 24, 2017 07:11
Sample test code using EF Core In-Memory provider.
[Fact]
public void GetClients_WhenCalledWithInMemoryDataContext_ReturnsExpectedResult()
{
var inMemoryDataContextOptions = new DbContextOptionsBuilder<EventDataContext>()
.UseInMemoryDatabase(databaseName: "Test_With_In_Memory_Database")
.Options;
// NOTE: Because we will need to assert against known data,
// we need to seed the in-memory test database
// with the same context options as the unit test
@jpvelasco
jpvelasco / ClientsController.cs
Last active March 24, 2017 07:12
Get Clients endpoint
// GET: api/Clients
[HttpGet("")
public IActionResult GetClients()
{
var result = _context.Clients.Select(client => new Client()
{
ClientId = client.ClientId,
FirstName = client.FirstName,
LastName = client.LastName,
Appointments = client.Appointments
@jpvelasco
jpvelasco / EventDbContextFactory.cs
Last active March 24, 2017 07:13
Sample implementation of IDBContextFactory for Entity Framework Core tooling
public class EventDbContextFactory : IDbContextFactory<EventDataContext>
{
public EventDataContext Create(DbContextFactoryOptions options)
{
var builder = new DbContextOptionsBuilder<EventDataContext>();
builder.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=SampleApiDatabase;Trusted_Connection=True;");
return new EventDataContext(builder.Options);
}
}