.net-core

How to mock Db connection in xunit?

送分小仙女□ 提交于 2021-01-28 13:45:05
问题 I am writing unit test cases in xUnit. I am writing unit test case for opening database connection. I am writing negative case when database is down. Below is the real code where I am making connection to database. public IDbConnection CreateDirectDb2Connection(int attempt = 0) { try { var conn = new DB2Connection(BuildDB2ConnectionString()); conn.Open(); return conn; } catch (Exception ex) { logService.Debug($"Failed to create and open a connection, attempt {attempt + 1}/3, error: {ex}"); if

Use injected service from JS code to static Blazor method

拜拜、爱过 提交于 2021-01-28 12:28:58
问题 I have an app that uses a jQuery lib to show 'confirmation' dialogs. When a user clicks 'OK' or 'Cancel' on the dialog, then first a callback is made to my Javascript code. From there I do a call to a Blazor method, based on the decision the user made. This all looks something like this: My js code: $('.alert-yesno).on('click', function() { // For simplicity I immediately call the Blazor method DotNet.invokeMethodAsync('[Assembly name]', 'DoSomething') .then(data => { // do something... }); }

.NET Core Identity. Use one context or two?

爱⌒轻易说出口 提交于 2021-01-28 12:11:56
问题 I am struggling with a basic problem. Keep my ASP.NET Core Identity context separate from my business context or combine the two. Philosophically, it seems good to keep them separate. If I want to upgrade .NET Core at some point in the future, I have fewer issues if my identity context is separate. Practically, it seems like a good idea to combine them. Otherwise, I am creating another user table or doing some weird workarounds to get user information from navigation properties. How do you

Get calendar schedules with Graph API from C# service

两盒软妹~` 提交于 2021-01-28 12:01:44
问题 I need to use the Microsoft Graph API to get free/busy schedules from the calendar with a .NET Core Windows service. According to Microsoft's own documentation I should use the following: GraphServiceClient graphClient = new GraphServiceClient( authProvider ); var schedules = new List<String>() { "adelev@contoso.onmicrosoft.com", "meganb@contoso.onmicrosoft.com" }; var startTime = new DateTimeTimeZone { DateTime = "2019-03-15T09:00:00", TimeZone = "Pacific Standard Time" }; var endTime = new

.Net Core Nuget Package - Copy files to package consumer wwwroot

喜你入骨 提交于 2021-01-28 11:50:48
问题 I have a .Net Core 2.2 Library project. All this project contains is a bunch of static files that have the "Build Action" set as Content. The sole purpose of this projectis to be built into a Nuget package, and for any consumers to have the included contents added to their wwwroot folder. Unfortunately, the files "appear" as if they are there, when looking at Solution Explorer, but they actual path is: C:\Users\MyName\.nuget\package\mylib.staticfiles\0.0.1\contentFiles\any\netcoreapp2.2

Certificate issue in Kestrel ssl JSON configuration using .net Core 3.1

Deadly 提交于 2021-01-28 11:45:54
问题 I have seen this question answered but it doesn't seem to be working for .net core 3.1 This code finds the Certificate: using (var store = new X509Store("Root", StoreLocation.LocalMachine)) { store.Open(OpenFlags.ReadOnly); var certCollection = store.Certificates; var currentCerts = certCollection.Find(X509FindType.FindBySubjectName, "*.timedesk.com", false); if (currentCerts.Count == 0) throw new Exception("Https certificate is not found."); } This appsettings.json does not find the

Certificate issue in Kestrel ssl JSON configuration using .net Core 3.1

微笑、不失礼 提交于 2021-01-28 11:39:50
问题 I have seen this question answered but it doesn't seem to be working for .net core 3.1 This code finds the Certificate: using (var store = new X509Store("Root", StoreLocation.LocalMachine)) { store.Open(OpenFlags.ReadOnly); var certCollection = store.Certificates; var currentCerts = certCollection.Find(X509FindType.FindBySubjectName, "*.timedesk.com", false); if (currentCerts.Count == 0) throw new Exception("Https certificate is not found."); } This appsettings.json does not find the

.net core cpu usage for machine

空扰寡人 提交于 2021-01-28 11:32:33
问题 I recently migrated from c# to .net core. In c# I use to get CPU usage with this: PerformanceCounter cpuCounter; PerformanceCounter ramCounter; cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total"); public string getCurrentCpuUsage(){ return cpuCounter.NextValue()+"%"; } but in .net core PerformanceCounter is not available what is the solution ? please give me an advice. 回答1: Performance counters are not in Linux thus not in NET Core. Alternative way: private async

Why are classes like SHA1Managed, SHA256Managed hidden from my Intellisense?

人走茶凉 提交于 2021-01-28 11:21:10
问题 When I go to the System.Security.Cryptography namespace, I can only see SHA1 , SHA256 , HMACSHA1 etc classes there. But actually, there is a SHA1Managed class, as well as SHA256Managed , which I don't see? When I write it out manually - everything works as expected. Is this hidden intentionally? And what's the difference between simply instancing a managed version of those, versus for example calling their factory methods ( SHA1.Create() or SHA256.Create() )? Are they the same thing? 回答1: Can

.Net core and plugins

寵の児 提交于 2021-01-28 11:13:44
问题 Following this lecture (https://docs.microsoft.com/en-us/dotnet/core/tutorials/creating-app-with-plugin-support), I managed to create an app based on plugins. So far so good. But, I want to do more with my plugins. Hence, for one of them, I created an additional library. Of course, when developing my plugin, I got a library dependance to this lib I created. The problem is more on execution. When running my app, more especially when the plugin executes its task, I have an exception raised