Skip to content

Instantly share code, notes, and snippets.

private static void InputDbNullWithDefault(SqlCommand cmd)
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "usp_Input_Has_Default";
SqlParameter par = new SqlParameter("@param1", SqlDbType.VarChar);
par.Direction = ParameterDirection.Input;
par.Value = DBNull.Value;
cmd.Parameters.Add(par);
}
private static void NoInputWithDefault(SqlCommand cmd)
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "usp_Input_Has_Default";
}
private static void OutputNoDefault(SqlCommand cmd)
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "usp_Output_No_Default";
SqlParameter par = new SqlParameter("@param1", SqlDbType.VarChar);
par.Direction = ParameterDirection.Output;
par.Size = 50;
par.Value = null;
cmd.Parameters.Add(par);
CREATE PROCEDURE [dbo].[usp_Output_No_Default]
@param1 VARCHAR(50) OUTPUT
AS
SELECT @param1;
SET @param1 = 'changed by procedure';
RETURN 0
@crowcoder
crowcoder / CSharpBasicAlternateDataStream
Last active August 13, 2019 12:05
A bare-bones example of how to write alternate data streams with C#
using Microsoft.Win32.SafeHandles;
using System;
using System.IO;
using System.Runtime.InteropServices;
namespace AlternateDataStreams
{
class Program
{
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
using Moq;
using Service;
using System;
namespace Business.Tests
{
public static class StockServiceMocks
{
/// <summary>
/// Causes GetCurrentPrice to return a specific price or optionally throws an exception.
namespace Service
{
public interface IStockService
{
Trade Buy(string ticker, decimal nbrShares);
decimal GetCurrentPrice(string ticker);
Trade GetLastTrade(string ticker);
Trade Sell(string ticker, decimal nbrShares);
}
}
namespace Service
{
public interface ILogService
{
void Log(string logMessage);
}
}
using Service;
using System;
namespace Business
{
public class StocksLogic
{
private readonly IStockService _stockService;
private readonly ILogService _logService;
[TestMethod]
public void BuyWhenLastTradeWasSell_Test()
{
#region setup the stock service
decimal simulatedCurrentPrice = 8.03m;
Trade simulatedLastTrade = new Trade
{
Ticker = "ABC",
Side = "sell",