Skip to main content

Job Interview Technical Test Preparation

· 2 min read
Mark Burton
Software Engineer & Technical Writer

docs.microsoft.com Apply to a controller action by specifying it in the signature public IActionResult EncodedName([ModelBinder(typeof(Base64StringBinder))] string name). Apply to a model using [ModelBinder(BinderType = typeof(AuthorEntityBinder))] and register in startup.cs

public void ConfigureServices(IServiceCollection services)  \\\{  services.AddMvc(options =>  \{  Insert at the top so this gets used before default binder  options.ModelBinderProviders.Insert(0, new AuthorEntityBinderProvider());  \\});  }
``` using a [model binder provider](https:/github.comaspnetDocstreemasteraspnetcoremvcadvancedcustom-model-bindingsampleCustomModelBindingSample) ``` csharp
public class AuthorEntityBinderProvider : IModelBinderProvider \\\{ if (context.Metadata.ModelType == typeof(Author)) \{ return new BinderTypeModelBinder(typeof(AuthorEntityBinder)); \\} return null; }
``` ## Decode base64 string
``` csharp string decodedJson = Encoding.UTF8.GetString(Convert.FromBase64String(value));

Deserialise

json convert

10 //  "Name": "Apple",
11 // "ExpiryDate": "2008-12-28T00:00:00",
12 // "Price": 3.99,
13 // "Sizes": [
14 // "Small",
15 // "Medium",
16 // "Large"
17 // ]
18 /\}
19
20 Product deserializedProduct = JsonConvert.DeserializeObject<Product />(output);

without netwonsoft csharp [DataContract] public class Product \\\{ [DataMember] public string Name \{ get; set; \\} [DataMember] public DateTime ExpiryDate \\{ get; set; \} } public static string WriteFromObject() \\{ Product user = new Product("Bob", DateTime.Now); MemoryStream ms = new MemoryStream(); Serializer the User object to the stream. DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Product)); ser.WriteObject(ms, product); byte[] json = ms.ToArray(); ms.Close(); return Encoding.UTF8.GetString(json, 0, json.Length); \} public static User ReadToObject(string json) \\{ Product deserializedProduct = new Product(); MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(json)); DataContractJsonSerializer ser = new DataContractJsonSerializer(deserializedUser.GetType()); deserializedUser = ser.ReadObject(ms) as Product; \} ##As a action filter decorate the controller action with [DecodingFilter]

```  #CQRS
[Martin Fowler - Command Query Responsibility Segregation](https:/www.martinfowler.comblikiCQRS.html) #Message queues ##AMQP
[Azure Service Bus .NET Standard client library ](https:/www.nuget.orgpackagesMicrosoft.Azure.ServiceBus)
[Using Service Bus from .NET with AMQP 1.0](https:/docs.microsoft.comen-usazureservice-bus-messagingservice-bus-amqp-dotnet) Void - Action<string /> prints = x => \\{ Debug.WriteLine(x); \}; Returns - Func&lt;int, int, int&gt; add = (x, y) => \\{ return x + y; \};

NUnit 3 Tests Are Not Showing In Visual Studio Test Explorer

· One min read
Mark Burton
Software Engineer & Technical Writer

![](/img/Empty Test%20Explorer.png)

The message suggests that simply building the solution will fix this and the tests will appear in Test Explorer. Regularly that has not been the outcome for me, the Test Explorer window remaining resolutely empty.

To fix this it is necessary to open Tools ->Extensions and Updates...

![](/img/Tools Extensions%20and%20Updates%20Menu.png)

Search for NUnit to find the NUnit 3 Test Adapter ![](/img/Tools Extensions%20and%20Updates.png) Click enable and restart Visual Studio, the tests now show correctly.

Running ASP.NET Core on a RaspberryPi 2 with Nginx

· One min read
Mark Burton
Software Engineer & Technical Writer

Failed to load ▒▒▒, error: libunwind.so.8: cannot open shared object file: No such file or directory Failed to bind to CoreCLR at /varwwwPublishOutputlibcoreclr.so'

`chmod 744?`  # Tell Kestrel to listen  If you are running headless you will need Kestrel to be listening for external requests to confirm the app is running, this can be done using the `ASPNETCORE_URLS environment variable`  ```perl  ASPNETCORE_URLS="http:/*:5000" dotnet Your.App.dll
``` # Create the service file
add a symlink for dotnet to limit the changes to the service file
```perl
sudo ln -s /optdotnetdotnet /usrbindotnet
``` # Configuring SSL
Rather than building nginx from source to get SSL I used nginx-core.

Setting up a Raspberry Pi NGINX PHP MySQL LEMP Stack

· 2 min read
Mark Burton
Software Engineer & Technical Writer
sudo apt-get install php-fpm

Then check the version ```PERL $ php -v

You should see something like this
```PERL
PHP 7.0.16-1~bpo8+1 (cli) (built: Feb 18 2017 02:34:09) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies with Zend OPcache v7.0.16-1~bpo8+1, Copyright (c) 1999-2017, by Zend Technologies
``` Then use these instructions to [setup PHP with Nginx](https:/www.digitalocean.comcommunitytutorialshow-to-install-linux-nginx-mysql-php-lemp-stack-in-ubuntu-16-04) Make sure to enable PHP in the Nginx config file, and ensure it is pointing to the correct location, for me that was
```PERL location ~ \.php$ \\\{ include snippetsfastcgi-php.conf; # # # With php5-cgi alone: # fastcgi_pass 127.0.0.1:9000; # # With php5-fpm: fastcgi_pass unix:varrunphpphp7.0-fpm.sock; \\}
``` restart Nginx to pick up the new configuration

sudo nginx -s reload

Test it with a simple php page using `&lt;?php phpinfo(); ?&gt;`  In order to serve extensionless html pages, update the try_files in the location block when setting up the sites-available server blocks config  ```PERL
location \\{ try_files $uri $uri.html $uri/ =404; \}
``` Install MySQL by following this tutorial again by [Ste Wright - Install MySQL Server on you Respberry Pi](https:/www.stewright.me201604install-mysql-server-raspberry-pi)
You should now have a working nginx server running PHP scripts, next time I will setup piwik so you can monitor the traffic to your website.