nunit

Async unit testing with NUnit and C#

江枫思渺然 提交于 2020-12-13 03:58:02
问题 I have the following method I created it's nothing fancy just retrieves data from an HTTP server but it is an async method. public async Task<string> GetStringFromConsul(string key) { string s = ""; // attempts to get a string from Consul try { //async method to get the response HttpResponseMessage response = await this.http.GetAsync(apiPrefix + key); //if it responds successfully if (response.IsSuccessStatusCode) { //parse out a string and decode said string s = await response.Content

Moq Sequence with Callback C#

久未见 提交于 2020-12-12 05:12:53
问题 I have this code below with a simple nunit test using Moq Sequence. The unit test works without using Callback, but it fails with Callback. Any ideas? public class MoqDemo { private ISender sender; public MoqDemo(ISender sender) { this.sender = sender; } public void Send() { for (int i = 0; i < 3; i++) { sender.SendMessage(i, $"{i}"); } } } NUnit test [TestFixture] public class MoqDemoTest { [Test] public void SequenceTest() { var sender = new Mock<ISender>(); using (Sequence.Create()) { var