Blog with ASP.NET Core and React/Redux. Part 3: Mock data

This is part of the series “Blog with ASP.NET Core and React/Redux”.

Image for post
Image for post

Before we start implementing features like stories search, likes or comments we want to have some data in our DB. So the goal for this part is to write a script that will populate our database with mock data.

Image for post
Image for post

All code for this part you can find in front-end and back-end repositories.

Back-end

This part will have only back-end part. We will write a script that will fetch users stories from Medium and save them in our format.

Let’s start by creating a new project.

$ dotnet new console -o Blog.Mocker

Now, we want to specify what we mean by mock data. It will be just a list of users and a list of stories. With time we can extend our pack, but for now, this set of data is sufficient.

In this part, we will use Medium to get mock data, but maybe someday we will want to use some other source. So we will make an interface for our mock data generator.

The simplest method for getting user stories from Medium appears to be fetching RSS feed. We will not take info about the user from this feed but only take some fields from the stories he made.

In order to use RSS helpers, we need to install an additional library.

$ dotnet add package Microsoft.SyndicationFeed.ReaderWriter

Our Program file will consist of this steps.

  1. Get mock set of data by passing list of usernames to Medium instance method.
  2. Specify BlogContext.
  3. Saving users to DB.
  4. Saving stories to DB.

In the next part, we will allow a user to like stories. Stay tuned!

Reach the next level of focus and productivity with increaser.org.

Image for post
Image for post
Increaser

Written by

Software engineer, creator of increaser.org. More at geekrodion.com

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store