TDD and protected methods

I am trying to learn TDD by creating a copy of an existing MVC application that I have, but I am creating a copy of it from scratch using TDD.

In my existing application, I have the Application_AuthenticateRequest method, as shown below.

It is protected. Do I believe that these methods should not be tested - i.e. you should check only public methods, not private and protected ones. If this is true, would I just delete the protected method below without writing any tests for it?

public class MvcApplication : System.Web.HttpApplication
{
    protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();

        WebApiConfig.Register(GlobalConfiguration.Configuration);
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);
        StaticDataSeeder.Seed();
    }

    protected void Application_AuthenticateRequest(Object sender, EventArgs e)
    {
        HttpCookie authCookie = Context.Request.Cookies[FormsAuthentication.FormsCookieName];

        if (authCookie == null) return;

        var authTicket = FormsAuthentication.Decrypt(authCookie.Value);

        if (authTicket == null) return;

        var userData = new UserDataModel(authTicket.UserData);

        var userPrincipal = new PaxiumPrincipal(new GenericIdentity(authTicket.Name), null)
        {
            Email = userData.Email,
            Menu = userData.Menu,
            RememberMe = userData.RememberMe
        };

        Context.User = userPrincipal;
    }
}
+4
source share
3 answers

. , , . , , , , .

:

public abstract class BaseMathsClass {
    protected int Mult(int a, int b) {
        return a * b;
    }
}

public class ConcreteMathClass : BaseMathsClass {
    public int Square(int x) {
        return Mult(x, x);
    }
}

Mult ConcreteMathClass, . , , , , , , . , , . .

, , . , , . , :

1

class MyClass {
    public int GetSquare(int someValue) {
        return someValue * someValue;
    }
}

2

class MyClass {
    public int GetSquare(int someValue) {
        return Mult(someValue, someValue);
    }

    private int Mult(int a, int b) {
        return a * b;
    }
}

2 , Mult, GetSquare . , Add, .

.

0

TDD. , - , , ?

, .

+3

, , , . , . , , , . , , . , , , .

+1

All Articles