• About
  • Privacy Policy
  • Utilities
Darchuk.NET

Testing

Unit Testing Common Logging with Moq

August 30, 2019 by Robert Leave a Comment

Sometimes there’s a path in a service or application that you want to test where all it does is log something and return.  You could check other things, but sometimes it is hard to check to see if something didn’t happen… and it would be a lot easier to know if something did happen, like … [Read more…]

Posted in: .NET Core, C#, Unit Testing Tagged: .NET Core, C#, Moq, Testing, unit testing

Unit Testing bit fields

August 9, 2019 by Robert Leave a Comment

Last week I wrote about bit fields and how they can be used to easily track boolean values.  Unit testing is pretty important to me, because I make mistakes a lot.  By writing tests, I can have a little bit of confidence in the code that I wrote. via GIPHY Bit Fields Knowing how bit … [Read more…]

Posted in: .NET Core, C#, Unit Testing Tagged: Bitwise, Csharp, enum, Flags, Testing

Spoofing a C# Stopwatch

May 24, 2019 by Robert Leave a Comment

C# has a Stopwatch class that is pretty accurate at timing things.  In fact, it uses some low-level operating system stuff to make sure to get exact timings.  This means it can be more accurate than comparing two different DateTime.Now instances. via GIPHY I’ve found myself using the Stopwatch occasionally, but it always is kind … [Read more…]

Posted in: .NET Core, C#, Unit Testing Tagged: .NET, C#, Testing, unit testing

C# overwriting a static field with reflection

April 5, 2019 by Robert Leave a Comment

Imagine that you have a NuGet package containing a bunch of static strings.  These fields are intended to be used instead of magic strings, making it so anything that takes a dependency on this NuGet package will all be on the same page about these unique keys. Now suppose that these keys also represent the … [Read more…]

Posted in: .NET Core, C#, Reflection, Unit Testing Tagged: Csharp, Reflection, Static, Testing

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

[object ErrorEvent] thrown … again

March 8, 2019 by Robert Leave a Comment

So there I am, happily writing unit tests, and suddenly this appears I keep seeing this error while trying to write Angular tests.  I… *think* this happens when something goes wrong during the constructor of a component.  I’ve written before about how it could be due to an @Input property not being initialized properly. But, … [Read more…]

Posted in: Angular, Jasmine, JavaScript, Typescript, Unit Testing Tagged: Angular, Jasmine, JavaScript, Testing, Typescript, UnitTesting

Getting Nested Classes With Reflection

February 1, 2019 by Robert Leave a Comment

Are you tired of feeling like your code is meaningless?  Sick of people not referring to your code as “black magic,” or struggling to gain recognition from your boss for writing sufficiently obfuscated code?If you’ve answered “yes” to any of the above, Reflection might be for you! via GIPHY Reflection I’ve talked about reflection a … [Read more…]

Posted in: C#, Reflection, Uncategorized, Unit Testing Tagged: C#, Reflection, Testing

Unit Testing NgbModal Modal Service

January 18, 2019 by Robert Leave a Comment

In the last blog post I showed how you could extend NgbModal to make a Modal Service, letting you re-use modal dialogs easily from within your Angular components. Even though its not always that much fun, I like to try and keep testability in mind when writing code… and, I’ll admit it, sometimes I gloss … [Read more…]

Posted in: Angular, Jasmine, JavaScript, Typescript, Unit Testing, Web Development Tagged: Angular, Dialog, Modal, NgbModal, Testing, Unit Test

RxJS 6 testing error paths

December 7, 2018 by Robert Leave a Comment

In a previous post I talked about how to use Observable.throw to simulate an Observable error in a unit test.  However, in RxJS 6, the syntax changed a bit.  I also talked about this a bit in this post about using of to create Observables on the fly for testing in RxJS 6, but I … [Read more…]

Posted in: Angular, JavaScript, Typescript, Unit Testing, Web Development Tagged: Observable, rxjs, RxJS6, Testing, throwError, UnitTesting

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
1 2 3 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