Skip to content

Instantly share code, notes, and snippets.

View bernardobrezende's full-sized avatar
:shipit:

Bernardo Bosak de Rezende bernardobrezende

:shipit:
View GitHub Profile
@bernardobrezende
bernardobrezende / GrupoDePessoas.cs
Created October 17, 2011 21:03
SchoolOO's PersonDAO makeover
using System.Collections.Generic;
using System.Linq;
namespace SchoolOO.DAO
{
public class GrupoDePessoas
{
public IList<Person> PorOrdemAlfabetica()
{
using (SchoolEntities schoolContext = new SchoolEntities())
@bernardobrezende
bernardobrezende / gist:1294485
Created October 18, 2011 02:37
Comparações entre teste com e sem membro estático
[TestMethod]
public void Se_Eu_Criar_Uma_Pessoa_Com_Endereco_Nos_EUA_TemResidenciaNoExterior_Deve_Ser_Verdadeiro()
{
Endereco[] enderecos = new [] { new Endereco("Porto Alegre", "BR"), new Endereco("Raccoon City", "US") };
Pessoa johnDoe = new Pessoa("John Doe", enderecos);
//
Assert.IsTrue(johnDoe.TemResidenciaNoExterior());
}
//////////
@bernardobrezende
bernardobrezende / gist:1294490
Created October 18, 2011 02:42
Comparações entre teste com e sem membro estático - Dependência estática
[TestMethod]
public void Se_Eu_Criar_Uma_Pessoa_Com_Endereco_Nos_EUA_TemResidenciaNoExterior_Deve_Ser_Verdadeiro()
{
Pessoa johnDoe = new Pessoa("John Doe");
// Como injetar os endereços para testar Pessoa isoladamente?
Assert.IsTrue(johnDoe.TemResidenciaNoExterior());
}
//////////
@bernardobrezende
bernardobrezende / gist:1309326
Created October 24, 2011 15:32
How to remove XML namespaces
using System.Linq;
using System.Xml.Linq;
namespace Foo.Namespace
{
public class XmlUtils
{
public static string RemoveAllNamespaces(string xmlDocument)
{
XElement xmlDocumentWithoutNs = RemoveAllNamespaces(XElement.Parse(xmlDocument));
@bernardobrezende
bernardobrezende / gist:1386540
Created November 22, 2011 18:57
Manipulando ViewBag de dentro do Action Filter
using System.Web.Mvc;
namespace Teste.TrocandoDadosComActionFilter.Controllers
{
public class HomeController : Controller
{
[MudaCor]
public ActionResult Index()
{
ViewBag.Cor = "Welcome to ASP.NET MVC!";
@bernardobrezende
bernardobrezende / gist:1388679
Created November 23, 2011 13:37
Dúvida sobre relacionamentos FNH
public class Pessoa
{
public virtual int Id { get; private set; }
public virtual string Nome { get; set; }
public virtual string Email { get; set; }
}
public class Login : Pessoa
{
public virtual string Senha { get; set; }
@bernardobrezende
bernardobrezende / gist:1388686
Created November 23, 2011 13:40
Mapeamentos do GIST #1388679
public class PessoaMap : ClassMap<Pessoa>
{
public PessoaMap()
{
Id(x => x.Id);
Map(x => x.Nome);
Map(x => x.Email);
}
}
@bernardobrezende
bernardobrezende / gist:1391870
Created November 24, 2011 17:35
Exemplo de bind em um DataGridView - Windows Forms
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
@bernardobrezende
bernardobrezende / gist:1393980
Created November 25, 2011 17:04
Microbenchmark para escrita/leitura em hashtable
using System;
using System.Diagnostics;
namespace MicroBenchmark.Hashtable
{
class Program
{
const int HASH_SIZE = 1000000;
static Guid keyToRetrieve;
@bernardobrezende
bernardobrezende / gist:1467471
Created December 12, 2011 14:29
Creating SessionFactory ignoring specific property.
var sessionFactory = Fluently
.Configure()
.Database(MsSqlConfiguration.MsSql2008.ConnectionString(c => c.FromConnectionStringWithKey("MyConnString")))
.Mappings(x => x.AutoMappings.Add(AutoMap.AssemblyOf<MyEntity>(mapConfig)
.OverrideAll(ign => ign.IgnoreProperty("MyPropertyToBeIgnored"))
))
.ExposeConfiguration(cfg => new SchemaUpdate(cfg).Execute(false, true))
.BuildSessionFactory();
return sessionFactory;