|
|
- package container
-
- import (
- "LAPP_LF_MOM_BACKEND/web/models"
- "fmt"
- "testing"
- )
-
- func TestSessionContext_New(t *testing.T) {
- userId := "userId"
- user := &models.Usertab{Userid: userId}
- sessionContext, err := NewSessionContext(user, transactionHandlerFactoryMock)
- if err != nil {
- t.Fatalf("意外错误:%s", err.Error())
- }
- if sessionContext == nil {
- t.Fatalf("创建失败!")
- }
- if sessionContext.user.Userid != userId {
- t.Fatalf("用户标识错误!")
- }
- }
-
- func TestSessionContext_New_NullUser(t *testing.T) {
-
- _, err := NewSessionContext(nil, transactionHandlerFactoryMock)
- if err == nil {
- t.Fatalf("意外的没有错误!")
- }
- if err.Error() != fmt.Sprintf("用户信息不能为空!") {
- t.Fatalf("意外错误:%s", err.Error())
- }
- }
-
- func TestSessionContext_New_NullTransactionHandlerFactory(t *testing.T) {
- userId := "userId"
- user := &models.Usertab{Userid: userId}
- _, err := NewSessionContext(user, nil)
- if err == nil {
- t.Fatalf("意外的没有错误!")
- }
- if err.Error() != fmt.Sprintf("事务句柄工厂不能为空!") {
- t.Fatalf("意外错误:%s", err.Error())
- }
- }
-
- func TestSessionContext_UserId(t *testing.T) {
- userId := "userId1"
- user := &models.Usertab{Userid: userId}
- sessionContext, err := NewSessionContext(user, transactionHandlerFactoryMock)
- if err != nil {
- t.Fatalf("意外错误:%s", err.Error())
- }
- userId = "userId2"
- sessionContext.user.Userid = userId
- if sessionContext.User().Userid != userId {
- t.Fatalf("获取用户标识错误!")
- }
- }
|