Category: .NET Core

Try Dot Net–again–part 32

I wanted to put my project on the .NET try – it is a wonderful tool that makes magic for .NET . However, I wanted to be in a docker container. I have open a issue here: https://github.com/dotnet/try/issues/590

It was resolved  – now I can specify the port

But the problem now it is that cannot run the program ( ok, I have not a simple program)

But – the idea is that is not released yet the final version

So I decide to let it go – and wait for the new official release.

Moral: if you do not have time, do not work with anything other than the release versions…

Infovalutar

And one hour passes...
(This is the result of 1 hour per day auto-challenge as a full cycle developer for an exchange rates application)
( You can see the sources at https://github.com/ignatandrei/InfoValutar/ )
NrPost 
1Start
2Reading NBR from internet
3Source control and build
4Badge and test
5CI and action
6Artifacts and dotnet try
7Docker with .NET Try
8ECB
9Intermezzo - Various implementations for programmers
10Intermezzo - similar code - options
11Plugin implementation
12GUI for console
13WebAPI
14Plugin in .NET Core 3
15Build and Versioning
16Add swagger
17Docker - first part
18Docker - second part
19Docker - build Azure
20Pipeline send to Docker Hub
21Play with Docker - online
22Run VSCode and Docker
23Deploy Azure
24VSCode see tests and powershell
25Code Coverage
26Database in Azure
27Sql In Memory or Azure
28Azure ConString, RSS
29Middleware for backward compatibility
30Identical Tables in EFCore
31Multiple Data in EFCore
32Dot net try again
33Start Azure Function
34Azure function - deploy
35Solving my problems
36IAsyncEnumerable transformed to IEnumerable and making Azure Functions works
37Azure functions - final
38Review of 37 hours
39Last Commit in AzureDevOps
40Create Angular WebSite
41Add static Angular to WebAPI .NET Core
42Docker for Angular
43Angular and CORS
44SSL , VSCode, Docker
45Routing in Angular
46RxJS for Routing
47RxJs Unsubscribe

Saving multiple data–part 31

I want to load the exchange rates from NBR and ECB and load at once .From here, the challenges of programming for a simple task like this:

  1. How we can display the errors ?
  2. What if the data exists already for this day and I cannot save into database, because it exists ?
  3. How to acknowledge what exists and what not , in one operation ?
  4. How to report success even if data exists ? Should we report number of records?
  5.  How we can perform async all that stuff and, however , report errors ?

If you know the answer to all that, I have a challenge for you: see the file at https://github.com/ignatandrei/InfoValutar/blob/master/InfoValutar/InfovalutarLoadAndSave/LoadAndSaveLastData.cs– and improve it.

Until then, I come with this simple code

 

public class ResultsLoadBankData
    {
        public string Bank { get; internal set; }
        public int NrRecords { get; internal set; }
        public bool HasSuccess { get; internal set; }
        public string ErrorMessage { get; internal set; }
    }

//in some class below
public async Task<ResultsLoadBankData[]> LoadAndSave()
        {
            
            
            var items= providers.Banks().Select(it =>
                new KeyValuePair<string, ResultsLoadBankData>(it,
                new ResultsLoadBankData()
                {
                    Bank = it,
                    ErrorMessage=null,
                    HasSuccess=true,
                    NrRecords=0
                })
             );
            var lst = new Dictionary<string, ResultsLoadBankData>(items);


            var rates = 
                providers.LoadExchange()
                .Select(it => it.GetActualRates())
                .ToArray();
            //TODO: how to load async all async enumerables?
            //TODO: how to report error if one fails?
            foreach (var rateAsync in rates)
            {
                
                await foreach(var rate in rateAsync)
                {
                    var item = lst[rate.Bank];
                    try
                    {
                        
                        if (await ret.Exists(rate))
                            continue;
                        var nr = await save.Save(rate);
                        item.NrRecords++;
                    }
                    catch(Exception ex)
                    {
                        //TODO:log
                        item.ErrorMessage = ex.Message;
                        item.HasSuccess = false;
                    }
                }
                
                
            }
            return lst.Values.ToArray();
        }

Infovalutar

And one hour passes...
(This is the result of 1 hour per day auto-challenge as a full cycle developer for an exchange rates application)
( You can see the sources at https://github.com/ignatandrei/InfoValutar/ )
NrPost 
1Start
2Reading NBR from internet
3Source control and build
4Badge and test
5CI and action
6Artifacts and dotnet try
7Docker with .NET Try
8ECB
9Intermezzo - Various implementations for programmers
10Intermezzo - similar code - options
11Plugin implementation
12GUI for console
13WebAPI
14Plugin in .NET Core 3
15Build and Versioning
16Add swagger
17Docker - first part
18Docker - second part
19Docker - build Azure
20Pipeline send to Docker Hub
21Play with Docker - online
22Run VSCode and Docker
23Deploy Azure
24VSCode see tests and powershell
25Code Coverage
26Database in Azure
27Sql In Memory or Azure
28Azure ConString, RSS
29Middleware for backward compatibility
30Identical Tables in EFCore
31Multiple Data in EFCore
32Dot net try again
33Start Azure Function
34Azure function - deploy
35Solving my problems
36IAsyncEnumerable transformed to IEnumerable and making Azure Functions works
37Azure functions - final
38Review of 37 hours
39Last Commit in AzureDevOps
40Create Angular WebSite
41Add static Angular to WebAPI .NET Core
42Docker for Angular
43Angular and CORS
44SSL , VSCode, Docker
45Routing in Angular
46RxJS for Routing
47RxJs Unsubscribe

EF Core identical tables and partial–part 30

Let’s suppose that you have 2 identical tables and you scaffold from the context the tables. It will give you 2 classes  – with the same properties. How can you make to work for the programmer as the same class, without modifying the models scaffolded by EF ?

Example – class Ecb and class Nbr from below are the same

public partial class Ecb
     {
         public string ExchangeFrom { get; set; }
         public string ExchangeTo { get; set; }
         public DateTime Date { get; set; }
         public decimal ExchangeValue { get; set; }
     }

public partial class Nbr
    {
        public string ExchangeFrom { get; set; }
        public string ExchangeTo { get; set; }
        public DateTime Date { get; set; }
        public decimal ExchangeValue { get; set; }
    }

public partial class InfoValutarContext : DbContext
    {
       

       public InfoValutarContext(DbContextOptions<InfoValutarContext> options)
            : base(options)
        {
        }

       public virtual DbSet<Ecb> Ecb { get; set; }
        public virtual DbSet<Nbr> Nbr { get; set; }

}

Answer:

Create an interface, add partials for the classes, add partial for context ( attention to namespaces)

public interface IExchangeRate
     {
         DateTime Date { get; set; }
         string ExchangeFrom { get; set; }
         string ExchangeTo { get; set; }
         decimal ExchangeValue { get; set; }
     }

public partial class Ecb: IExchangeRate
     {
     }
     public partial class Nbr : IExchangeRate
     {
     }

public partial class InfoValutarContext
     {
         public IQueryable<IExchangeRate> RateQ(string bank)
         {
             switch (bank?.ToLower())
             {
                 case “ecb”:
                     return this.Ecb.AsNoTracking();
                 case “bnr”:
                     return this.Nbr.AsNoTracking();
                 default:
                     throw new ArgumentException($”cannot find bank {bank}”);
             }
         }
     }

Infovalutar

And one hour passes...
(This is the result of 1 hour per day auto-challenge as a full cycle developer for an exchange rates application)
( You can see the sources at https://github.com/ignatandrei/InfoValutar/ )
NrPost 
1Start
2Reading NBR from internet
3Source control and build
4Badge and test
5CI and action
6Artifacts and dotnet try
7Docker with .NET Try
8ECB
9Intermezzo - Various implementations for programmers
10Intermezzo - similar code - options
11Plugin implementation
12GUI for console
13WebAPI
14Plugin in .NET Core 3
15Build and Versioning
16Add swagger
17Docker - first part
18Docker - second part
19Docker - build Azure
20Pipeline send to Docker Hub
21Play with Docker - online
22Run VSCode and Docker
23Deploy Azure
24VSCode see tests and powershell
25Code Coverage
26Database in Azure
27Sql In Memory or Azure
28Azure ConString, RSS
29Middleware for backward compatibility
30Identical Tables in EFCore
31Multiple Data in EFCore
32Dot net try again
33Start Azure Function
34Azure function - deploy
35Solving my problems
36IAsyncEnumerable transformed to IEnumerable and making Azure Functions works
37Azure functions - final
38Review of 37 hours
39Last Commit in AzureDevOps
40Create Angular WebSite
41Add static Angular to WebAPI .NET Core
42Docker for Angular
43Angular and CORS
44SSL , VSCode, Docker
45Routing in Angular
46RxJS for Routing
47RxJs Unsubscribe

Middleware for custom urls–part 29

The question was how I can now intercept calls like

www.infovalutar.ro/bnr/2004/10/10/EUR

www.infovalutar.ro/bnr/azi/eur

www.infovalutar.ro/2004/6/4/eur.bnr

http://www.infovalutar.ro/bnr/rss

? There is no controller ! So – middleware to help!

For reading about middleware, please see https://docs.microsoft.com/en-us/aspnet/core/fundamentals/middleware/?view=aspnetcore-3.0

For rewriting, please see https://docs.microsoft.com/en-us/aspnet/core/fundamentals/url-rewriting?view=aspnetcore-3.0

Anyway, this is my code:

var service = app.ApplicationServices.GetService<LoadExchangeProviders>();
foreach (var item in service.Banks())
{
app.MapWhen(cnt =>
cnt.Request.Path.Value.StartsWith(“/” + item + “/”, StringComparison.InvariantCultureIgnoreCase)
||
cnt.Request.Path.Value.EndsWith(“.” + item, StringComparison.InvariantCultureIgnoreCase)
, HandleBank);
}

Figures also that previous answer was a string, not an object – changing return type to string

Infovalutar

And one hour passes...
(This is the result of 1 hour per day auto-challenge as a full cycle developer for an exchange rates application)
( You can see the sources at https://github.com/ignatandrei/InfoValutar/ )
NrPost 
1Start
2Reading NBR from internet
3Source control and build
4Badge and test
5CI and action
6Artifacts and dotnet try
7Docker with .NET Try
8ECB
9Intermezzo - Various implementations for programmers
10Intermezzo - similar code - options
11Plugin implementation
12GUI for console
13WebAPI
14Plugin in .NET Core 3
15Build and Versioning
16Add swagger
17Docker - first part
18Docker - second part
19Docker - build Azure
20Pipeline send to Docker Hub
21Play with Docker - online
22Run VSCode and Docker
23Deploy Azure
24VSCode see tests and powershell
25Code Coverage
26Database in Azure
27Sql In Memory or Azure
28Azure ConString, RSS
29Middleware for backward compatibility
30Identical Tables in EFCore
31Multiple Data in EFCore
32Dot net try again
33Start Azure Function
34Azure function - deploy
35Solving my problems
36IAsyncEnumerable transformed to IEnumerable and making Azure Functions works
37Azure functions - final
38Review of 37 hours
39Last Commit in AzureDevOps
40Create Angular WebSite
41Add static Angular to WebAPI .NET Core
42Docker for Angular
43Angular and CORS
44SSL , VSCode, Docker
45Routing in Angular
46RxJS for Routing
47RxJs Unsubscribe

Refactoring ,AzureConnectionString, rss, asmx–part 28

Now, I want to see that I can read from the database the exchange rates. For this, in Azure WebAPP I go to Settings => Configuration and add my connection string.

But now I have a problem: I must read from the configuration.  So back on DI with InMemory class – I inject from ASP.NET Core the Configuration and in the tests I construct directly with null.

IConfiguration configuration;

public InMemoryDB(IConfiguration config)
{
this.configuration = config;

}
private string GetConRead(string name)
{
return configuration?.GetConnectionString(name);
}

 

Also, for easy retrieving from URL , I modify from

public async Task<ExchangeRates[]> Rates(string bank,string fromDate, string toDate)

( that generates the url : https://infovalutar.azurewebsites.net/api/v1.0/FromDB/Rates?bank=bnr&fromDate=20010101&toDate=20500101 )

to

[HttpGet(“{bank}/{fromDate}/{toDate}”)]
public async Task<ExchangeRates[]> Rates([FromRoute] string bank, [FromRoute]string fromDate, [FromRoute]string toDate)

( that generates the URL: https://infovalutar.azurewebsites.net/api/v1.0/rates/bnr/20010101/20100101 )

 

( I have also modified the route on the controller to [Route(“api/v{version:apiVersion}/rates”)] )

The modifications are at https://github.com/ignatandrei/InfoValutar/commit/aeda74e071a333e800a36936d2d3fc685b4b3ac8 .

The bad part – the deploy takes now 7 minutes…( running tests first …)

I have to implement now the following (

www.infovalutar.ro/bnr/2004/10/10/EUR

www.infovalutar.ro/bnr/azi/eur

www.infovalutar.ro/2004/6/4/eur.bnr

http://www.infovalutar.ro/bnr/rss

http://infovalutar.ro/curs.asmx?wsdl

 

I will implement first into the rates API , then I will redirect.

For example, the first one is like this: www.infovalutar.ro/bnr/2004/10/10/EUR and www.infovalutar.ro/2004/6/4/eur.bnr can be implemented like this:

 

[HttpGet(“{year}/{month}/{day}/{exchange}.{bank}”)]
[HttpGet(“{bank}/{year}/{month}/{day}/{exchange}”)]
public async Task<ExchangeRates> RatesOnDate([FromRoute] string bank,
[FromRoute]int year, [FromRoute]int month,
[FromRoute] int day, [FromRoute] string exchange)

 

 

What about the rss ? There is a package called System.ServiceModel.Syndication in .NET Core  – and we can use for RSS like this:

[HttpGet(“{bank}/rss”)]
public async Task<IActionResult> GetRssFeed(string bank)
{
var data= await ret.TodayRates(bank);
var items = data
.Select(it =>
new SyndicationItem(
it.ExchangeTo,
it.ExchangeValue.ToString(),
new Uri($”http://www.infovalutar.ro/bnr/{it.Date.Year}/{it.Date.Month}/{it.Date.Day}/{it.ExchangeTo}”))
)
.ToArray();

var feed = new SyndicationFeed(
“Curs Valutar”,
“CursValutar, case, banci”,
new Uri( “http://www.infovalutar.ro/”),
items
);
feed.Language = “ro-ro”;
feed.TimeToLive = TimeSpan.FromSeconds(30);
using var sw = new StringWriter();
using var rssWriter = XmlWriter.Create(sw);

var rssFormatter = new Rss20FeedFormatter(feed,false);
rssFormatter.WriteTo(rssWriter);
rssWriter.Close();
return Content(sw.ToString(), “text/xml”);
}

 

What about http://infovalutar.ro/curs.asmx?wsdl ? Found https://devblogs.microsoft.com/dotnet/custom-asp-net-core-middleware-example/ article , that says”it has no support for message security, WSDL generation, duplex channels, non-HTTP transports” – so I do not want to do. Maybe something should be left…

So , now , how I can now intercept calls like

www.infovalutar.ro/bnr/2004/10/10/EUR

www.infovalutar.ro/bnr/azi/eur

www.infovalutar.ro/2004/6/4/eur.bnr

http://www.infovalutar.ro/bnr/rss

? There is no controller ! So – middleware to help!

Infovalutar

And one hour passes...
(This is the result of 1 hour per day auto-challenge as a full cycle developer for an exchange rates application)
( You can see the sources at https://github.com/ignatandrei/InfoValutar/ )
NrPost 
1Start
2Reading NBR from internet
3Source control and build
4Badge and test
5CI and action
6Artifacts and dotnet try
7Docker with .NET Try
8ECB
9Intermezzo - Various implementations for programmers
10Intermezzo - similar code - options
11Plugin implementation
12GUI for console
13WebAPI
14Plugin in .NET Core 3
15Build and Versioning
16Add swagger
17Docker - first part
18Docker - second part
19Docker - build Azure
20Pipeline send to Docker Hub
21Play with Docker - online
22Run VSCode and Docker
23Deploy Azure
24VSCode see tests and powershell
25Code Coverage
26Database in Azure
27Sql In Memory or Azure
28Azure ConString, RSS
29Middleware for backward compatibility
30Identical Tables in EFCore
31Multiple Data in EFCore
32Dot net try again
33Start Azure Function
34Azure function - deploy
35Solving my problems
36IAsyncEnumerable transformed to IEnumerable and making Azure Functions works
37Azure functions - final
38Review of 37 hours
39Last Commit in AzureDevOps
40Create Angular WebSite
41Add static Angular to WebAPI .NET Core
42Docker for Angular
43Angular and CORS
44SSL , VSCode, Docker
45Routing in Angular
46RxJS for Routing
47RxJs Unsubscribe

In memory or sql–part 27

When I want to perform tests , the SqlServer in memory is enough good. But , when in production, should have a proper connection string.

So I figured a simple way to understand this: if no connection string in appsettings.json, then use InMemory Sql Server . If there is, it should be a read connection string.

First, I have tried with

ConfigurationManager.ConnectionStrings[“DBWrite”];

– but this is the old XML way – does not work with appsettings.json

I did not want to have DI in the constructor to read the file – so I realized that I can do this:

configuration = new ConfigurationBuilder()
.SetBasePath(AppDomain.CurrentDomain.BaseDirectory)
.AddJsonFile(“appsettings.json”)
.Build();

This is not so good – because the code for retrieving looks like this:

DbContextOptionsBuilder<InfoValutarContext> opt;
var ConnectionString = InMemoryDB.sing.GetConRead(“DBRead”);

if (string.IsNullOrWhiteSpace(ConnectionString ))
{
opt = InMemoryDB.sing.MemoryOptions();
}
else
{
opt = new DbContextOptionsBuilder<InfoValutarContext>();
opt.UseSqlServer(ConnectionString);
}

However,adding save and retrieve code ( with interfaces) , adding tests , adding controllers and DI on the WebAPI takes 1 hour

The commit is https://github.com/ignatandrei/InfoValutar/commit/ddd6fdc38bd8eee46d7fea0c54603c3644046cf6 and has 11 files .

Infovalutar

And one hour passes...
(This is the result of 1 hour per day auto-challenge as a full cycle developer for an exchange rates application)
( You can see the sources at https://github.com/ignatandrei/InfoValutar/ )
NrPost 
1Start
2Reading NBR from internet
3Source control and build
4Badge and test
5CI and action
6Artifacts and dotnet try
7Docker with .NET Try
8ECB
9Intermezzo - Various implementations for programmers
10Intermezzo - similar code - options
11Plugin implementation
12GUI for console
13WebAPI
14Plugin in .NET Core 3
15Build and Versioning
16Add swagger
17Docker - first part
18Docker - second part
19Docker - build Azure
20Pipeline send to Docker Hub
21Play with Docker - online
22Run VSCode and Docker
23Deploy Azure
24VSCode see tests and powershell
25Code Coverage
26Database in Azure
27Sql In Memory or Azure
28Azure ConString, RSS
29Middleware for backward compatibility
30Identical Tables in EFCore
31Multiple Data in EFCore
32Dot net try again
33Start Azure Function
34Azure function - deploy
35Solving my problems
36IAsyncEnumerable transformed to IEnumerable and making Azure Functions works
37Azure functions - final
38Review of 37 hours
39Last Commit in AzureDevOps
40Create Angular WebSite
41Add static Angular to WebAPI .NET Core
42Docker for Angular
43Angular and CORS
44SSL , VSCode, Docker
45Routing in Angular
46RxJS for Routing
47RxJs Unsubscribe

Adding database in Azure –part 26

Now getting the database – needed for historic data.

When I go to Create New Database in Azure Portal , there are many types of Database (mongo, postgres, many others) – the easy choice, for me, is SqlServer ( even if the tables are not be updated – the exchange rates does not change a lot). There is something that is easy to deploy a WebApp : WebApp + Sql

But I wil create a new one – Azure Sql Managed Instance – the price for 4 vCore is > 400 EUR. Sure do not want this…

So I decided yo have SqlServer, with a database with 2 GB storage  – smaller price, like 4.21 per month– for a normal person.

I can access with SSMS to create tables – and then I generate the script

CREATE TABLE [dbo].[NBR](
[ExchangeFrom] [nvarchar](50) NOT NULL,
[ExchangeTo] [nvarchar](50) NOT NULL,
[Date] [date] NOT NULL,
[ExchangeValue] [decimal](18, 6) NOT NULL,
CONSTRAINT [PK_NBR] PRIMARY KEY CLUSTERED
(
[ExchangeFrom] ASC,
[ExchangeTo] ASC,
[Date] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO

 

Create an ISave interface ( trying to cope with CQRS) .

Now I want to scaffold C# from database like https://docs.microsoft.com/en-us/ef/core/miscellaneous/cli/dotnet

Installing

dotnet tool install –global dotnet-ef

gives error about versioning

dotnet tool install –global dotnet-ef –version 3.0.0

SUccess!

Now trying to scaffold

dotnet ef dbcontext scaffold “Server=(localdb)\mssqllocaldb;Database=Blogging;Trusted_Connection=True;” Microsoft.EntityFrameworkCore.SqlServer -o Models

Error – does not find project

Ok. Run in the folder with the project. Now it does not like .NET Standard – wants .NET Core . Changed in .csproj <TargetFramework>netcoreapp3.0</TargetFramework>

Now it says:

Your startup project ‘InfovalutarDB’ doesn’t reference Microsoft.EntityFrameworkCore.Design.

Adding the NuGet Package

Now the command line

dotnet ef dbcontext scaffold “Server=(localdb)\mssqllocaldb;Database=Blogging;Trusted_Connection=True;” Microsoft.EntityFrameworkCore.SqlServer -o Models

Works!

Reading about storing connection strings safe:

http://go.microsoft.com/fwlink/?LinkId=723263

Figuring a way to use either inmemory database( for fast testing) or sqlserver

var config = ConfigurationManager.ConnectionStrings[“DB”];
var opt= new DbContextOptionsBuilder<InfoValutarContext>();
if (config == null)
{
opt.UseInMemoryDatabase(“write”);
}
else
{
opt.UseSqlServer(config.ConnectionString);
}

var cnt = new InfoValutarContext(opt.Options);

 

So a new Test created:

ISave s = new SaveSqlServer();
var response = await File.ReadAllTextAsync(Path.Combine(“Data”, “20191020bnr.txt”));
var m = new MockHttpMessageHandler();
m.When(“https://www.bnr.ro/nbrfxrates.xml”)
.Respond(“application/text”, response);

var nbr = new GetNBRExchange(m);
var data = await nbr.GetActualRates().ToArrayAsync();
var nr= await s.Save(data);
Assert.Equal(nr, data.Length);

 

And modified in the Docker file to restore this new project

Infovalutar

And one hour passes...
(This is the result of 1 hour per day auto-challenge as a full cycle developer for an exchange rates application)
( You can see the sources at https://github.com/ignatandrei/InfoValutar/ )
NrPost 
1Start
2Reading NBR from internet
3Source control and build
4Badge and test
5CI and action
6Artifacts and dotnet try
7Docker with .NET Try
8ECB
9Intermezzo - Various implementations for programmers
10Intermezzo - similar code - options
11Plugin implementation
12GUI for console
13WebAPI
14Plugin in .NET Core 3
15Build and Versioning
16Add swagger
17Docker - first part
18Docker - second part
19Docker - build Azure
20Pipeline send to Docker Hub
21Play with Docker - online
22Run VSCode and Docker
23Deploy Azure
24VSCode see tests and powershell
25Code Coverage
26Database in Azure
27Sql In Memory or Azure
28Azure ConString, RSS
29Middleware for backward compatibility
30Identical Tables in EFCore
31Multiple Data in EFCore
32Dot net try again
33Start Azure Function
34Azure function - deploy
35Solving my problems
36IAsyncEnumerable transformed to IEnumerable and making Azure Functions works
37Azure functions - final
38Review of 37 hours
39Last Commit in AzureDevOps
40Create Angular WebSite
41Add static Angular to WebAPI .NET Core
42Docker for Angular
43Angular and CORS
44SSL , VSCode, Docker
45Routing in Angular
46RxJS for Routing
47RxJs Unsubscribe

Code Coverage–part 25

Install coverlet and report generator

dotnet tool install coverlet.console

dotnet tool install dotnet-reportgenerator-globaltool

 

Then

dotnet coverlet Infovalutar.sln –target “dotnet” –targetargs “test InfovalutarTest\InfovalutarTest.csproj –configuration release –no-build” –format opencover –exclude “[xunit*]*”

dotnet reportgenerator “-reports:coverage.opencover.xml” “-targetdir:coveragereport” “-reporttypes:HTMLInline;HTMLSummary;Badges”

 

And the result ?No assemblies have been covered.

Updating all NuGet packages for the solution  – including a collector for coverlet.

Reading more, discover it works with

dotnet test –collect:”XPlat Code Coverage”  -r resultsFolder

The problem is that generates a GUID inside resultsFolder … and reportGenerator cannot be pointed to a random folder

Playing with different options, such as

dotnet test /p:CollectCoverage=true /p:CoverletOutput=’results’ /p:CoverletOutputFormat=json -v n

No results in the results directory…

Found obscure reference https://github.com/tonerdo/coverlet/issues/201 that I need to add package coverlet.msbuild

Now

dotnet test –configuration release –no-build  /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura -v m /p:CoverletOutput=cob.xml

dotnet reportgenerator “-reports:InfovalutarTest/cob.xml” “-targetdir:coveragereport” “-reporttypes:HTMLInline;HTMLSummary;Badges”

 

And generates report.

And because I want those to be added in AzureDevOps at test I add –logger trx  and https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/test/publish-test-results?view=azure-devops&tabs=yaml

– task: PublishTestResults@2
inputs:
testRunner: VSTest
testResultsFiles: ‘**/*.trx’

– task: PublishCodeCoverageResults@1
inputs:
codeCoverageTool: cobertura
summaryFileLocation: ‘**/cob.xml’

It works! Last: going to shields.io to have a display of the tests

![Azure DevOps tests (branch)](https://img.shields.io/azure-devops/tests/ignatandrei0674/InfoValutar/5/master)

![Azure DevOps cc](https://img.shields.io/azure-devops/coverage/ignatandrei0674/InfoValutar/5/master)

 

Infovalutar

And one hour passes...
(This is the result of 1 hour per day auto-challenge as a full cycle developer for an exchange rates application)
( You can see the sources at https://github.com/ignatandrei/InfoValutar/ )
NrPost 
1Start
2Reading NBR from internet
3Source control and build
4Badge and test
5CI and action
6Artifacts and dotnet try
7Docker with .NET Try
8ECB
9Intermezzo - Various implementations for programmers
10Intermezzo - similar code - options
11Plugin implementation
12GUI for console
13WebAPI
14Plugin in .NET Core 3
15Build and Versioning
16Add swagger
17Docker - first part
18Docker - second part
19Docker - build Azure
20Pipeline send to Docker Hub
21Play with Docker - online
22Run VSCode and Docker
23Deploy Azure
24VSCode see tests and powershell
25Code Coverage
26Database in Azure
27Sql In Memory or Azure
28Azure ConString, RSS
29Middleware for backward compatibility
30Identical Tables in EFCore
31Multiple Data in EFCore
32Dot net try again
33Start Azure Function
34Azure function - deploy
35Solving my problems
36IAsyncEnumerable transformed to IEnumerable and making Azure Functions works
37Azure functions - final
38Review of 37 hours
39Last Commit in AzureDevOps
40Create Angular WebSite
41Add static Angular to WebAPI .NET Core
42Docker for Angular
43Angular and CORS
44SSL , VSCode, Docker
45Routing in Angular
46RxJS for Routing
47RxJs Unsubscribe

See the tests in VSCode and improvements in powershell–part 24

I wanted that the user can see the tests when running in  VSCode. So in devcontainer.json I have put

“extensions”: [
“ms-vscode.csharp”
“ms-vscode.csharp”,
“hbenl.vscode-test-explorer”,
“formulahendry.dotnet-test-explorer”
]

and in the settings.json on .vscode folder

 

dotnet-test-explorer.enableTelemetry”: false,
“dotnet-test-explorer.testProjectPath”:”**/*.sln”,
“dotnet-test-explorer.autoExpandTree”:true

 

So far, so good. But – I remember that powershell have a problem. And I figure why – before running

dotnet pwsh

I should run

dotnet tool restore

in order to run the dotnet-toolsjson from .config file

 

{

“version”: 1,

“isRoot”: true,

“tools”: {

“powershell”: {

“version”: “6.2.3”,

“commands”: [

“pwsh”

]

}

}

}

 

.And this command should be executed both in Docker and in Azure

Infovalutar

And one hour passes...
(This is the result of 1 hour per day auto-challenge as a full cycle developer for an exchange rates application)
( You can see the sources at https://github.com/ignatandrei/InfoValutar/ )
NrPost 
1Start
2Reading NBR from internet
3Source control and build
4Badge and test
5CI and action
6Artifacts and dotnet try
7Docker with .NET Try
8ECB
9Intermezzo - Various implementations for programmers
10Intermezzo - similar code - options
11Plugin implementation
12GUI for console
13WebAPI
14Plugin in .NET Core 3
15Build and Versioning
16Add swagger
17Docker - first part
18Docker - second part
19Docker - build Azure
20Pipeline send to Docker Hub
21Play with Docker - online
22Run VSCode and Docker
23Deploy Azure
24VSCode see tests and powershell
25Code Coverage
26Database in Azure
27Sql In Memory or Azure
28Azure ConString, RSS
29Middleware for backward compatibility
30Identical Tables in EFCore
31Multiple Data in EFCore
32Dot net try again
33Start Azure Function
34Azure function - deploy
35Solving my problems
36IAsyncEnumerable transformed to IEnumerable and making Azure Functions works
37Azure functions - final
38Review of 37 hours
39Last Commit in AzureDevOps
40Create Angular WebSite
41Add static Angular to WebAPI .NET Core
42Docker for Angular
43Angular and CORS
44SSL , VSCode, Docker
45Routing in Angular
46RxJS for Routing
47RxJs Unsubscribe

Deploy to Azure–part 23

Create in Azure an AppService infovalutar with InfovalutarRG resource group – can be done like here

https://docs.microsoft.com/en-us/azure/app-service/app-service-web-get-started-dotnet

or from the Azure Portal ( create AppService – I have put Linux with .NET Core 3.0)

Searching how to connect AzureDevOps – the connection should be added from Project Settings (a link at the bottom of the page)

Creating the service InfoValutarServiceConnection on AzureDevops

Saving the yaml files ( with inherent spaces problems)

https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/azure-rm-web-app-deployment?view=azure-devops

Now it says the error:

2019-11-28T19:02:29.1210252Z ##[error]Error Code: ERROR_DESTINATION_NOT_REACHABLE
More Information: Could not connect to the remote computer ("infovalutar.scm.azurewebsites.net"). On the remote computer, make sure that Web Deploy is installed and that the required process ("Web Management Service") is started.  Learn more at: http://go.microsoft.com/fwlink/?LinkId=221672#ERROR_DESTINATION_NOT_REACHABLE.

Good – but my site is  https://infovalutar.azurewebsites.net/ ,  not infovalutar.scm.azurewebsites.net

Reading documentation from https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/azure-rm-web-app-deployment?view=azure-devops

Changing from

– task: AzureRmWebAppDeployment@3

inputs:

azureSubscription: ‘InfoValutarServiceConnection’

WebAppName: ‘infovalutar’

Package: $(System.ArtifactsDirectory)/*InfoValLinuxX64*.zip

ResourceGroupName: ‘infovalutarRG’

to

– task: AzureRmWebAppDeployment@4

and hoping in magic  ( also, put in docker job

dependsOn:

– Build_With_Test

condition: and(succeeded(),false)

in order to not execute docker job now…

And now the deployment works! See yourself at https://infovalutar.azurewebsites.net/

Infovalutar

And one hour passes...
(This is the result of 1 hour per day auto-challenge as a full cycle developer for an exchange rates application)
( You can see the sources at https://github.com/ignatandrei/InfoValutar/ )
NrPost 
1Start
2Reading NBR from internet
3Source control and build
4Badge and test
5CI and action
6Artifacts and dotnet try
7Docker with .NET Try
8ECB
9Intermezzo - Various implementations for programmers
10Intermezzo - similar code - options
11Plugin implementation
12GUI for console
13WebAPI
14Plugin in .NET Core 3
15Build and Versioning
16Add swagger
17Docker - first part
18Docker - second part
19Docker - build Azure
20Pipeline send to Docker Hub
21Play with Docker - online
22Run VSCode and Docker
23Deploy Azure
24VSCode see tests and powershell
25Code Coverage
26Database in Azure
27Sql In Memory or Azure
28Azure ConString, RSS
29Middleware for backward compatibility
30Identical Tables in EFCore
31Multiple Data in EFCore
32Dot net try again
33Start Azure Function
34Azure function - deploy
35Solving my problems
36IAsyncEnumerable transformed to IEnumerable and making Azure Functions works
37Azure functions - final
38Review of 37 hours
39Last Commit in AzureDevOps
40Create Angular WebSite
41Add static Angular to WebAPI .NET Core
42Docker for Angular
43Angular and CORS
44SSL , VSCode, Docker
45Routing in Angular
46RxJS for Routing
47RxJs Unsubscribe

Andrei Ignat weekly software news(mostly .NET)

* indicates required

Please select all the ways you would like to hear from me:

You can unsubscribe at any time by clicking the link in the footer of our emails. For information about our privacy practices, please visit our website.

We use Mailchimp as our marketing platform. By clicking below to subscribe, you acknowledge that your information will be transferred to Mailchimp for processing. Learn more about Mailchimp's privacy practices here.