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.Net; | |
using System.Net.Http; | |
using System.Net.Http.Headers; | |
using System.Text; | |
using System.Threading.Tasks; | |
using WebApiContrib.Internal; | |
namespace WebApiContrib.MessageHandlers | |
{ |
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
if (Regex.IsMatch(Request.Url.AbsoluteUri, @"^((http|https)://[^www]).*$")) | |
{ | |
string newDomain = String.Format("{0}://www.{1}{2}", | |
Request.Url.Scheme, | |
Request.Url.Authority, | |
Request.Url.AbsolutePath); | |
Response.Status = "301 Moved Permanently"; | |
Response.AddHeader("Location", newDomain); | |
Response.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
public class AppBasicAuthenticationAttribute : BasicAuthenticationAttribute | |
{ | |
public override string Realm { get { return "DOMINIO"; }} | |
public override bool Authorize(string username, string password) | |
{ | |
var membershipService = IoC.Current.Resolve<IMembershipService>(); | |
return membershipService.ValidateUser(username, password); | |
} | |
} |
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
$.ajax({ | |
url: "http://localhost:36210/api/values", | |
type: "GET", | |
dataType: "json", | |
beforeSend: function(xhr){ | |
xhr.setRequestHeader('Authorization', 'Basic d2FsZHlyOjEyMw=='); | |
}, | |
success: function(data) { | |
$(data).each(function(index, value){ | |
console.log(index + ') '+ value); |
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 (var client = new HttpClient()) | |
{ | |
client.DefaultRequestHeaders.Add("Authorization", "Basic d2FsZHlyOjEyMw=="); | |
var strings = await client.GetAsync("/api/values"); | |
var strResult = await strings.Content.ReadAsStringAsync(); | |
var serializer = new JavaScriptSerializer(); | |
var result = serializer.Deserialize<string[]>(strResult); | |
foreach (var s in result) |
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
private static readonly byte[] iv = // array of 16 bytes | |
public static string Encrypt(string message, string password) | |
{ | |
var algorithm = SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithmNames.AesCbcPkcs7); | |
var key = algorithm.CreateSymmetricKey(Encoding.UTF8.GetBytes(password).AsBuffer()); | |
var encrypted = CryptographicEngine.Encrypt(key, Encoding.UTF8.GetBytes(message).AsBuffer(), iv.AsBuffer()); | |
return CryptographicBuffer.EncodeToBase64String(encrypted); | |
} |
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
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)) |
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
tf undo $/Root/Folder/file.txt /workspace:"Maquina";[email protected] /s:https://SERVER.tfspreview.com/DefaultCollection |
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
[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()) | |
{ |
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 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>()) |
NewerOlder