Software Testing Series Introduction

Hello everyone,

Today, I am going to introduce a new tutorial series about software testing. Software testing is a pretty big topic (with frameworks and scenarios) but I am thinking about writing the following list. Hopefully it might help you to figure something about the topic and they can be useful notes for myself :).

Continue reading Software Testing Series Introduction

How to Install and Use PostgreSQL on Dotnet

Hi,

I will try to explain how to install PostgreSql on windows pc and how to change available .net web api project database with PostgreSql. Firstly, let’s download and install PostgreSql. You can download it from here. Installation screens is as follows.

When you click finish button, second installation will start. Second installation is for administration tools. I skipped this step because I installed them before. But you should continue, because I used pgAdmin afterwards. It’s mean, you will see screenshots from pgAdmin. Anyway, let’s check the PostgreSQL. Click to start menu on windows and search pgAdmin from my computer. It’s browser based management panel for pgAdmin. pgAdmin screenshot is as follows.

Now, I will create a new database for my web api via pgAdmin. The screenshot is as follows.

After create a database, firstly I runned as follows command.

dotnet tool install –global dotnet-ef

I have already Entity Framework library in my project. Now, I will add a sub library. That version should be same with available Entity Framework. It’s as follows.

dotnet add package Microsoft.EntityFrameworkCore.Design

I need one more library for this example. I will include PostgreSQL to my project. This library is as follows.

dotnet add package Npgsql.EntityFrameworkCore.PostgreSQL –version 3.1.1

Before database migration and update, I should add new line on my DBContext file. New line will be on onConfiguring method.

optionsBuilder.UseNpgsql(@”Host=localhost;Port=5432;Username=postgres;Password=YourPassword;Database=YourDatabase“);

Now, Everything is ready for migration and update. You should run this command on your Data Access project.

dotnet ef migrations add example

The screenshot is as follows.

Let’s run last command and then database will be ready.

Let’s return pgAdmin and check tables. The screenshot is a follows.

Now, database and connection ready for use. Let’s run web api and check connection.

Example method;

Thanks.

How to Write .Net Core Web Api via MongoDB on Windows Computer

Hi,

I will try to explain “How to write .net core web api via MongoDB” in this post. Firstly, I should install MongoDB to my computer. Let’s get start. I used this link for download. Example screenshot is as follows.

After downloaded application, Let’s start to install it. The screenshots are as follows.

You can cancel MongoDB Compass. I didn’t install it.

After installation, I added new value in environment variables. This is for command prompt. I used mongoDB setup location in this step. My one is C:\Program Files\MongoDB\Server\4.2\bin If you want, you can skip this step.

I added two times. First one User variables for Your Username area and second one is system variables area. You should restart your computer after this step.
Let’s check MongoDB commands. I checked some commands. First command is;

mongo

show databases

use databaseName

db.CreateCollection(“ExampleCollection”)

db.DropDatabase()

That examples are enough for now. Maybe we can check all commands in another article. Now, let’s get start to web api.

I created and opened my project. After created project, I added mongoDB driver in my project. I used command for this as follows.

dotnet add package MongoDB.Driver –version 2.9.2

You can see this package in your .csproj file.

I started from model folder for development. Firstly, I created base model file. I added Id field because mongoDB is using Id field in collections. I created base model file for this. The screenshot is as follows.

After this file, I created an example model for my web api methods.

Now, I created a base repository for my models. I will use this with my model repository.

Example model repository is as follows.

I added connection string property in appconfig.json file. I will use this in startup.cs file.

Startup.cs is as follows.

Example methods are as follows.

Now, I can see my database on command prompt.

You can download my example project in this link.

Thanks.

How to include React in Available .Net Core Web Application

Hi,

In this post, I will try to explain “How to include React in available .Net Core Web Application” You can access example code end of the post. Let’s get start.

I don’t have any project for this example. Because of this I created empty project for this example. You can pass the project create step. The screenshot is as follows.

I selected project template on second step. Example project will be web application.

My project is ready now. Before start to development, I should include some packages for react. This packages are as follows.

React.AspNet,

JavaScriptEngineSwitcher.ChakraCore

JavaScriptEngineSwitcher.ChakraCore.Native.win-x64 (If you are using Windows x86 or another OS, you should download your version for this OS.)

JavaScriptEngineSwitcher.Extensions.MsDependencyInjection

After downloaded packages, I modified startup.cs file in my project. Firstly, I added new libraries to startup.cs. This libraries as follows.

using Microsoft.Extensions.DependencyInjection

using JavaScriptEngineSwitcher.ChakraCore

using JavaScriptEngineSwitcher.Extensions.MsDependencyInjection

using React.AspNet

My page is as follows.

I added the following code to the end of configureservices method.

I added code in configure method as follow. This code must be before static files. The screenshot is as follows.

I created JSX folder in wwwroot. I will use this folder for my react files. Let’s start.

Firstly, I added new div in my masterpage layout. (_layout.cshtml) My react components will use this div. The screenshot is as follows.

Now, I can write react code. I added a new jsx file in my jsx folder. The screenshot is as follows.

My component details are as follows.

In this step, I called react file from _layout.cshtml. I added codes bottom of in my master page as follow. (_layout.cshtml)

Script links are as follows.

https://cdnjs.cloudflare.com/ajax/libs/react/16.8.0/umd/react.development.js

https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.8.0/umd/react-dom.development.js

I started localhost and It worked!

 

I shared example codes on github. You can access from this link.

Thanks.