xunit

xUnit: how to Assert other event of types then EventHandler<EventArgs>

点点圈 提交于 2021-01-04 10:35:05
问题 I'm a beginner in unit testing and I've been searching the net for couple of hours now and I still can't find the answer to my simple question. I have a class with the following event: event Action<ITagData> OnTagHandled Now I want to write a unit test to assert if the event has been raised but when I write something like: Assert.Raises<EventArgs>(handler => m_rssiHander.OnTagHandled += handler, handler => m_rssiHander.OnTagHandled -= handler, () => { }); I get an error like: Cannot

(When) would it be a good idea to use FluentAssertions? [closed]

天涯浪子 提交于 2021-01-04 02:42:28
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 1 year ago . Improve this question I am rewriting a C# .NET project and currently planning how I am going to do the testing. After everything I have read I will install the XUnit framework (for the first time -- I am more experienced with MSTest). Now I am wondering whether I should

(When) would it be a good idea to use FluentAssertions? [closed]

旧街凉风 提交于 2021-01-04 02:39:21
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 1 year ago . Improve this question I am rewriting a C# .NET project and currently planning how I am going to do the testing. After everything I have read I will install the XUnit framework (for the first time -- I am more experienced with MSTest). Now I am wondering whether I should

(When) would it be a good idea to use FluentAssertions? [closed]

谁说胖子不能爱 提交于 2021-01-04 02:36:56
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 1 year ago . Improve this question I am rewriting a C# .NET project and currently planning how I am going to do the testing. After everything I have read I will install the XUnit framework (for the first time -- I am more experienced with MSTest). Now I am wondering whether I should

(When) would it be a good idea to use FluentAssertions? [closed]

寵の児 提交于 2021-01-04 02:36:25
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 1 year ago . Improve this question I am rewriting a C# .NET project and currently planning how I am going to do the testing. After everything I have read I will install the XUnit framework (for the first time -- I am more experienced with MSTest). Now I am wondering whether I should

not able to print output to console window while running xunit tests

风流意气都作罢 提交于 2020-12-31 09:53:37
问题 public class test2InAnotherProject { private readonly ITestOutputHelper output; public test2InAnotherProject(ITestOutputHelper output) { this.output = output; } int Diff(int a, int b) { return (a - b); } int Div(int a, int b) { return (b / a); } [Fact] public void Test2() { int a = 2, b = 4; output.WriteLine("Test1: Project 2 in old library"); int c = Diff(a, b); Assert.Equal(c, (a - b)); output.WriteLine("Test1: Asssert done Project 2 in old library"); } [Fact] public void Test3() { int a =

.NET core write better unit tests with Xunit + Autofixture + Moq

◇◆丶佛笑我妖孽 提交于 2020-12-13 07:07:40
问题 In .NET Core for unit testing, I'm using Xunit, Moq, and Autofixture. But even with them, I see that my unit tests become complicated and take time. Maybe someone could tell me if there are any ways to make this test smaller? [Fact] public async Task Verify_NotAuthorised_NoServiceSendInvoked() { // Arrange var fixture = new Fixture() .Customize(new AutoMoqCustomization()); var sut = fixture.Create<VerificationService>(); var mockApiBuilder = fixture.Freeze<Mock<IApiEntityBuilder>>(); //init

.NET core write better unit tests with Xunit + Autofixture + Moq

自闭症网瘾萝莉.ら 提交于 2020-12-13 07:02:46
问题 In .NET Core for unit testing, I'm using Xunit, Moq, and Autofixture. But even with them, I see that my unit tests become complicated and take time. Maybe someone could tell me if there are any ways to make this test smaller? [Fact] public async Task Verify_NotAuthorised_NoServiceSendInvoked() { // Arrange var fixture = new Fixture() .Customize(new AutoMoqCustomization()); var sut = fixture.Create<VerificationService>(); var mockApiBuilder = fixture.Freeze<Mock<IApiEntityBuilder>>(); //init

Mocking HttpClient GetAsync by using Moq library in Xunit test

ε祈祈猫儿з 提交于 2020-12-12 06:28:25
问题 I am writing a simple unit test for this small service that simply calls external APIs: public class ApiCaller : IApiCaller { private readonly IHttpClientFactory _httpFactory; public ApiCaller(IHttpClientFactory httpFactory) { _httpFactory = httpFactory; } public async Task<T> GetResponseAsync<T>(Uri url) { using (HttpClient client = _httpFactory.CreateClient()) { client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); client.Timeout = TimeSpan

C# Mock IHttpclient & CreateClient

南楼画角 提交于 2020-12-05 12:01:54
问题 I have a function that I want to x-unit test, but it seems that I have to mock the CreateClient function? Whenever I debug it during testing it seems that the var client is equals to null. I am injecting the dependencies properly, I am sure of that. What I want to know is how to mock the CreateClient. here is that function: public async Task CreateMessageHistoryAsync(Message message) { //This seems to be giving a null value var client = this.clientFactory.CreateClient(NamedHttpClients.COUCHDB