C#

String Extensions

using System.Globalization; using System.Linq; using System.Text; namespace ALeonJ.Extensions { public static class StringExtensions { public static string RemoveDiacritics(this string value) { if (string.IsNullOrWhiteSpace(value)) { ...
Read More

‘Required If’ Validation Attribute

namespace ALeonJ.ValidationAttributes { using System; using System.ComponentModel.DataAnnotations; using System.Globalization; /// <summary> /// Provides conditional validation based on related property value. /// ...
Read More

‘Numeric Greater Than’ Validation Attribute

namespace ALeonJ.ValidationAttributes { using System.ComponentModel.DataAnnotations; public class NumericGreaterThanAttribute : ValidationAttribute { private readonly string otherPropertyName; public NumericGreaterThanAttribute(string otherPropertyName) { this.otherPropertyName = ...
Read More

‘Must Be Checked’ Validation Attribute

namespace ALeonJ.ValidationAttributes { using System; using System.ComponentModel.DataAnnotations; public class MustBeCheckedAttribute : ValidationAttribute { public override bool IsValid(object value) { if (value ...
Read More

‘Minimum Elements’ Validation Attribute

namespace ALeonJ.ValidationAttributes { using System.Collections; using System.ComponentModel.DataAnnotations; public class MinimumElementsAttribute : ValidationAttribute { private readonly int minElements; public MinimumElementsAttribute(int minElements) { ...
Read More

‘Date Less Than’ Validation Attribute

namespace ALeonJ.ValidationAttributes { using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Web.Mvc; public class DateLessThanAttribute : ValidationAttribute, IClientValidatable { private readonly string ...
Read More

‘At Least One True’ Validation Attribute

namespace ALeonJ.ValidationAttributes { using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Web.Mvc; public class AtLeastOneTrueAttribute : ValidationAttribute, IClientValidatable { public AtLeastOneTrueAttribute(string otherPropertyNames) ...
Read More

Stream Extensions

namespace ALeonJ.Extensions { using System.IO; using System.Linq; public static class StreamExtensions { public static bool HasSameContentAs(this MemoryStream memoryStream1, MemoryStream memoryStream2) { ...
Read More

Identity Extensions

namespace ALeonJ.Extensions { using System; using System.Security.Principal; using Microsoft.AspNet.Identity; public static class IdentityExtensions { public static Guid GetUserIdAsGuid(this IIdentity identity) { ...
Read More

Exception Extensions

namespace ALeonJ.Extensions { using System; using System.Collections.Generic; using System.Linq; public static class ExceptionExtensions { public static string MessageWithInnerExceptions(this Exception exception) { ...
Read More

Enumerable Extensions

namespace ALeonJ.Extensions { using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; public static class EnumerableExtensions { public static void ForEach<T>(this IEnumerable<T> ...
Read More

Enhanced Wrapper for ASP.NET Identity

Identity Security Wrapper namespace ALeonJ.Security.Identity { using System; using System.Linq; using System.Text; using System.Web.Security; using ALeonJ.Security.Identity.Interfaces; using ALeonJ.Security.Identity.Models; using Microsoft.AspNet.Identity; using Microsoft.AspNet.Identity.Owin; ...
Read More

Unit Testing an ASP.NET MVC Controller

Some people argue that there is no value in testing MVC Controllers as they should not be housing any complex ...
Read More

ArrangeActAssert Test Class Structure

namespace ALeonJ { using System; using System.Diagnostics.CodeAnalysis; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq.AutoMock; [TestClass] public abstract class ArrangeActAssert<TUnderTest> where TUnderTest : class { ...
Read More