Showing posts from 2020

Unit test c#: Create Fake Httpcontext to bypass Null exception for User object

Microsoft Visual studio Test Framework
Requirement: Nuget package Moq (or later)
Settings in visual studio: Menu->Tools->Options ->Debugging->General Tick "Use Managed Compatibility Mode"
Code: (copied from stackoverflow) Step 1: Create a new class FakeHttpContext and paste the below code. Change the Returns value to whatever user name you need.
public static class FakeHttpContext    {         public static void SetFakeContext(this Controller controller)         {
            var httpContext = MakeFakeContext();             ControllerContext context =             new ControllerContext(             new RequestContext(httpContext,             new RouteData()), controller);             controller.ControllerContext = context;         }

        private static HttpContextBase MakeFakeContext()         {             var context = new Mock<HttpContextBase>();             var request = new Mock<HttpRequestBase>();             var response = new Mock<HttpResponseBase&g…

Accessing SMB share from Raspberry pi (or linux)

Install smbclient :sudo apt update sudo apt install smbclientList the share items in the server:smbclient -L hostfor example: smbclient -L need to enter password.then you'll see the result like this:Domain=[WORKGROUP] OS=[Windows 6.1] Server=[Samba 4.9.5-Debian] Sharename Type Comment --------- ---- ------- print$ Disk Printer Drivers RaspberrypiShare Disk IPC$ IPC IPC Service (Samba 4.9.5-Debian) pi Disk Home Directories Domain=[WORKGROUP] OS=[Windows 6.1] Server=[Samba 4.9.5-Debian] Server Comment --------- ------- RASPBERRYPI Samba 4.9.5-Debian Workgroup Master --------- -------To browse Shared folder :smbclient \\\\\\RaspberrypiShare pa$$w0rd

Temperature/CPU/Memory info of Raspberry Pi in console

Open the console/terminal in the desktop or
Connect to the raspberry pi via ssh and type in the below command

For temperature:
/opt/vc/bin/vcgencmd measure_temp

For CPU info:
cat /proc/cpuinfo

For Memory info:
cat /proc/meminfo

Add Python(or Java or anything) to Environment variables

After installation of python in windows 10, python is not added to environment variable by default. If you want to use cmd for python, then python installed path must be configured in the environment variable.  When you type python in cmd, you'll see the below message:
Follow the below steps to add python to environment: 1) Open System in Control panel 2) Click Advanced system settings 3)Click Environment Variables 4) Select Path in User Variables and click edit 5) Either create new and type in the path of Python installed location or Browse the folder using browse button in the above screenshot.
6) Click OK and close the Environment variables settings window and all other opened windows.  7) Start a new command prompt and type python to test.  Done!

Add Azure Devops plugins in Android Studio for Git or TFVC Version control

By default, Android studio can not connect to the Azure devops source codes. To connect to the Azure devops, a plugins by Microsoft needs to be installed in the android studio. To install the plugin, follow the below steps:

1) Open a project in Android studio
2) go to File --> Setting
3) go to Plugins
4) Search for azure devops
5) Click Install
6) Restart the Android studio.
7) Menu->VCS->Checkout from Version Control -> Azure Devops Git
8)Click Sign in ...  9) Follow the wizard to connect the project.

Create Azure SQL User and add a sql role

I wanted to add a new sql user "sqluser" in Azure SQL server to access a database "sanjeeb".

Steps to create a new SQL user. 

1) Connect to the Azure sql server with existing user using Microsoft SQL Server Management studio

2) Open new query window under Master database

3) Run the below script

CREATE LOGIN [sqllogin] WITH PASSWORD = 'verystrongpassword#1' 

4) Open new query window under database "sanjeeb"
5) Run the below script
-- Add user to the database owner role EXEC sp_addrolemember N'db_owner', N'sqluser' GO
6) You've now created a user login "sqllogin", user account "sqluser" and added the user to "db_owner role"

7) Connect to the database using the new user login account. 
login: sqllogin password:verystrongpassword#1