Skip to content

Instantly share code, notes, and snippets.

View gBritz's full-sized avatar
🎯
Focusing

Guilherme Britz Videira gBritz

🎯
Focusing
View GitHub Profile
@gBritz
gBritz / LogAuditXmlSoap.cs
Created April 2, 2019 20:43
Log xml soap webservice
using System;
using System.Diagnostics;
using System.IO;
using System.Web.Services.Protocols;
namespace SoapService.Client
{
public class LogXmlSoap : SoapExtension
{
private Stream oldStream;
using System;
using System.Diagnostics;
using System.IO;
using System.Web.Services.Protocols;
namespace SoapService.Client
{
public class LogXmlSoap : SoapExtension
{
private Stream oldStream;
@gBritz
gBritz / interceptor.js
Created October 2, 2018 03:57
Proxy all methods in javascript for debugging
/*
Proxy all methods from object to log all calls in console for debugging.
Exemplo:
var myObj = {
property: 1,
sendTo: function (endpoint) {
console.log('sending ' + this.property + ' to ' + endpoint);
}
};
@gBritz
gBritz / ApplyTagDescriptionFromControllerSummary.cs
Created November 17, 2016 21:37
Swagger > Swashbuckle > Apply tag description from summary comments of apicontroller class
using System.Collections.Generic;
using System.Linq;
using System.Web.Http.Description;
using System.Xml.XPath;
using Swashbuckle.Swagger;
using Swashbuckle.Swagger.XmlComments;
namespace Web.Common.Swagger
{
public class ApplyTagDescriptionFromControllerSummary : IDocumentFilter
@gBritz
gBritz / FileLog.cs
Created September 14, 2016 12:52
Utility log method
private static void Log(string message, params object[] args)
{
if (!args.IsEmpty())
{
message = message.With(args);
}
var msg = "{0:dd/MM/yyyy hh:mm:ss.fff} {1}{2}".With(DateTime.Now, message, Environment.NewLine);
File.AppendAllText(@"C:\log.txt", msg);
}
@gBritz
gBritz / IDbAsyncEnumerableExtensions.cs
Created August 25, 2016 16:54
ForEachAsync to asynchronous action
using System;
using System.Data.Entity.Infrastructure;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace Extensions
{
/// <summary>
/// http://stackoverflow.com/questions/29787098/doesnt-await-when-using-foreachasync-with-await-inside-action#29787099
@gBritz
gBritz / ExceptionFilterTest.cs
Created July 29, 2016 18:20
Testing multiples mvc exception filters
using System;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using LiterateElephant.Web.Common;
using LiterateElephant.Web.Common.Utilities;
using Moq;
using Xunit;
namespace LiterateElephant.Tests.Web
@gBritz
gBritz / MyDbContext
Created June 6, 2016 20:38
dbcontext with modified properties, update sql statement without before load entity
public class MyDbContext : DbContext
{
public void ModifiedProperties<TEntity>(TEntity instance, params string[] propertyNames) where TEntity : class, IEquatable<TEntity>
{
DbEntityEntry<TEntity> entity = Attached<TEntity>(instance).FirstOrDefault();
if (entity != null)
{
entity.State = EntityState.Detached;
}
@gBritz
gBritz / PropertyExtractor.cs
Created June 6, 2016 20:09
property extractor
using System;
using System.Linq;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Reflection;
namespace Util
{
public class PropertyExtractor<T> where T : class
{
@gBritz
gBritz / SaveFileTest.cs
Last active April 29, 2016 13:36
test mocking file system
[Fact]
public async Task GivenCorrectlyFile_WhenSaveAsync_ShouldBeStorageFile()
{
var filePath = "C:\\CWI\\Elefante Letrado\\src\\LiterateElephant.Tests\\bin\\Debug\\Content\\cdn\\audio\\20160427123212_AudioLouco.mp3";
var fileDataMock = new MockFileData(new byte[0]);
var fileSystemMock = new MockFileSystem();
fileSystemMock.AddFile(filePath, fileDataMock);