<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Andre Carstens</title>
    <description>The latest articles on DEV Community by Andre Carstens (@silkstream).</description>
    <link>https://dev.to/silkstream</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F981782%2F833453c3-76d6-4bd0-9245-ead1d2cd8d9b.jpeg</url>
      <title>DEV Community: Andre Carstens</title>
      <link>https://dev.to/silkstream</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/silkstream"/>
    <language>en</language>
    <item>
      <title>Create npm api project with nest</title>
      <dc:creator>Andre Carstens</dc:creator>
      <pubDate>Fri, 21 Apr 2023 16:02:53 +0000</pubDate>
      <link>https://dev.to/silkstream/create-npm-api-project-with-nest-1ob6</link>
      <guid>https://dev.to/silkstream/create-npm-api-project-with-nest-1ob6</guid>
      <description>&lt;p&gt;To build a new backend api that you can host in AWS Lambda or Azure app services, you can start with a blank node project.  You should just install nest -  npm -install nest&lt;/p&gt;

&lt;p&gt;When nest is installed, call the cli and it will scaffold a project for you.&lt;/p&gt;

&lt;p&gt;npx @nest/cli new project-name&lt;/p&gt;

&lt;p&gt;nest will create the src folder for you, it will setup a controller, a module, a test and a service. It will also create main.js and assign port 3000 as your default.  You can access the app on port 3000 immediately.&lt;/p&gt;

&lt;p&gt;Adding swagger&lt;/p&gt;

&lt;p&gt;install swagger from the terminal&lt;br&gt;
 npm install --save @nestjs/swagger&lt;/p&gt;

&lt;p&gt;in main.js, import swagger&lt;br&gt;
import { DocumentBuilder,SwaggerModule } from '@nestjs/swagger';&lt;/p&gt;

&lt;p&gt;Then you setup swagger details using options and then render it to /api using app as a parameter.&lt;/p&gt;

&lt;p&gt;const options = new DocumentBuilder()&lt;br&gt;
    .setTitle('My API')&lt;br&gt;
    .setDescription('My API description')&lt;br&gt;
    .setVersion('1.0')&lt;br&gt;
    .build();&lt;/p&gt;

&lt;p&gt;const document =SwaggerModule.createDocument(app,options);&lt;br&gt;
  SwaggerModule.setup('api',app,document);&lt;/p&gt;

</description>
      <category>npm</category>
      <category>api</category>
      <category>nestjs</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How to Moq ILogger for .net core unit test</title>
      <dc:creator>Andre Carstens</dc:creator>
      <pubDate>Tue, 14 Mar 2023 10:21:33 +0000</pubDate>
      <link>https://dev.to/silkstream/how-to-moq-ilogger-for-net-core-unit-test-31c1</link>
      <guid>https://dev.to/silkstream/how-to-moq-ilogger-for-net-core-unit-test-31c1</guid>
      <description>&lt;p&gt;Using Moq, you can create custom implemenation of your service layers.  But what about the standard items we inject into classes such as logging or configuration.&lt;/p&gt;

&lt;p&gt;To mock an instance of Microsoft.Extensions.Logging so you can pass it to your underlying class, you create an Mock of ILogger and inject it.&lt;/p&gt;

&lt;p&gt;var logger = Mock.Of&amp;gt;();&lt;br&gt;
var xXXXProvider = new XXXXProvider(httpClient,logger,null);&lt;/p&gt;

&lt;p&gt;Where the XXXXProvider class has _logger injected into it and you cannot just mock it up.&lt;/p&gt;

</description>
      <category>csharp</category>
      <category>testing</category>
      <category>moq</category>
    </item>
    <item>
      <title>Asp.Net core SPA proxy wont start</title>
      <dc:creator>Andre Carstens</dc:creator>
      <pubDate>Wed, 08 Feb 2023 15:04:21 +0000</pubDate>
      <link>https://dev.to/silkstream/aspnet-core-spa-proxy-wont-start-14d8</link>
      <guid>https://dev.to/silkstream/aspnet-core-spa-proxy-wont-start-14d8</guid>
      <description>&lt;p&gt;When I was trying to start an existing .net core 6 project that has a React SPA embedded in it, I was getting an error that the proxy server was not responding.  I spent a lot of time trying to find out where the proxy port is declared, people said its in the package.json file or in launch.settings.  I didnt find the port, but I did find out that the proxy spa feature of .net core looks for an avaialble port to forward to, so it isnt from a setting file.  &lt;/p&gt;

&lt;p&gt;Anyway, even after finding this out, it made no difference, the SPA app wouldnt start.  I tried changing the startup.cs settings &lt;br&gt;
for the SPA.  &lt;/p&gt;

&lt;p&gt;if (env.IsDevelopment())&lt;br&gt;
                               spa.UseProxyToSpaDevelopmentServer("&lt;a href="http://localhost:xxx%22"&gt;http://localhost:xxx"&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;}&lt;br&gt;
I went from using spa.UseReactDevelopmentServer to spa.UseProxyToSpaDevelopmentServer("&lt;a href="http://localhost:"&gt;http://localhost:&lt;/a&gt;"). It didnt help. &lt;/p&gt;

&lt;p&gt;Eventually, I tried using a cmd line in the Clientapp\ folder to get npm to start the app.  &lt;/p&gt;

&lt;p&gt;`npm start&lt;/p&gt;

&lt;p&gt;npm threw an error ERR_OSSL_EVP_UNSUPPORTED.`&lt;/p&gt;

&lt;p&gt;This was related to an update made to node that moved them from OpenSSL 1.x to OpenSSL 3.x&lt;/p&gt;

&lt;p&gt;Eventually, I added the script below to the &lt;strong&gt;package&lt;/strong&gt;.json, and the project finally started working again.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   "start": "rimraf ./build &amp;amp;&amp;amp; react-scripts --openssl-legacy-provider start",

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>csharp</category>
      <category>react</category>
      <category>webdev</category>
    </item>
    <item>
      <title>C# arrays using Distinct</title>
      <dc:creator>Andre Carstens</dc:creator>
      <pubDate>Fri, 03 Feb 2023 09:55:11 +0000</pubDate>
      <link>https://dev.to/silkstream/c-arrays-using-distinct-1hae</link>
      <guid>https://dev.to/silkstream/c-arrays-using-distinct-1hae</guid>
      <description>&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int[] nums = new int[] { 1, 4, 5, 2, 3, 5, 6 };
//unique values
var unique = nums.Distinct();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There is a array of integers as an example above. The Distinct() command will shorten the integer array by removing any duplicate values and returning a shortened array. The duplicate value (5) will be removed and the resulting array will be {1, 4, 2, 3, 5, 6}&lt;/p&gt;

&lt;p&gt;Note: The array will not be sorted yet, only the duplicate values removed. To sort the array, you can chain a call to OrderBy() at the end of Distinct().&lt;/p&gt;

&lt;p&gt;Question:&lt;br&gt;
Can you specify which values in an integer array, you want to apply Distinct to?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var selectedDistinct = nums.Where(x =&amp;gt; x &amp;gt;= 3).Select(x =&amp;gt; x).Distinct();

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The code above will shorten nums to only values that are greater or equal to 3 and then apply Distinct() to that shortened result.&lt;/p&gt;

</description>
      <category>blockchain</category>
      <category>ethereum</category>
      <category>web3</category>
      <category>crypto</category>
    </item>
    <item>
      <title>C# arrays using Average</title>
      <dc:creator>Andre Carstens</dc:creator>
      <pubDate>Fri, 03 Feb 2023 08:56:32 +0000</pubDate>
      <link>https://dev.to/silkstream/c-arrays-using-average-1297</link>
      <guid>https://dev.to/silkstream/c-arrays-using-average-1297</guid>
      <description>&lt;p&gt;Average is used to get the average of all values within an array.&lt;br&gt;
For example, you can get the average value of all the items in the integer array by using average&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int[] nums = new int[] { 1, 4, 5, 2, 3, 5, 6 };

//normal array average
var average = nums.Average();

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will return a double with the value of: 3.7142857142857144&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Question:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Can you use a select to filter the items used in average of an array?&lt;br&gt;
Lets try&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var averageSelected = nums.Where(x =&amp;gt; x &amp;gt;= 2).Select(x =&amp;gt; x).Average();

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the code above, the integer array &lt;strong&gt;nums&lt;/strong&gt; is first trimmed using the .&lt;strong&gt;Where&lt;/strong&gt; clause, the .&lt;strong&gt;Select&lt;/strong&gt; clause will choose the value of the array and the .&lt;strong&gt;Average&lt;/strong&gt;() will return the average of the selected values that matched the .&lt;strong&gt;Where&lt;/strong&gt; statement.&lt;/p&gt;

</description>
      <category>cryptocurrency</category>
      <category>blockchain</category>
      <category>ethereum</category>
      <category>web3</category>
    </item>
  </channel>
</rss>
