xunit

xunit constructor runs before each test

空扰寡人 提交于 2020-07-28 12:03:46
问题 In a test class, the constructor starts before each test and the initialized data provided by the constructor isn't reachable by the following tests. I'd like the initialized data to be accessible for all tests. (be created only once) [Category("Basics")] [Collection("DD")] [ExcludeFromCodeCoverage] public class SecurityTests : TestUnitBase { StartUpFixture fixture; public AuthenticationTests(StartUpFixture fixture) : base() { this.fixture = fixture; } [Fact(DisplayName = "Successful response

How to create mock for httpclient getasync method?

三世轮回 提交于 2020-07-21 12:54:25
问题 I am using Moq to create mocks for my unit tests but I am stuck when I have to create mock for getasync method of httpclient. Previously I was using SendAsync method and for that I could use the below code: var mockResponse = new HttpResponseMessage(HttpStatusCode.OK) {Content = new StringContent(expectedResponse)}; mockResponse.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); var mockHandler = new Mock<DelegatingHandler>(); mockHandler .Protected() .Setup<Task

How to moq HttpContext on Asp net Core

拜拜、爱过 提交于 2020-06-29 05:29:07
问题 I have an asp .net core project, and practically in each action we use session, my question is how to test it if I don't have sessionRepository. Controller tests crush because session in controller is null. I try to Moq IHttpContextAcessor and it also doesn't work. I try this: HttpContext.Current = new HttpContext(new HttpRequest(null, "http://tempuri.org", null), new HttpResponse(null)); but HttpContext doesn't contain the definition for Current. (using Microsoft.AspNetCore.Http;) Is there

Invalid cast exception Xunit deserialization error

守給你的承諾、 提交于 2020-06-29 05:13:09
问题 When trying to run a test case that uses the xunit framework through Visual Studio I am currently getting the following error. System.InvalidCastException HResult=0x80004002 Message=Specified cast is not valid. Source=xunit.execution.desktop StackTrace: at Xunit.Serialization.XunitSerializationInfo.GetValue[T](String key) in C:\Dev\xunit\xunit\src\common\XunitSerializationInfo.cs:line 40 at Xunit.Sdk.XunitTestCase.Deserialize(IXunitSerializationInfo data) in C:\Dev\xunit\xunit\src\xunit

Is it possible to use xUnit with LINQPad?

冷暖自知 提交于 2020-06-26 13:51:08
问题 Is it possible to use xUnit with LINQPad? It would be great to be able to write some tests for concepts being designed in LINQPad first. It's easier than adding yet another ConsoleApp23423894238 just to be able to quickly write some unit tests. 回答1: Possible? Sort of. This is neither a main use case of LINQPad nor of unit testing. Regarding LINQPad, you could use an existing test runner but probably the only ones that could be integrated with LINQPad are console runners. A test runner is not