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.Text; | |
using MongoDB.Driver; | |
namespace SimpleMongoDb | |
{ | |
public class MongoDbContext | |
{ |
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 MongoDB.Driver; | |
using System; | |
namespace mvcMongoDB.Models | |
{ | |
public class CountryDB | |
{ | |
//For Best practice, Please put this in the web.config. This is only for demo purpose. | |
//==================================================== | |
public String connectionString = "mongodb://localhost"; |
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 MongoDB.Driver; | |
namespace Luru.Collections | |
{ | |
public class PaginatedList<T> | |
{ | |
public int PageIndex { get; set; } |
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 class TempDataDocument | |
{ | |
[BsonRepresentation(BsonType.ObjectId)] | |
public string Id { get; set; } | |
[BsonElement("key")] | |
public string Key { get; set; } | |
[BsonElement("value")] | |
[BsonSerializer(typeof(CustomSerializer))] | |
public object Value { get; set; } | |
} |
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 MvcMockHelpers | |
{ | |
public static HttpContextBase FakeHttpContext() | |
{ | |
var context = new Mock<HttpContextBase>(); | |
var request = new Mock<HttpRequestBase>(); | |
var response = new Mock<HttpResponseBase>(); | |
var session = new Mock<HttpSessionStateBase>(); | |
var server = new Mock<HttpServerUtilityBase>(); |
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 class BetterDefaultModelBinder : DefaultModelBinder | |
{ | |
protected override object CreateModel(ControllerContext controllerContext, ModelBindingContext bindingContext, Type modelType) | |
{ | |
var model = base.CreateModel(controllerContext, bindingContext, modelType); | |
if (model == null || model is IEnumerable) | |
return model; | |
foreach (var property in modelType.GetProperties(BindingFlags.Public | BindingFlags.Instance)) |
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 class HttpContextBuilder | |
{ | |
private Mock<HttpContextBase> _context; | |
private Mock<HttpRequestBase> _request; | |
private Mock<HttpResponseBase> _response; | |
private Mock<HttpSessionStateBase> _session; | |
private Mock<HttpServerUtilityBase> _server; | |
private Mock<IPrincipal> _user; | |
private Mock<IIdentity> _identity; |
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 HttpContextBase FakeHttpContext() { | |
var context = new Mock<HttpContextBase>(); | |
var files = new Mock<HttpFileCollectionBase>(); | |
var request = new Mock<HttpRequestBase>(); | |
var response = new Mock<HttpResponseBase>(); | |
var session = new Mock<HttpSessionStateBase>(); | |
var server = new Mock<HttpServerUtilityBase>(); | |
var user = new Mock<IPrincipal>(); | |
var identity = new Mock<IIdentity>(); | |
request.Setup(req => req.ApplicationPath).Returns("~/"); |
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.Text; | |
namespace System.Security.Cryptography { | |
public static class StringExtensions | |
{ | |
public static int CRC32(this string src) | |
{ | |
return (int)Crc32.Compute(Encoding.UTF8.GetBytes(src)); | |
} |
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; | |
namespace System.Data.SqlClient { | |
public class SqlHelper { | |
readonly string connectionString; | |
public SqlHelper(string connectionString) { this.connectionString = connectionString; } | |
public string StringCommand (string commandString, Action<SqlParameterCollection> bindingCommand) { | |
using (var connection = new SqlConnection(connectionString)) { |