dimanche 22 mars 2020

How to fix the following issue with test not being executed in Visual Studios

When Ever I try to run my test it shows the following

NUnit3TestExecutor converted 8 of 8 NUnit test cases The active test run was aborted. Reason: Test host process crashed : Process is terminated due to StackOverflowException.

I have a Helper class which has few methods here are the methods.

public class Helper
{
    public void Asserts(HttpWebResponse response)
    {
        Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
    }


    [AttributeUsage(AttributeTargets.Property)]
    public class UseWithApiMethodsAttribute : Attribute
    {
        public UseWithApiMethodsAttribute(params string[] methodNames)
        {
            MethodNames = methodNames;
        }

        public string[] MethodNames { get; private set; }
    }

    public class SelectivePropertyResolver : DefaultContractResolver
    {
        public string ApiMethodName { get; private set; }

        public SelectivePropertyResolver(string apiMethodName)
        {
            ApiMethodName = apiMethodName;
        }

        protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
        {
            JsonProperty prop = base.CreateProperty(member, memberSerialization);
            if (member.MemberType == MemberTypes.Property)
            {
                var att = ((PropertyInfo)member).GetCustomAttribute<UseWithApiMethodsAttribute>(true);
                if (att == null || !att.MethodNames.Contains(ApiMethodName))
                {
                    prop.Ignored = true;
                }
            }
            return prop;
        }
    }

    public string SerializeForApiMethod(Object model, string methodName)
    {
        var settings = new JsonSerializerSettings
        {
            ContractResolver = new SelectivePropertyResolver(methodName),
            Formatting = Formatting.Indented
        };
        return JsonConvert.SerializeObject(model, settings);
    }
}

I am calling the SerializeForApiMethod in my method that I am serializing from my model class. I am giving the model class instance reference name and the method name Ex:

public HttpWebResponse UpdateEndpointsFromTags()
{
    RequestHandler requestor = new RequestHandler(BaseUrl + "UpdateEndpointsFromTags", HttpVerb.POST, AuthenticationType.Bearer);
    return requestor.SendRequest(helper.SerializeForApiMethod(defaultModel, "UpdateEndpointsFromTags"));
}

Ex:

public HttpWebResponse UpdateTag()
{
    RequestHandler requestor = new RequestHandler(BaseUrl + "UpdateTag", HttpVerb.POST, AuthenticationType.Bearer);
    return requestor.SendRequest(helper.SerializeForApiMethod(modelForUpdate, "UpdateTag"));
}

Aucun commentaire:

Enregistrer un commentaire