• About
  • Privacy Policy
  • Utilities
Darchuk.NET

Autofac.Extras.Moq AutoMock

March 23, 2018 by Robert Leave a Comment

Unit testing can be annoying.  Sometimes it feels like setting up a delicate house of cards in just the right way and hoping that nobody opens a window to let a breeze knock the whole thing over. If you’re using inversion of control (and you should be), its a little easier because you can use … [Read more…]

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

TimedProcessor – A slightly fancier timer

March 16, 2018 by Robert Leave a Comment

Timers are pretty useful.  They allow you to define a block of code that will execute on a given interval.  It’s the C# version of JavaScript’s setInterval.  There’s a lot of different reasons for using a timer, such as persisting updates to a database.  Since database calls can be slow, maybe you want to build … [Read more…]

Posted in: .NET Core, Asynchronous, C#, Concurrency Tagged: async, Asynchronous, C#, setInterval, Timer

MongoDB–Projecting and filtering out of a list

March 9, 2018 by Robert Leave a Comment

Recently I had an interesting MongoDB query that I wanted to write.  I had a document that contained a list, and I wanted to query a specific item out of the list, returning only the fields that I wanted.  Here’s a similar dataset: In this example, many different records may be created under the same … [Read more…]

Posted in: Asynchronous, C#, Mongo Tagged: C#, CRUD, Lists, Mongo

C# Mongo array CRUD

March 2, 2018 by Robert Leave a Comment

MongoDB is a pretty cool document database that allows you to just toss data into a database without worrying too much about a schema. It’s not quite that easy, of course, because your code might be looking for specific properties, but its simpler than being stuck to a rigid schema. Lists and stuff Recently I … [Read more…]

Posted in: Asynchronous, C#, Mongo Tagged: Array, C#, Create, CRUD, Database, Delete, Mongo, Read, Update

D3.js, “this”, and TypeScript

February 23, 2018 by Robert Leave a Comment

D3.js is a super cool and very powerful library for creating some really interesting visualizations. One of the problems that I ran into recently was regarding the “this” keyword in D3 functions.  For example, in regular old javascript you would do: Which is fine.  “this” is scoped to the function, so it would point back … [Read more…]

Posted in: D3, JavaScript, Typescript, Web Development Tagged: d3, JavaScript, this, Typescript

ASP.NET Core [FromBody] Null?

February 16, 2018 by Robert Leave a Comment

Recently I was having an issue where a parameter being passed in to my WebAPI call was not being populated correctly. Theoretically all you need to do is add [FromBody] to the route, and it will automatically populate the object from the HTTP message’s body… but that wasn’t working for me Turns out this IS … [Read more…]

Posted in: .NET Core, C#, Web API, Web Development Tagged: .NET, .NET Core, [FromBody], model, Null, Serialization, Web API

Javascript – Combining arrays with the spread operator

February 9, 2018 by Robert Leave a Comment

Recently I had several small arrays in Javascript that I wanted to combine into one array.  It would be easy enough to write a function to accept two arrays, push the values from one into the other, and return the resulting array, but ECMAScript 6 introduced the spread operator (<—a lot more examples in this … [Read more…]

Posted in: JavaScript, Typescript Tagged: JavaScript, Spread, Typescript

Moq sequential callbacks

February 2, 2018 by Robert Leave a Comment

In the last blog post I talked about how to use Moq’s built in SetupSequence to create a “chain” of actions to execute for subsequent calls of the same mocked method. This works great for the simple case, but falls down when you have to do something a little more complicated like, say, issue a … [Read more…]

Posted in: C#, Unit Testing Tagged: C#, Callback, Moq, Sequence, Sequential, unit testing

Moq sequential calls

January 26, 2018 by Robert 1 Comment

Say that you’re unit testing and you want a mocked interface to behave differently for different calls to the same method. I was trying to test a TCP listener loop – a TcpListener waits for an incoming connection, does something with it, and then goes back to listening.  In essence, the loop will last until … [Read more…]

Posted in: Asynchronous, C#, Unit Testing Tagged: C#, Concurrency, Moq, unit testing

Mocking TcpClient

January 19, 2018 by Robert Leave a Comment

Sometimes I want to unit test the pieces of my code that are close to the transport layer, but often they are so close to the metal that it is hard to separate them. There’s really not a great way to abstract out the communication layer, so you just have to bite the bullet and … [Read more…]

Posted in: C#, Unit Testing Tagged: C#, Mock, TCP, TcpClient, unit testing
« Previous 1 … 8 9 10 … 12 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