<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/"><channel><title>2017-07 on Funky Si's Test</title><link>https://blog-test.funkysi1701.com/2017/07/</link><description>Recent content in 2017-07 on Funky Si's Test</description><generator>Hugo -- gohugo.io</generator><language>en-gb</language><managingEditor>funkysi1701@gmail.com (Simon Foster)</managingEditor><webMaster>funkysi1701@gmail.com (Simon Foster)</webMaster><lastBuildDate>Mon, 31 Jul 2017 20:00:45 +0000</lastBuildDate><atom:link href="https://blog-test.funkysi1701.com/2017/07/index.xml" rel="self" type="application/rss+xml"/><item><title>Creating NuGet packages with VSTS</title><link>https://blog-test.funkysi1701.com/posts/2017/creating-nuget-packages/</link><author>funkysi1701@gmail.com (funkysi1701)</author><pubDate>Mon, 31 Jul 2017 20:00:45 +0000</pubDate><guid>https://blog-test.funkysi1701.com/posts/2017/creating-nuget-packages/</guid><category term="NuGet">NuGet</category><category term="C-Sharp">C-Sharp</category><category term="VisualStudio">VisualStudio</category><description>&lt;p&gt;For a while I have found myself writing the same bits of code for different web projects. This annoys me as it goes against the DRY principle (don’t repeat yourself).&lt;/p&gt;
&lt;p&gt;
&lt;img class="img-fluid" alt="Nuget" src="https://blog-test.funkysi1701.com/images/2017/nuget.png" loading="lazy"
width="444" height="135"
/&gt;
One possible solution is to write your own nuget packages. You can then add this piece of code to any project you work on.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://www.nuget.org/" target="_blank" rel="noopener noreferrer"&gt;nuget.org&lt;/a&gt;
is the public nuget feed where any developer can download nuget packages. You could publish your nuget package here, but your might want to restrict access so better to create a private nuget feed.&lt;/p&gt;
&lt;p&gt;Lets look at how we create a nuget feed in Visual Studio. First thing you need to do is install the &lt;a href="https://marketplace.visualstudio.com/items?itemName=ms.feed" target="_blank" rel="noopener noreferrer"&gt;Package Management&lt;/a&gt;
extension to Visual Studio Team Services (its free for less than 5 users), this will add a packages section under the build menu.&lt;/p&gt;
&lt;p&gt;Before you can start using this new feature you need to add a Package Management License in the users hub.&lt;/p&gt;
&lt;p&gt;Once that is done you can create a feed. You need to give your feed a name, decide if only members of the current project or everyone in your account should have access to read and contribute to.&lt;/p&gt;
&lt;p&gt;Now you have a feed you could use the nuget package command to create a nupkg file and then nuget push command to add it to your feed. A better way is to get Visual Studio Team Services to do all the hard work.&lt;/p&gt;
&lt;p&gt;Create a new project in Visual Studio Team Service to house your nuget package. In the build section add an empty build definition. Choose a build agent, I am using the Hosted VS2017. Then add the following steps nuget restore, Visual Studio Build, nuget pack and nuget push.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;nuget restore – this step is only needed if your code depends on other packages. If it depends on other packages that are only in your feed you must specify your feed in the feeds and authentication section.&lt;/li&gt;
&lt;li&gt;Visual Studio Build – this builds your code like you would in Visual Studio. The only config I made to this step was to specify Release in configuration.&lt;/li&gt;
&lt;li&gt;nuget pack – this creates the nupkg file from your built project. In configuration to package specify the same as you specified in the previous step (in my case Release)&lt;/li&gt;
&lt;li&gt;nuget push – this publishes to your feed, so of course you need to specify your feed.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;One last thing to configure is to enable the continuous integration option in triggers. This means whenever you push code all these steps will run and you have a new version of your nuget package.&lt;/p&gt;
&lt;p&gt;In Visual Studio you need to create a *.nuspec file, this contains all the meta data about your nuget package. Let look at an example.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-xml" data-lang="xml"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;&amp;lt;?xml version=&amp;#34;1.0&amp;#34;?&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#f92672"&gt;&amp;lt;package&lt;/span&gt; &lt;span style="color:#f92672"&gt;&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#f92672"&gt;&amp;lt;metadata&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#f92672"&gt;&amp;lt;id&amp;gt;&lt;/span&gt;$id$&lt;span style="color:#f92672"&gt;&amp;lt;/id&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#f92672"&gt;&amp;lt;version&amp;gt;&lt;/span&gt;1.0.2&lt;span style="color:#f92672"&gt;&amp;lt;/version&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#f92672"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Nuget&lt;span style="color:#f92672"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#f92672"&gt;&amp;lt;authors&amp;gt;&lt;/span&gt;Simon Foster&lt;span style="color:#f92672"&gt;&amp;lt;/authors&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#f92672"&gt;&amp;lt;owners&amp;gt;&lt;/span&gt;Simon Foster&lt;span style="color:#f92672"&gt;&amp;lt;/owners&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#f92672"&gt;&amp;lt;requireLicenseAcceptance&amp;gt;&lt;/span&gt;false&lt;span style="color:#f92672"&gt;&amp;lt;/requireLicenseAcceptance&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#f92672"&gt;&amp;lt;description&amp;gt;&lt;/span&gt;An example of a nuget package.&lt;span style="color:#f92672"&gt;&amp;lt;/description&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#f92672"&gt;&amp;lt;releaseNotes&amp;gt;&lt;/span&gt;Release Notes&lt;span style="color:#f92672"&gt;&amp;lt;/releaseNotes&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#f92672"&gt;&amp;lt;copyright&amp;gt;&lt;/span&gt;Copyright 2017&lt;span style="color:#f92672"&gt;&amp;lt;/copyright&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#f92672"&gt;&amp;lt;projectUrl&amp;gt;&lt;/span&gt;https://[yourVSaccount].visualstudio.com/nuget/&lt;span style="color:#f92672"&gt;&amp;lt;/projectUrl&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#f92672"&gt;&amp;lt;/metadata&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#f92672"&gt;&amp;lt;/package&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;One last thing to mention is version numbers. You can either change the version number in your *.nuspec file everytime you push changes. This will create stable packages like 1.0, 1.1, 1.2 etc&lt;/p&gt;
&lt;p&gt;However you can use the automatic version number setting in the nuget pack build step. However I have found this only ever creates pre-release packages and I haven’t found a way to upgrade a package from pre-release to stable.&lt;/p&gt;
&lt;p&gt;This is a really neat way to reuse your code in multiple projects. I have only been looking at this for a few days and I have already extracted code to do with emails, creating excel downloads and database related methods. I suspect that doing this will also have a side benefit of forcing me to create code with fewer dependencies so more code can be turned into a nuget package.&lt;/p&gt;</description></item><item><title>Async and Await</title><link>https://blog-test.funkysi1701.com/posts/2017/async-and-await/</link><author>funkysi1701@gmail.com (funkysi1701)</author><pubDate>Mon, 24 Jul 2017 20:00:45 +0000</pubDate><guid>https://blog-test.funkysi1701.com/posts/2017/async-and-await/</guid><category term="Async">Async</category><category term="Await">Await</category><category term="C-Sharp">C-Sharp</category><description>&lt;p&gt;For a while the Async and Await commands in c# have confused me.&lt;/p&gt;
&lt;p&gt;Like most things the best way to learn about something is to use it in a real world example. I am currently adding an email alert feature to a website. This is an ideal example of something that would benefit from Asynchronous programming. There is no need for the webpage to wait to send 1000s of emails, lets just send a call to get started and allow the browser to carry on as normal.&lt;/p&gt;
&lt;p&gt;This is my first try at using async and await so feel free to suggest best practises in the comments.&lt;/p&gt;
&lt;p&gt;Lets start with a Send method in my EmailController.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-csharp" data-lang="csharp"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;public&lt;/span&gt; ActionResult Send(&lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; id, &lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; pageId, &lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; userID)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;{
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;if&lt;/span&gt; (!Authorize.checkPageIsAuthorised(userID, (Authorize.PageIds)pageId))
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;return&lt;/span&gt; Redirect(&lt;span style="color:#e6db74"&gt;&amp;#34;/login&amp;#34;&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;else&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; Task&amp;lt;&lt;span style="color:#66d9ef"&gt;string&lt;/span&gt;&amp;gt; t = SendNotifications(id,userID);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;return&lt;/span&gt; Redirect(Request.UrlReferrer.ToString());
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This simply checks to see if you have permission to the page. If not redirects to the login page otherwise it makes a method call and redirects back to the page it came from.&lt;/p&gt;
&lt;p&gt;Lets have a look at that method call in more detail.&lt;/p&gt;
&lt;p&gt;Task&lt;string&gt; t = SendNotification(id, userid);&lt;/p&gt;
&lt;p&gt;SendNotification doesn’t return a normal string it returns a Task&lt;string&gt;, so lets look at how we are creating this.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-csharp" data-lang="csharp"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;public&lt;/span&gt; &lt;span style="color:#66d9ef"&gt;async&lt;/span&gt; Task&amp;lt;&lt;span style="color:#66d9ef"&gt;string&lt;/span&gt;&amp;gt; SendNotifications(&lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; id,&lt;span style="color:#66d9ef"&gt;string&lt;/span&gt; type,&lt;span style="color:#66d9ef"&gt;int&lt;/span&gt; userid)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;{
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#75715e"&gt;//logic ommitted&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;await&lt;/span&gt; ef.SendEmail(model, emailHtmlBody);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;return&lt;/span&gt; &lt;span style="color:#e6db74"&gt;&amp;#34;OK&amp;#34;&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The return type is set to Task but it has the aysnc keyword appended to it. It also makes a call with the await keyword.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-csharp" data-lang="csharp"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;public&lt;/span&gt; &lt;span style="color:#66d9ef"&gt;async&lt;/span&gt; Task SendEmail(EmailModel model,&lt;span style="color:#66d9ef"&gt;string&lt;/span&gt; emailHtmlBody)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;{
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#75715e"&gt;//logic removed&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;await&lt;/span&gt; smtp.SendMailAsync(message);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;So that is it. My first bit of code that uses Async and Await. My controller calls a method asynchronously which then calls another method asynchronously which sends emails asynchronously.&lt;/p&gt;
&lt;p&gt;Async – This enables the Await keyword to be used in the method&lt;/p&gt;
&lt;p&gt;Await – This is where things get asynchronous. The await keyword allows the code to wait asynchronously for the long running code to complete.&lt;/p&gt;</description></item><item><title>How good is your SSL?</title><link>https://blog-test.funkysi1701.com/posts/2017/how-good-is-your-ssl/</link><author>funkysi1701@gmail.com (funkysi1701)</author><pubDate>Mon, 17 Jul 2017 20:00:45 +0000</pubDate><guid>https://blog-test.funkysi1701.com/posts/2017/how-good-is-your-ssl/</guid><category term="SSL">SSL</category><category term="Security">Security</category><description>&lt;p&gt;
&lt;img class="img-fluid" alt="Troy Hunt SSL expert" src="https://blog-test.funkysi1701.com/images/2017/Troy-Hunt-Profile-Photo.jpg" loading="lazy"
width="800" height="800"
/&gt;
&lt;/p&gt;
&lt;p&gt;I recently watched Troy Hunt’s &lt;a href="https://www.pluralsight.com/courses/https-every-developer-must-know" target="_blank" rel="noopener noreferrer"&gt;What Every Developer Must Know about HTTPS&lt;/a&gt;
course on Pluralsight. Its very good and really make you think about SSL certificates and how to correctly implement them.&lt;/p&gt;
&lt;p&gt;One thing in particular Troy mentions is the website &lt;a href="https://www.ssllabs.com/ssltest/index.html" target="_blank" rel="noopener noreferrer"&gt;SSL Labs&lt;/a&gt;
. This website allows you to test a websites implementation of SSL. A grade of A to F is assigned with A being the best and F being the worst.&lt;/p&gt;
&lt;p&gt;Troy Hunt has a &lt;a href="https://www.troyhunt.com/do-you-really-want-bank-grade-security/" target="_blank" rel="noopener noreferrer"&gt;blog&lt;/a&gt;
post where he discusses how Australian Banks score. Lets look at a few UK banks.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;strong&gt;Bank&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;SSL Certificate&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Grade&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Home Page Under SSL&lt;/strong&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;HSBC&lt;/td&gt;
&lt;td&gt;&lt;a href="https://www.hsbc.co.uk" target="_blank" rel="noopener noreferrer"&gt;www.hsbc.co.uk&lt;/a&gt;
&lt;/td&gt;
&lt;td&gt;B&lt;/td&gt;
&lt;td&gt;Y&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Nationwide&lt;/td&gt;
&lt;td&gt;onlinebanking.nationwide.co.uk&lt;/td&gt;
&lt;td&gt;C&lt;/td&gt;
&lt;td&gt;N&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;NatWest&lt;/td&gt;
&lt;td&gt;&lt;a href="https://www.nwolb.com" target="_blank" rel="noopener noreferrer"&gt;www.nwolb.com&lt;/a&gt;
&lt;/td&gt;
&lt;td&gt;C&lt;/td&gt;
&lt;td&gt;N&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Barclaycard&lt;/td&gt;
&lt;td&gt;&lt;a href="https://www.barclaycard.co.uk" target="_blank" rel="noopener noreferrer"&gt;www.barclaycard.co.uk&lt;/a&gt;
&lt;/td&gt;
&lt;td&gt;A-&lt;/td&gt;
&lt;td&gt;Y&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Barclays&lt;/td&gt;
&lt;td&gt;bank.barclays.co.uk&lt;/td&gt;
&lt;td&gt;A-&lt;/td&gt;
&lt;td&gt;N&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Lloyds Bank&lt;/td&gt;
&lt;td&gt;&lt;a href="https://www.lloydsbank.com" target="_blank" rel="noopener noreferrer"&gt;www.lloydsbank.com&lt;/a&gt;
&lt;/td&gt;
&lt;td&gt;A&lt;/td&gt;
&lt;td&gt;N&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Royal Bank of Scotland&lt;/td&gt;
&lt;td&gt;&lt;a href="https://www.rbsdigital.com" target="_blank" rel="noopener noreferrer"&gt;www.rbsdigital.com&lt;/a&gt;
&lt;/td&gt;
&lt;td&gt;C&lt;/td&gt;
&lt;td&gt;N&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Standard Chartered&lt;/td&gt;
&lt;td&gt;&lt;a href="https://www.sc.com" target="_blank" rel="noopener noreferrer"&gt;www.sc.com&lt;/a&gt;
&lt;/td&gt;
&lt;td&gt;C&lt;/td&gt;
&lt;td&gt;Y&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Virgin Money&lt;/td&gt;
&lt;td&gt;uk.virginmoney.com&lt;/td&gt;
&lt;td&gt;A+&lt;/td&gt;
&lt;td&gt;Y&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Santander&lt;/td&gt;
&lt;td&gt;retail.santander.co.uk&lt;/td&gt;
&lt;td&gt;A-&lt;/td&gt;
&lt;td&gt;N&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;On the whole the ratings are all quite good with all being in the range A-C. However I have also indicated if they have SSL on the home page. Only 4 out 10 website listed above have the home page load under SSL.&lt;/p&gt;
&lt;p&gt;Why does this matter as long as the login is under SSL? Any page that loads over http is potentially at risk from a man in the middle attack. A fake malicious home page could contain links to any page and trick users into entering personal information.&lt;/p&gt;
&lt;p&gt;If you want to test a bank or other website not listed here. Go to &lt;a href="https://www.ssllabs.com/ssltest/index.html" target="_blank" rel="noopener noreferrer"&gt;https://www.ssllabs.com/ssltest/index.html&lt;/a&gt;
and type the address that is on the SSL certificate in to the search. The good news is that this site scores a A.&lt;/p&gt;
&lt;p&gt;Troy mentions that there is rapid growth in the adoption of SSL, there is also rapid growth in improving ratings. One of these banks went from a C to an A during the course of writing this blog.&lt;/p&gt;</description></item><item><title>Writing your first test</title><link>https://blog-test.funkysi1701.com/posts/2017/writing-your-first-test/</link><author>funkysi1701@gmail.com (funkysi1701)</author><pubDate>Mon, 10 Jul 2017 20:00:45 +0000</pubDate><guid>https://blog-test.funkysi1701.com/posts/2017/writing-your-first-test/</guid><category term="Act">Act</category><category term="Arrange">Arrange</category><category term="Assert">Assert</category><category term="Testing">Testing</category><description>&lt;p&gt;Whenever I write a new test I have to think how best to do it. Hopefully I can summarise a few tips here to help get started.&lt;/p&gt;
&lt;h2 id="arrange-act-assert"&gt;Arrange Act Assert&lt;a class="anchor ms-1" href="#arrange-act-assert" aria-label="Permalink: Arrange Act Assert"&gt;&lt;i class="fas fa-link" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;The first thing I think about when writing a test is Arrange, Act, Assert. Arrange, Act, Assert is a pattern for writing the tests.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Arrange&lt;/strong&gt; – This gets things in order ready to execute the test.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Act&lt;/strong&gt; – This executes the method you want to test.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Assert&lt;/strong&gt; – This compares the value produced in the Act step with a known value typically with a method similar to the following&lt;/p&gt;
&lt;p&gt;Assert.AreEqual(expected value, actual value)&lt;/p&gt;
&lt;p&gt;Say for example you wanted to test a method called ReturnsTrue() which does nothing but returns a value of true. This method is in a class called ReturnsTrueClass&lt;/p&gt;
&lt;p&gt;The Arrange step in this example would be.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-csharp" data-lang="csharp"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;ReturnsTrueClass t = &lt;span style="color:#66d9ef"&gt;new&lt;/span&gt; ReturnsTrueClass();
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The Act step in this example would be.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-csharp" data-lang="csharp"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;var&lt;/span&gt; result = t.ReturnTrue();
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The Assert step in this example would be.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-csharp" data-lang="csharp"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Assert.AreEqual(&lt;span style="color:#66d9ef"&gt;true&lt;/span&gt;, result);
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This is a stupidly simple example but hopefully you get the idea of how you can build all your tests with these three steps.&lt;/p&gt;
&lt;p&gt;Recently I saw a tweet complaining that someone has mixed up expected and actual in the Assert statement.&lt;/p&gt;
&lt;blockquote class="twitter-tweet"&gt;&lt;p lang="en" dir="ltr"&gt;There is a minor but special hell reserved for those who mix up the expected and actual parameters in Assert.Equals&lt;/p&gt;&amp;mdash; Keith Williams (@zogface) &lt;a href="https://twitter.com/zogface/status/882737770095149056?ref_src=twsrc%5Etfw"&gt;July 5, 2017&lt;/a&gt;&lt;/blockquote&gt; &lt;script async src="https://platform.twitter.com/widgets.js" charset="utf-8"&gt;&lt;/script&gt;
&lt;p&gt;At first glance this probably isn’t the worst mistake to make as if your tests are all passing actual and expected are the same.&lt;/p&gt;
&lt;p&gt;However tests will fail, that is the whole point of them, you can then fix bits of code. If you have mixed up actual and expected it adds extra time to debugging and figuring out what values are produced from your code and what you are expecting it to produce. It may be your test uses a mocking framework and somewhere in there, there is an issue, with mixed up expected/actual you may assume a problem in your code rather than the test.&lt;/p&gt;
&lt;p&gt;Also, how do you make such an error? When I type Assert.AreEquals() in Visual Studio, Visual Studio tells me what each parameter does, it takes a matter of seconds to do this, just by hovering over the code.&lt;/p&gt;
&lt;p&gt;One last tip to say about tests. Write your tests to test the behaviour of your application.&lt;/p&gt;</description></item><item><title>Uploading Files to AWS</title><link>https://blog-test.funkysi1701.com/posts/2017/uploading-files-to-aws/</link><author>funkysi1701@gmail.com (funkysi1701)</author><pubDate>Mon, 03 Jul 2017 20:00:45 +0000</pubDate><guid>https://blog-test.funkysi1701.com/posts/2017/uploading-files-to-aws/</guid><category term="AWS">AWS</category><category term="C-Sharp">C-Sharp</category><description>&lt;p&gt;I am a fan of Azure but today I have been looking at AWS. Specifically how to upload and download files.&lt;/p&gt;
&lt;p&gt;AWS S3 stores files in Buckets. I already had an AWS S3 account setup with a Bucket. I am going to assume you have got a bucket setup and concentrate on the code to get files in and out.&lt;/p&gt;
&lt;p&gt;First step is to use nuget to install the AWS packages. In nuget the packages you want are called AWSSDK.Core and AWSSDK.S3.&lt;/p&gt;
&lt;p&gt;The using statements you want to use are called Amazon.S3 and Amazon.S3.Transfer, not sure why this doesn’t match nuget, this difference caught me out a couple of times.&lt;/p&gt;
&lt;p&gt;Now to the code that uploads files&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-c#" data-lang="c#"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;AmazonS3Client AWSclient = &lt;span style="color:#66d9ef"&gt;new&lt;/span&gt; AmazonS3Client(accessKeyID, secretAccessKeyID, Amazon.RegionEndpoint.EUWest1);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;TransferUtility fileTransferUtility = &lt;span style="color:#66d9ef"&gt;new&lt;/span&gt; TransferUtility(AWSclient);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;using&lt;/span&gt; (FileStream streamWriter = &lt;span style="color:#66d9ef"&gt;new&lt;/span&gt; FileStream(path, FileMode.Open))
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;{
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; TransferUtilityUploadRequest fileTransferUtilityRequest = &lt;span style="color:#66d9ef"&gt;new&lt;/span&gt; TransferUtilityUploadRequest
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; BucketName = &lt;span style="color:#e6db74"&gt;&amp;#34;flawlessimages&amp;#34;&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; InputStream = streamWriter,
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; Key = fileName
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; };
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; fileTransferUtility.Upload(fileTransferUtilityRequest);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Lets break it down and look at what it does.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-c#" data-lang="c#"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;AmazonS3Client AWSclient = &lt;span style="color:#66d9ef"&gt;new&lt;/span&gt; AmazonS3Client(accessKeyID, secretAccessKeyID, Amazon.RegionEndpoint.EUWest1);
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This creates an instance of AmazonS3Client, we are passing the Access Key and Secret Access Key both of which can be found from your Amazon S3 account My Security Credentials section. Amazon.RegionEndpoint.EUWest1 specifies the amazon data centres that your bucket is located in.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-c#" data-lang="c#"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;TransferUtility fileTransferUtility = &lt;span style="color:#66d9ef"&gt;new&lt;/span&gt; TransferUtility(AWSclient);
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This creates an instance of TransfterUtility using the AmazonS3Client instance we created in the previous step.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-c#" data-lang="c#"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;using&lt;/span&gt; (FileStream streamWriter = &lt;span style="color:#66d9ef"&gt;new&lt;/span&gt; FileStream(path, FileMode.Open))
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;{
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This opens up a filestream from a files path and specifies that the file should be opened.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-c#" data-lang="c#"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;TransferUtilityUploadRequest fileTransferUtilityRequest = &lt;span style="color:#66d9ef"&gt;new&lt;/span&gt; TransferUtilityUploadRequest
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;{
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; BucketName = &lt;span style="color:#e6db74"&gt;&amp;#34;flawlessimages&amp;#34;&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; InputStream = streamWriter,
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; Key = fileName
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;};
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;fileTransferUtility.Upload(fileTransferUtilityRequest);
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This last step specifies which bucket to upload to, what input stream to upload and the Key to use. Key is just AWS way of referring to files, more commonly referred to as the filename.&lt;/p&gt;
&lt;p&gt;This is all you need to do to upload a file to your Bucket. The file will be located at &lt;a href="https://s3-eu-west-1.amazonaws.com/[bucketname]/[filename]" target="_blank" rel="noopener noreferrer"&gt;https://s3-eu-west-1.amazonaws.com/[bucketname]/[filename]&lt;/a&gt;
, however by default it will not be downloadable until you set Read permission to everyone, once you do that anyone who has the link will be able to download your file.&lt;/p&gt;
&lt;p&gt;This is the same permission level as any file you have on your webserver, however AWS has a better way.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-c#" data-lang="c#"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;using&lt;/span&gt; (s3Client = &lt;span style="color:#66d9ef"&gt;new&lt;/span&gt; AmazonS3Client(accessKeyID, secretAccessKeyID, Amazon.RegionEndpoint.USEast1))
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;{
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; GetPreSignedUrlRequest request1 = &lt;span style="color:#66d9ef"&gt;new&lt;/span&gt; GetPreSignedUrlRequest
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; BucketName = bucketName,
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; Key = filename,
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; Expires = DateTime.Now.AddMinutes(&lt;span style="color:#ae81ff"&gt;5&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; };
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; urlString = s3Client.GetPreSignedURL(request1);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Here we are generating a url to download the file, but we are specifying that it is only valid for 5 minutes. This means that if you share the url it will only work for 5 minutes, after that AWS will give an access denied message.&lt;/p&gt;
&lt;p&gt;This is much better security than you have on a typical web server, and easy to implement, every time a user clicks on a download link you generate a new presigned url and send the download to the browser, as long as this process doesn’t take longer than 5 minutes the user will never know.&lt;/p&gt;</description></item></channel></rss>