This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Reflection; | |
using System.ServiceModel; | |
using System.ServiceModel.Channels; | |
using System.ServiceModel.Description; | |
using System.ServiceModel.Dispatcher; | |
using System.Web; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Custom function to perform looping operation. | |
/// </summary> | |
/// <typeparam name="T">type of ienumerable</typeparam> | |
/// <param name="list">The list.</param> | |
/// <param name="action">The action.</param> | |
/// <returns>index value</returns> | |
/// <exception cref="System.ArgumentNullException"> if the supplied action is null</exception> | |
public static int ForEach<T>(this IEnumerable<T> list, Action<int, T> action) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Gets the error message attribute. | |
/// </summary> | |
/// <param name="memberName">Name of the member.</param> | |
/// <returns> | |
/// value of attribute from class | |
/// </returns> | |
public static string GetErrorMessageAttributeValue(string memberName) | |
{ | |
string message = string.Empty; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void Usage() | |
{ | |
var instance = new Timer(); | |
// check if the event is assigned a handler | |
if (GetEventHandler(instance, "Elapsed", "ElapsedEventHandler") == null) | |
{ | |
throw new InvalidOperationException(string.Format("The Timer elapsed event must be assigned an event handler. Source: {0}", type.FullName)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. Stub() defines the behavior for stubbed object. | |
2. Expect() defines the behavior and the expectation for mocked object. | |
3. Follow the principle of "Test only one thing per test". | |
4. mockrepositoryObject doesn't stop recording until you call ReplayAll. Try using repositoryInstance.PlayBack(); | |
sample: | |
using (repository.Playback()) | |
{ | |
} | |
5. Call repository.VerfiyAll() in the end. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.ComponentModel; | |
using System.IO; | |
using System.Linq; | |
using System.Net; | |
using System.Net.Security; | |
using System.Reflection; | |
using System.Security.Cryptography.X509Certificates; | |
using System.Text; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// DoAsync is a method template to perform any task asynchronously. | |
/// </summary> | |
/// <typeparam name="T">type of argument</typeparam> | |
/// <param name="action">method</param> | |
/// <param name="argument">value of argument of type T</param> | |
public static void DoAsync<T>(Action<T> action, T argument) | |
{ | |
// Invoke the task to execute the item | |
Task.Factory.StartNew(() => action.Invoke(argument), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Testing websites: | |
http://www.regex101.com/r/yM3vL0 | |
http://www.regexplanet.com/advanced/dotnet/index.html | |
UrlSourceOrLocalDriveWithRegex = @"(?i)\b^(https?|s?ftp)+:\/\/[aA-zZ]*[0-9]*|([aA-zZ]{1}:{1}\\{1}\b).*$"; | |
Matches: Https://www.something.com, Ftp://somesource.com, sftp://securesource.com, http://moreurl.com, C:\path etc. | |
Unmatch: httpss://something.com, abcd://, c:, C, | |
SystemDriveOrUNCPathRegex = @"^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w ]*.*))+$" | |
Matches: c:\folder, \\server\folder |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class HtmlHelperExtensions | |
{ | |
private static readonly char Separator = '/'; | |
private static readonly string TemplateFolder = HttpContext.Current.Server.MapPath("~/App/templates"); | |
private static readonly IViewEngine ViewEngine = new HandlebarsRazorViewEngine(); | |
public static MvcHtmlString RenderEmber(this HtmlHelper helper, string path = "", bool noTemplateName = false) | |
{ | |
if (HttpRuntime.Cache[path] == null) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// The deserialize to generic list. | |
/// </summary> | |
/// <param name="jsonString"> | |
/// The json string. | |
/// </param> | |
/// <typeparam name="TReturnType">Type of a list of type TItemType | |
/// </typeparam> | |
/// <typeparam name="TItemType">Type of generic argument to list | |
/// </typeparam> |