Pages

Monday, August 28, 2017

Haz tu propio C# snippet para generar Unit Tests

El objetivo de los 'snippets' es evitarnos el tener que teclear lo mismo cada vez, y si tu estas actualmente haciendo Unit tests, no estas ya cansado de escribir  arrange, act y assert ?

Si eres como yo, entonce la respuesta es SI. y no solo eso sino que hay otras areas en las que podemos mejorar nuestra experiencia de programacion. Asi que toma esto como un ejemplo introductorio a los snippets, y creemos uno para nuestro unit test.

Lo que queremos lograr es que con un par de teclas podamos obtener esto:


Y que el cursor se enfoque en la parte WhatAreWeTesting (que estamos testeando)  de el nombre de la funcion para que podamos cambiarla, luego con un TAB para a la parte 'ExpectedResult' (Resultado esperado) y luego despues de un ENTER final que el cursor vaya a la linea de arrange para poder empezar a escribir nuestro codigo.

Un snippet es solo un archivo XML que tiene una estructura especifica, lo puedes crear en cualquier editor de texto, en este caso yo usare el Visual Studio Code .

Asi que abrimos cualquier Folder en VS Code:


y añadimos un nuevo archivo XML:


Monday, July 31, 2017

Build your own C# search Engine using Azure Search

Azure Search is a Cloud service provided by Azure to enable an indexed search over any type of data you can create, It has filters abilities based on Lucene syntax and its has many of the features you would expect from Solr or ElasticSearch.

I will show you how to configure your service, and hot to get data in and perform searches over that data. We will skip the UI part, which you can build with your favorite tool. But I will show you the C# code to talk to the Azure Search Service.


Part 1 - Setup your Azure Search
For this you need an Azure Account, You can apply for a free one if you have a credit card to register. Once you have the Azure Account enter the azure portal:


Once there click the '+' sign to add a new service 
- Then on the search box  type: 'azure Search' and 'Enter'. 
- Then clic the 'Create' button on the lower part of the azure search tab.



Next lets put a name to our service this service can have more than one Index (or type of data) so lets make a general name for it. Select your subscription and click on 'Create'


Now you have to wait until the service its created. Once the service is created you will see it listed on your dashboard. enter the service by clicking on its name.

Friday, July 7, 2017

Make your own C# snippet to stub out Unit Tests

The point of snippets is to avoid repetitive typing and if you are currently creating unit tests, aren't you tired of writing arrange,act and assert ?

If you are like me, then the answer is Yes. And not only that but there are other areas that we can use to improve our coding experience. So take this as an introductory example to snippets, and lets create our unit test one.

What we wan to achieve is that after a couple of keystrokes we get this:


And the focus on the WhatAreAreTesting part of the function name so we can change it then one TAB press for ExpectedResult and then a final ENTER to get us to the arrange line so we can start coding.

A code snippet is just an XML file with an especific structure, you can create it in any text editor you want, in this case I will use Visual Sutio Code .

So lets open any Folder on VS Code:


then Add a new XML File:


Wednesday, June 21, 2017

Calling Azure functions from C# with security enabled

Azure functions allow us to run server-less code. We will see how, and in the interest of this sample we will simulate the problem of having to run some code when a payment is done, the code to do it will be on azure and the call would come from our C# payment app.
So to ensure we don't get unauthorized calls, we will activate security on our Azure function and I will show you how to make a secure call and review the azure logs for those calls. So lets begin.

Part 1 - Azure function

In order to create our azure function lets head to:
portal.azure.com
and enter your credentials, if you dont have an azure account, you can get a trial account for free.

Once inside the portal click on the new button '+' then on 'Compute' and on the FuctionApp option.



Then we will set the name of our new function as  ‘licensefunctions’ and click on ‘Create’ (If the name is not available just choose one you see fit)


Tuesday, June 20, 2017

Usar Azure functions en C# con seguridad Activada

Azure functions nos permiten correr codigo 'sin-servidor'. Veremos como, y para este ejemplo simularemos el problema de tener que correr codigo cuando un pago es hecho por un cliente, el cdigo para hacerlo esta en Azure y la llamada vendria de nuestra aplicacion de pago.
Asi que para asegurarnos de no recibir llamadas fraudulentas , vamos a activar la seguridad de nuestra Azure function y te mostrare como hacer una llamada segura y revisar el log de Azure de esas llamadas. Asi que, comencemos.

Parte 1 - Azure function

Para crear nuestra funcion azure dirigete a:
portal.azure.com
e ingresa tus credenciales, si no tienes una cuenta azure, puedes obtener una cuenta de prueba gratis.

Una vez dentro del porta; haz click en el botón '+' y luego en 'Compute' y en la opción FuctionApp.



Ahora pondremos el nombre de nuestra nueva función  ‘licensefunctions’ y hacemos click en ‘Create’ (Si el nombre no esta disponible, escoge uno que veas conveniente)