Skip to content

Instantly share code, notes, and snippets.

View priyankadavle's full-sized avatar

priyankadavle

View GitHub Profile
@priyankadavle
priyankadavle / gist:c99fe1456b835b4a2ef36609cd468d1e
Created November 15, 2017 16:00
ISqlConnection Mocking (Unit Test)
class SqlDataContext : ISqlDataContext {
private readonly SqlConnection _connection;
public SqlDataContext(string connectionString)
{
_connection = CreateConnection(connectionString);
}
public IDataReader ExecuteReader(string storedProcedureName, ICollection<SqlParameter> parameters)
declare @encrypt varbinary(200)
select @encrypt = EncryptByPassPhrase('key', 'abc' ) //abc is the data you want to encrypt
select @encrypt
select convert(varchar(100),DecryptByPassPhrase('key', @encrypt ))
@priyankadavle
priyankadavle / gist:6f149850ab55bf95f17c56ea5c332bca
Created October 27, 2017 14:38
Suppress warning CS1998: This async method lacks 'await'
I've got an interface with some async functions.
Methods returning Task, I believe. async is an implementation detail, so it can't be applied to interface methods.
Some of the classes that implements the interface does not have anything to await, and some might just throw.
In these cases, you can take advantage of the fact that async is an implementation detail.
If you have nothing to await, then you can just return Task.FromResult:
public Task<int> Success() // note: no "async"
{
@priyankadavle
priyankadavle / gist:b1b7f29df6de28903b729bb69d4489f1
Created October 23, 2017 15:31
ConfigurationManager.AppSettings for UnitTests
When developing an ASP .NET MVC or WebAPI based application, we eventually need to read configurations from <appSettings> section of Web.Config file. Here is an example entry from my imaginary project:
<configuration>
<!-- other config sections -->
<appSettings>
<add key="app.name" value="My Application" />
<add key="app.domain" value="mydomain.com" />
<add key="encryption.algorithm" value="TripleDES" />
<add key="encryption.key" value="MY_KEY" />
@priyankadavle
priyankadavle / API GET Call
Created October 12, 2017 18:43
API GET Call
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.Http;
using System.Net;
namespace HTTP_Test