使用NModel自动生成测试用例(2)

发表于:2015-09-25来源:uml.org.cn作者:不详点击数: 标签:测试用例
接下来模拟动作: [ Feature ( Login )] public static class Login { public static Map User , LoginStatus ActiveLoginRequests = Map User , LoginStatus .EmptyMap; [ Requirement ( Send username and

  接下来模拟动作:

[Feature("Login")]

public static class Login

{

public static Map<User, LoginStatus> ActiveLoginRequests = Map<User, LoginStatus>.EmptyMap;

 

[Requirement("Send username and password to the server to log in.")]

[Action]

public static void Login_Start(User user, Password password)

{

if (password == Password.Correct)

ActiveLoginRequests = ActiveLoginRequests.Add(user, LoginStatus.Success);

else

ActiveLoginRequests = ActiveLoginRequests.Add(user, LoginStatus.Failure);

}

 

public static bool Login_StartEnabled()

{

return WebSiteModel.State == ModeState.Running;

}

 

public static bool Login_StartEnabled(User user)

{

return !ActiveLoginRequests.ContainsKey(user) &&

!WebSiteModel.UsersLoggedIn.Contains(user);

}

 

[Requirement("It should be possible to log out from any page")]

[Action]

public static void Logout(User user)

{

WebSiteModel.UsersLoggedIn = WebSiteModel.UsersLoggedIn.Remove(user);

}

public static bool LogoutEnabled()

{

return WebSiteModel.State == ModeState.Running;

}

 

public static bool LogoutEnabled(User user)

{

return WebSiteModel.UsersLoggedIn.Contains(user);

}

}

原文转自:http://www.uml.org.cn/Test/201005051.asp