XUnit test case for controller action and service method in WebAPI.

Mar 15 2022 11:49 AM

Hi,

I had following action method in controller.cs

public PrivacyModel GetUserPrivacyDetails() => _userService.GetUserPrivacyDetails();

and following in the ineterface and service class

PrivacyModel GetUserPrivacyDetails();

public PrivacyModel GetUserPrivacyDetails()
        {
            List<privacy> privacy = null;

            privacy = (from fq in this._dataContext.Privacymasters
                       where fq.Isactive == true
                       select new privacy
                       {
                           privacyId = fq.Id,
                           privacyTitle = fq.Privacyname
                       }).ToList();
            PrivacyModel privacyModel = new PrivacyModel();
            privacyModel.Privacy = privacy;
            privacyModel.Type = "Users";

            return privacyModel;
        }

Xunit testcasesd

Please suggest me how to write Xunit testcases for my controller, model and service class  action/methods