• About
  • Privacy Policy
  • Utilities
Darchuk.NET

Web API

ASP.NET Core Unit Testing – Setting the request body

June 28, 2019 by Robert Leave a Comment

Every now and again I find it necessary to set up the request body manually (as opposed to using the [FromBody] tag).  In the controller you can read from the request body easily enough: via GIPHY Testing How do you test this?  Normally I would just create a controller, call the method, and check the … [Read more…]

Posted in: .NET Core, ASP.NET, C#, MVC, Unit Testing, Web API, Web Development Tagged: ASP.NET, ASP.NET Core, Csharp, unit testing, Web Development

Callback MemoryStream

June 7, 2019 by Robert Leave a Comment

In the last post I talked about streaming data back via a WebAPI.  On the front end, I had a “download” button that I wanted to disable until the download is complete, so that users don’t inadvertently spam the server with download requests.  When the button is clicked, an iframe is opened to the WebAPI … [Read more…]

Posted in: ASP.NET, C#, SignalR, Web API Tagged: C#, Callback, SignalR, Streams

ASP.NET Core Web API–Returning a FileStream

May 31, 2019 by Robert 3 Comments

So I built a service that collects information, say, log information, and sends it down to a client.  This information is normally streamed right to a web browser via SignalR, but sometimes there is a lot of it, and scrolling through it on the web view can be quite a pain.  It would be nice … [Read more…]

Posted in: .NET Core, ASP.NET, C#, Web API, Web Development Tagged: ASP.NET, C#, File Download, Stream, WebAPI

ASP.NET Core – Unit Testing a file upload

March 29, 2019 by Robert 1 Comment

Last week I wrote about how to upload a file from a website using Angular and .NET Core.  Writing tests for this is mostly straightforward, but there’s a few gotchas that I thought I would write down for the next time I need to do this.  The front end tests are pretty trivial – you … [Read more…]

Posted in: .NET Core, C#, Unit Testing, Web API, Web Development Tagged: .NET Core, ASP.NET, ASP.NET Core, File Upload, IFormCollection, IFormFile, Testing, unit testing

Uploading a file from a website

March 22, 2019 by Robert 1 Comment

Uploading a file from a website is pretty simple, but I always have to look it up.  There’s all sorts of different technologies and frameworks that work with the web, so I just thought I would write down how I got it to work so that next time I can just come back here and … [Read more…]

Posted in: .NET Core, Angular, ASP.NET, C#, JavaScript, Typescript, Web API, Web Development Tagged: .NET Core, Angular, ASP.NET, File, MemoryStream, Typescript, Upload, Web API

CORS in ASP .NET Core 2.2

December 21, 2018 by Robert Leave a Comment

Recently my team upgraded to .NET Core 2.2.  We have an API that needs to be accessed from an Angular project living in a different domain, so we had CORS enabled this way: Disclaimer: this is an intranet application – so it is only accessible inside of a corporate firewall, making it more acceptable to … [Read more…]

Posted in: .NET Core, ASP.NET, C#, Security, Web API, Web Development Tagged: .NET Core, ASP.NET, C#, CORS, NETCORE, Security, WebAPI

Angular HttpClient error handling

November 30, 2018 by Robert Leave a Comment

HttpClient is the preferred way to make http calls from an Angular app.  It is simple and straightforward to use, returning an Observable<T>.  All you have to do is subscribe and the callback will be invoked when the data comes back from the server. via GIPHY But what about error handling? In a perfect world, … [Read more…]

Posted in: Angular, Web API, Web Development Tagged: Angular, Error, ErrorHandling, HttpClient, HttpErrorResponse

Angular HttpClient unit testing

November 23, 2018 by Robert 2 Comments

There’s several tutorials for how to use and test HttpClient, but I wanted to distill it down to a simple snippet that I can refer back to when I inevitably forget how to do it. via GIPHY HttpTestingController This handy thing is provided by importing the HttpClientTestingModule in to your TestBed.  It lets you manipulate … [Read more…]

Posted in: Angular, Asynchronous, Jasmine, Typescript, Unit Testing, Web API, Web Development Tagged: Angular, HttpClient, Mock, Testing, unit testing

C# Mapping an Enum to a key value pair

May 18, 2018 by Robert 2 Comments

Enums are useful because they help you avoid magic numbers.  You can write your code in a way that is easy to read and understand from the human’s perspective, which, at the end of the day, is pretty important. Exposing enums on your Web API I want to share my enums with other things, notably … [Read more…]

Posted in: .NET Core, ASP.NET, C#, Typescript, Web API, Web Development Tagged: .NET, Angular, ASP.NET, C#, enum, Typescript, Web API

ASP.NET MVC — Unit Testing IActionResult

April 13, 2018 by Robert Leave a Comment

In the last post I talked about using and extending IActionResult to return your preferred HttpStatus code in your ASP.NET MVC controllers.  But how do you write unit tests that make sure that you’re returning what you expect?  Your controllers will return one of these: IActionResult There’s nothing on this interface that you can easily … [Read more…]

Posted in: .NET Core, ASP.NET, C#, MVC, Unit Testing, Web API, Web Development Tagged: .NET Core, ASP.NET, C#, Controller, IActionResult, MVC, unit testing, XUnit
1 2 Next »

Recent Posts

  • Allowing trailing JSON commas in ASP.NET Core 3
  • YADNC3JSG–Yet Another .NET Core 3.0 JSON Serializer Gotcha
  • Logging in a .NET Core 3 SignalR client
  • .NET Core 3 unit testing project sdk
  • .NET Core 3.0 Upgrade–New JSON Serializer Gotchas

Recent Comments

  1. Robert on C# Setting Socket Keep-Alive
  2. Oliver Schramm on C# Setting Socket Keep-Alive
  3. John Anderson on Waiting for a keypress asynchronously in a C# console app
  4. Ronald Garlit on .NET Core 3 unit testing project sdk
  5. Ronald Garlit on .NET Core 3 unit testing project sdk

Copyright © 2025 Darchuk.NET.

Omega WordPress Theme by ThemeHall