Skip to content

Instantly share code, notes, and snippets.

Alex Brown alexjamesbrown

Block or report user

Report or block alexjamesbrown

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@alexjamesbrown
alexjamesbrown / applicationConfig.xdt
Created Mar 14, 2019
disable urlCompression for Azure Functions via xdt transform
View applicationConfig.xdt
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.webServer>
<urlCompression xdt:Transform="Remove" />
<urlCompression doStaticCompression="false" doDynamicCompression="false" xdt:Transform="InsertIfMissing" />
</system.webServer>
</configuration>
@alexjamesbrown
alexjamesbrown / TopicProcessorWithRetry.cs
Created Feb 23, 2019
Example of retrying messages by re-queuing
View TopicProcessorWithRetry.cs
[FunctionName("TopicProcessor")]
public static async Task Run(
[ServiceBusTrigger("%topic-name%", "%subscription-name%", AccessRights.Manage, Connection = "connection")] BrokeredMessage msg,
[ServiceBus("%topic-name%", AccessRights.Manage, Connection = "connection", EntityType = EntityType.Topic)] IAsyncCollector<BrokeredMessage> outputTopic,
ILogger log)
{
var thing = msg.GetBody<Thing>();
try {
var apiClient = new ApiClient();
@alexjamesbrown
alexjamesbrown / ServiceBusTriggerExample.cs
Created Feb 23, 2019
Example of ServiceBusTrigger function runtime
View ServiceBusTriggerExample.cs
var message = ReceiveMessageFromTopic();
try {
//run the code within your function, passing the message as a parameter
RunFunctionCode(message);
}
catch() {
message.Abandon();
}
message.Complete();
@alexjamesbrown
alexjamesbrown / TopicProcessorDeadletter.cs
Created Feb 23, 2019
Try deadletter message on exception
View TopicProcessorDeadletter.cs
[FunctionName("TopicProcessor")]
public static async Task Run(
[ServiceBusTrigger("%topic-name%", "%subscription-name%", AccessRights.Manage, Connection = "connection")] BrokeredMessage msg,
ILogger log)
{
var thing = msg.GetBody<Thing>();
var apiClient = new ApiClient();
try {
await apiClient.PostAsync(thing);
}
@alexjamesbrown
alexjamesbrown / TopicProcessor.cs
Last active Feb 23, 2019
Simple ServiceBusTrigger Function
View TopicProcessor.cs
[FunctionName("TopicProcessor")]
public static async Task Run(
[ServiceBusTrigger("%topic-name%", "%subscription-name%", AccessRights.Manage, Connection = "connection")] BrokeredMessage msg,
ILogger log)
{
var thing = msg.GetBody<Thing>();
var apiClient = new ApiClient();
await apiClient.PostAsync(thing);
}
View CustomerControllerTests.cs
//Arrange
var mockCustomerService = new Mock();
var customerController = new CustomerController(mockCustomerService.Object);
Customer customerServiceSaveArg = null;
mockCustomerService
.Setup(x => x.Save(It.IsAny()))
.Returns(1)
.Callback(c => customerServiceSaveArg = c);
View CustomerController.cs
var customer = new Customer();
customer.FirstName = firstName;
customer.LastName = firstName; //uh oh!
View CustomerControllerTests.cs
//Arrange
var mockCustomerService = new Mock();
var customerController = new CustomerController(mock.Object);
mockCustomerService.Setup(x=> x.Save(It.IsAny())
.Returns(1);
//Act
customerController.Post("Alex", "Brown");
View ICustomerService.cs
public interface ICustomerService
{
int Save(Customer customer);
}
View CustomerController.cs
public class CustomerController : Controller
{
private ICustomerService _customerService;
public CustomerController(ICustomerService customerService)
{
_customerService = customerService;
}
public IActionResult Post(string firstName, string lastName)
You can’t perform that action at this time.