Skip to content

Instantly share code, notes, and snippets.

View waldyrfelix's full-sized avatar

Waldyr Felix waldyrfelix

View GitHub Profile
@section estilo {
<link href="@Url.Content("~/Scripts/uploadify/uploadify.css")" rel="stylesheet" type="text/css" />
<link href="@Url.Content("~/Content/themes/smoothness/jquery-ui.css")" rel="stylesheet" type="text/css" />
<link href="@Url.Content("~/Content/jquery.Jcrop.css")" rel="stylesheet" type="text/css" />
}
@section scripts {
@JavaScriptHelper.CadastroDeCurso() @* Isto não deveria estar aqui *@
}
@using (Html.BeginForm("Cadastrar", "Curso", FormMethod.Post, new { id = "frmCadastro", enctype = "multipart/form-data" }))
{
@waldyrfelix
waldyrfelix / criar tabelas.sql
Created November 8, 2011 17:34
Script de criação de tabela para o teste de performance.
create table categoria (
id int not null identity primary key,
nome varchar(100) not null,
)
create table produto (
id int not null identity primary key,
nome varchar(100) not null,
preco money not null,
categoria_id int not null foreign key references categoria(id)
@waldyrfelix
waldyrfelix / subselect.sql
Created November 8, 2011 17:35
Teste usando subselect para a consulta
select count(*) from categoria
where id not in (select categoria_id from produto)
@waldyrfelix
waldyrfelix / left outer join.sql
Created November 8, 2011 17:37
Teste usando left outer join para a consulta
select count(*) from categoria c
left outer join produto p on c.Id = p.categoria_id
where p.id is null
@waldyrfelix
waldyrfelix / preenchimento tabelas.sql
Created November 8, 2011 17:46
Preenchimento das tabelas para teste
-- inserindo categorias
insert into categoria (nome) values ('categoria ')
go 2000
-- inserindo produtos até demais...
declare @i int = 0
while @i < 100000
begin
insert into produto (nome, preco, categoria_id)
@waldyrfelix
waldyrfelix / gist:2564309
Created May 1, 2012 01:48
Converte um dataset para array de inteiro
private int[] dataSetToArray(DataSet dataset)
{
return dataset.Tables[0].Select()
.Select(row => Convert.ToInt32(row["ANO"]))
.ToArray();
}
@waldyrfelix
waldyrfelix / gist:3093834
Created July 11, 2012 21:48
Mock de um UnitOfWork retornada a partir de um ServiceLocator
public static Mock<IUnitOfWork> MockUnitOfWork()
{
var mockUnitOfWork = new Mock<IUnitOfWork>();
var mockUnitOfWorkFactory = new Mock<IUnitOfWorkFactory>();
mockUnitOfWorkFactory.Setup(_ => _.Criar())
.Returns(mockUnitOfWork.Object);
var mockServiceLocator = new Mock<IServiceLocator>();
mockServiceLocator.Setup(_ => _.GetInstance<IUnitOfWorkFactory>())
@waldyrfelix
waldyrfelix / gist:3093920
Created July 11, 2012 21:59
Mock para verificar sequencia de chamadas (iniciar transação, inserir um pacote de desconto, finalizar transação)
[TestMethod]
public void CadastrarPacoteDeDesconto_deve_chamar_o_repositorio_inserindo_o_pacotes_de_descontos_numa_transação()
{
// arrange
var pacote = new PacoteDesconto();
var mockUnitOfWork = TestHelper.MockUnitOfWork();
using (Sequence.Create())
{
@waldyrfelix
waldyrfelix / gist:3709328
Created September 12, 2012 19:34
Para liberar arquivos presos no TFS Preview
tf undo $/Root/Folder/file.txt /workspace:"Maquina";[email protected] /s:https://SERVER.tfspreview.com/DefaultCollection
@waldyrfelix
waldyrfelix / gist:3908162
Created October 17, 2012 21:02
AES Mode CBC with PKCS7 Padding
private static readonly byte[] iv = // array de 16 bytes
private static string decrypt(string message, string key)
{
var encryptedBytes = Convert.FromBase64String(message);
var aesAlg = makeAesCryptoServiceProvider(key);
var decryptor = aesAlg.CreateDecryptor();
using (var memory = new MemoryStream(encryptedBytes))