How to deserialize C# async OkResult from controller that uses mongodb

I’m trying to create xUnit using mock tests for my api that uses DataAccess layer for mongodb. But for some reason it just doesn’t parse okResult to Json or Bson. I definitely know that there is 2 values that I need from debugger: My model is: namespace DataAccess.Models; [BsonIgnoreExtraElements] public class CyberGood { [BsonId] [BsonElement("id")]… Read More How to deserialize C# async OkResult from controller that uses mongodb

How Can I Setup mock object for unit test with Moq and Xunit in ASP.NET MVC Application?

I am new to unit testing and was trying to write unit tests for controllers’ action methods using Moq Library and Xunit framework. I created a list of departments as mock data and tried testing it by passing in Returns() method with the Setup() method of the Moq. But it shows error "Cannot convert type… Read More How Can I Setup mock object for unit test with Moq and Xunit in ASP.NET MVC Application?

Is it possible to pass number of times invocation is met as parameter to a unit test class method?

I have a unit test class method that currently takes 1 parameter but I want to extend it to receive 2 parameters with the latter being the number of times invocation is met on a mock object. What I currently have is something like this, which doesn’t compile successfully due to errors [Theory] [InlineData("", Times.Never)]… Read More Is it possible to pass number of times invocation is met as parameter to a unit test class method?

Error while testing my async function using XUNIT in c# .net core

I have convereted my IEnumerable function into a (public async Task<List>) however im having issues fixing my unit test for that specific part. Im using fakeiteasy to mock my data, and assert that my result.count == 1 after fetching my data. However i get this specific error Unable to cast object of type ‘System.Threading.Tasks.Task1[System.Collections.Generic.List1[WebAPI__CodeFirst.Classes.Customer]]’ to… Read More Error while testing my async function using XUNIT in c# .net core

Enum validation

Purpose is to validate Enum. namespace Test.Enums { public enum Type { Audi, Porsche, Peugeot } } I would like to write these values into an array so that I can compare them. [Fact] public void Test() { //arrange string[] expected = {"Audi", "Porsche", "Peugeot"}; string[] actual = new Test.Enums.Type(); //assert Assert.Equal(expected, actual); } How… Read More Enum validation

Visual Studio 2022 not running XUnit tests

I’ve created a EntityFramework ASP.NET solution and i’m trying to create a XUnit test project to test my differents classes i’ve created. I’ve created a TestClass for my Activity Class : using LADS_Model; using LADS_WebUI.Controllers; using Microsoft.VisualStudio.TestTools.UnitTesting; using System.Collections.Generic; using Xunit; using Assert = Microsoft.VisualStudio.TestTools.UnitTesting.Assert; namespace LADS_XUnit { public class UnitTest_Activity { [TestClass] public class… Read More Visual Studio 2022 not running XUnit tests

Running in Test using XUnit

Trying to learn Test Driven Design for the first time. I have a server that goes like this: public class ServerEngine { private static Socket _serverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); private static List<Socket> _clientSockets = new List<Socket>(); private static byte[] _buffer = new byte[1024]; public ServerEngine() { SetupServer(); } private void SetupServer() { Console.WriteLine("Setting… Read More Running in Test using XUnit