當前位置: 首頁>>代碼示例>>Golang>>正文


Golang MockPersonRepository.On方法代碼示例

本文整理匯總了Golang中bitbucket/org/msamson/doorbot-api/tests.MockPersonRepository.On方法的典型用法代碼示例。如果您正苦於以下問題:Golang MockPersonRepository.On方法的具體用法?Golang MockPersonRepository.On怎麽用?Golang MockPersonRepository.On使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在bitbucket/org/msamson/doorbot-api/tests.MockPersonRepository的用法示例。


在下文中一共展示了MockPersonRepository.On方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestPostCreateError

func TestPostCreateError(t *testing.T) {
	render := new(tests.MockRender)
	repo := new(tests.MockPersonRepository)

	db := new(tests.MockExecutor)

	repositories := new(tests.MockRepositories)
	repositories.On("PersonRepository").Return(repo)
	repositories.On("DB").Return(db)
	repositories.On("AccountScope").Return(uint(1))

	person := &doorbot.Person{
		Name: "ACME",
	}

	repo.On("Create", db, person).Return(errors.New("errooor"))

	render.On("JSON", http.StatusInternalServerError, doorbot.NewInternalServerErrorResponse([]string{})).Return()

	Post(render, repositories, PersonViewModel{Person: person})

	render.Mock.AssertExpectations(t)
	repo.Mock.AssertExpectations(t)
	repositories.Mock.AssertExpectations(t)
}
開發者ID:masom,項目名稱:doorbot,代碼行數:25,代碼來源:people_test.go

示例2: TestIndexError

func TestIndexError(t *testing.T) {
	session := &auth.Authorization{
		Type: auth.AuthorizationPerson,
		Person: &doorbot.Person{
			AccountType: doorbot.AccountOwner,
		},
	}

	people := []*doorbot.Person{}
	err := errors.New("i like pasta")

	render := new(tests.MockRender)
	repo := new(tests.MockPersonRepository)

	db := new(tests.MockExecutor)

	repositories := new(tests.MockRepositories)
	repositories.On("PersonRepository").Return(repo)
	repositories.On("AccountScope").Return(uint(0))
	repositories.On("DB").Return(db)

	repo.On("All", db).Return(people, err)
	render.On("JSON", http.StatusInternalServerError, doorbot.NewInternalServerErrorResponse([]string{})).Return()

	Index(render, repositories, session)

	render.Mock.AssertExpectations(t)
	repo.Mock.AssertExpectations(t)
	repositories.Mock.AssertExpectations(t)
}
開發者ID:masom,項目名稱:doorbot,代碼行數:30,代碼來源:people_test.go

示例3: TestIndex

func TestIndex(t *testing.T) {
	people := []*doorbot.Person{
		&doorbot.Person{
			ID:        1,
			AccountID: 1,
			Name:      "A",
		},
	}

	session := &auth.Authorization{
		Type: auth.AuthorizationPerson,
		Person: &doorbot.Person{
			AccountType: doorbot.AccountOwner,
		},
	}

	render := new(tests.MockRender)
	repo := new(tests.MockPersonRepository)

	db := new(tests.MockExecutor)

	repositories := new(tests.MockRepositories)
	repositories.On("PersonRepository").Return(repo)
	repositories.On("DB").Return(db)

	repo.On("All", db).Return(people, nil)
	render.On("JSON", http.StatusOK, PeopleViewModel{People: people}).Return()

	Index(render, repositories, session)

	render.Mock.AssertExpectations(t)
	repo.Mock.AssertExpectations(t)
	repositories.Mock.AssertExpectations(t)
}
開發者ID:masom,項目名稱:doorbot,代碼行數:34,代碼來源:people_test.go

示例4: TestDeleteNotFound

func TestDeleteNotFound(t *testing.T) {
	var person *doorbot.Person

	repo := new(tests.MockPersonRepository)
	render := new(tests.MockRender)

	db := new(tests.MockExecutor)

	repositories := new(tests.MockRepositories)
	repositories.On("PersonRepository").Return(repo)
	repositories.On("DB").Return(db)
	repositories.On("AccountScope").Return(uint(1))

	params := martini.Params{
		"id": "44",
	}

	account := &doorbot.Account{}
	session := &auth.Authorization{
		Type: auth.AuthorizationPerson,
		Person: &doorbot.Person{
			AccountType: doorbot.AccountOwner,
		},
	}

	repo.On("Find", db, uint(44)).Return(person, nil)

	render.On("JSON", http.StatusNotFound, doorbot.NewEntityNotFoundResponse([]string{"The specified person does not exists"})).Return()

	Delete(render, repositories, params, account, session)

	render.Mock.AssertExpectations(t)
	repo.Mock.AssertExpectations(t)
	repositories.Mock.AssertExpectations(t)
}
開發者ID:masom,項目名稱:doorbot,代碼行數:35,代碼來源:people_test.go

示例5: TestGet

func TestGet(t *testing.T) {
	session := &auth.Authorization{
		Type: auth.AuthorizationPerson,
		Person: &doorbot.Person{
			AccountType: doorbot.AccountOwner,
		},
	}

	render := new(tests.MockRender)
	repo := new(tests.MockPersonRepository)

	db := new(tests.MockExecutor)

	repositories := new(tests.MockRepositories)
	repositories.On("PersonRepository").Return(repo)
	repositories.On("DB").Return(db)

	params := martini.Params{
		"id": "33",
	}

	person := &doorbot.Person{
		ID:   33,
		Name: "ACME",
	}

	render.On("JSON", http.StatusOK, PersonViewModel{Person: person}).Return(nil)
	repo.On("Find", db, uint(33)).Return(person, nil)

	Get(render, repositories, params, session)

	render.Mock.AssertExpectations(t)
	repo.Mock.AssertExpectations(t)
	repositories.Mock.AssertExpectations(t)
}
開發者ID:masom,項目名稱:doorbot,代碼行數:35,代碼來源:people_test.go

示例6: TestPost

func TestPost(t *testing.T) {
	render := new(tests.MockRender)
	repo := new(tests.MockPersonRepository)

	db := new(tests.MockExecutor)

	repositories := new(tests.MockRepositories)
	repositories.On("PersonRepository").Return(repo)
	repositories.On("DB").Return(db)
	repositories.On("AccountScope").Return(uint(0))

	person := &doorbot.Person{
		Name: "ACME",
	}

	repo.On("Create", db, person).Return(nil)

	render.On("JSON", http.StatusCreated, PersonViewModel{Person: person}).Return()

	Post(render, repositories, PersonViewModel{Person: person})

	render.Mock.AssertExpectations(t)
	repo.Mock.AssertExpectations(t)
	repositories.Mock.AssertExpectations(t)
}
開發者ID:masom,項目名稱:doorbot,代碼行數:25,代碼來源:people_test.go

示例7: TestPassword

func TestPassword(t *testing.T) {
	account := &doorbot.Account{
		ID:        444,
		Name:      "ACME",
		IsEnabled: true,
	}

	person := &doorbot.Person{
		ID:    1,
		Name:  "Cookie Monster",
		Email: "[email protected]",
	}

	passwordAuthentication := &doorbot.Authentication{
		AccountID: 444,
		PersonID:  1,
		Token:     "$2a$10$8XdprxFRIXCv1TC2cDjMNuQRiYkOX9PIivVpnSMM9b.1UjulLlrVm", // test
	}

	passwordRequest := PasswordRequest{
		Authentication: PasswordAuthentication{
			Email:    "[email protected]",
			Password: "test",
		},
	}

	var tokenNotFound *doorbot.Authentication

	render := new(tests.MockRender)
	personRepo := new(tests.MockPersonRepository)
	authRepo := new(tests.MockAuthenticationRepository)

	repositories := new(tests.MockRepositories)
	repositories.On("PersonRepository").Return(personRepo)
	repositories.On("AuthenticationRepository").Return(authRepo)

	db := new(tests.MockExecutor)
	repositories.On("DB").Return(db)

	personRepo.On("FindByEmail", db, "[email protected]").Return(person, nil)

	authRepo.On("FindByPersonIDAndProviderID", db, person.ID, auth.ProviderPassword).Return(passwordAuthentication, nil).Once()
	authRepo.On("FindByPersonIDAndProviderID", db, person.ID, auth.ProviderAPIToken).Return(tokenNotFound, nil).Once()
	authRepo.On("Create", db, mock.AnythingOfType("*doorbot.Authentication")).Return(nil).Once()

	render.On("JSON", http.StatusOK, mock.AnythingOfType("auth.APITokenResponse")).Return().Once()
	Password(render, account, repositories, passwordRequest)

	render.Mock.AssertExpectations(t)
	personRepo.Mock.AssertExpectations(t)
	repositories.Mock.AssertExpectations(t)
	authRepo.Mock.AssertExpectations(t)
}
開發者ID:masom,項目名稱:doorbot,代碼行數:53,代碼來源:auth_test.go

示例8: TestNotify

func TestNotify(t *testing.T) {
	render := new(tests.MockRender)
	db := new(tests.MockExecutor)
	repositories := new(tests.MockRepositories)

	notificator := new(tests.MockNotificator)
	peopleRepo := new(tests.MockPersonRepository)
	doorRepo := new(tests.MockDoorRepository)

	account := &doorbot.Account{
		ID: 44,
	}

	person := &doorbot.Person{
		AccountID:   44,
		ID:          45,
		Name:        "John Rambo",
		Email:       "[email protected]",
		IsVisible:   true,
		IsAvailable: true,
	}

	door := &doorbot.Door{}

	notification := Notification{
		DoorID:   33,
		PersonID: 45,
	}

	repositories.On("PersonRepository").Return(peopleRepo)
	repositories.On("DoorRepository").Return(doorRepo)
	repositories.On("DB").Return(db)

	peopleRepo.On("Find", db, uint(45)).Return(person, nil)
	doorRepo.On("Find", db, uint(33)).Return(door, nil)

	notificator.On("Notify", account, door, person).Return(nil)

	vm := ViewModel{Notification: &notification}

	render.On("JSON", http.StatusAccepted, ViewModel{Notification: &notification}).Return()

	Notify(render, account, repositories, notificator, vm)

	render.Mock.AssertExpectations(t)
	peopleRepo.Mock.AssertExpectations(t)
	doorRepo.Mock.AssertExpectations(t)
	repositories.Mock.AssertExpectations(t)
	notificator.Mock.AssertExpectations(t)
}
開發者ID:masom,項目名稱:doorbot,代碼行數:50,代碼來源:notifications_test.go

示例9: TestPasswordInvalid

func TestPasswordInvalid(t *testing.T) {
	person := &doorbot.Person{
		ID:    1,
		Name:  "Cookie Monster",
		Email: "[email protected]",
	}

	account := &doorbot.Account{
		ID:        1,
		Name:      "ACME",
		IsEnabled: true,
	}

	passwordAuthentication := &doorbot.Authentication{
		AccountID: 1,
		PersonID:  1,
		Token:     "$2a$10$8XdprxFRIXCv1TC2cDjMNuQRiYkOX9PIivVpnSMM9b.1UjulLlrVm", // test
	}

	passwordRequest := PasswordRequest{
		Authentication: PasswordAuthentication{
			Email:    "[email protected]",
			Password: "test1",
		},
	}

	render := new(tests.MockRender)
	personRepo := new(tests.MockPersonRepository)
	authRepo := new(tests.MockAuthenticationRepository)

	db := new(tests.MockExecutor)

	repositories := new(tests.MockRepositories)
	repositories.On("PersonRepository").Return(personRepo)
	repositories.On("AuthenticationRepository").Return(authRepo)
	repositories.On("DB").Return(db)

	personRepo.On("FindByEmail", db, "[email protected]").Return(person, nil)
	authRepo.On("FindByPersonIDAndProviderID", db, person.ID, auth.ProviderPassword).Return(passwordAuthentication, nil)

	render.On("JSON", http.StatusUnauthorized, doorbot.NewUnauthorizedErrorResponse([]string{"Invalid email or password"})).Return()
	Password(render, account, repositories, passwordRequest)

	render.Mock.AssertExpectations(t)
	personRepo.Mock.AssertExpectations(t)
	authRepo.Mock.AssertExpectations(t)
	repositories.Mock.AssertExpectations(t)
}
開發者ID:masom,項目名稱:doorbot,代碼行數:48,代碼來源:auth_test.go

示例10: TestRegister

func TestRegister(t *testing.T) {
	render := new(tests.MockRender)
	notificator := new(tests.MockNotificator)

	accountRepo := new(tests.MockAccountRepository)
	authRepo := new(tests.MockAuthenticationRepository)
	personRepo := new(tests.MockPersonRepository)

	db := new(tests.MockExecutor)
	tx := new(tests.MockTransaction)

	config := &doorbot.DoorbotConfig{}

	repositories := new(tests.MockRepositories)
	repositories.On("AccountRepository").Return(accountRepo)
	repositories.On("PersonRepository").Return(personRepo)
	repositories.On("AuthenticationRepository").Return(authRepo)
	repositories.On("SetAccountScope", uint(0)).Return()

	repositories.On("DB").Return(db)
	repositories.On("Transaction").Return(tx, nil)

	vm := RegisterViewModel{
		Account: AccountRegisterRequest{
			Name: "ACME",
		},
	}

	var noAccount *doorbot.Account

	accountRepo.On("FindByHost", db, mock.AnythingOfType("string")).Return(noAccount, nil)
	accountRepo.On("Create", tx, mock.AnythingOfType("*doorbot.Account")).Return(nil)
	personRepo.On("Create", tx, mock.AnythingOfType("*doorbot.Person")).Return(nil)
	authRepo.On("Create", tx, mock.AnythingOfType("*doorbot.Authentication")).Return(nil)

	notificator.On("AccountCreated", mock.AnythingOfType("*doorbot.Account"), mock.AnythingOfType("*doorbot.Person"), mock.AnythingOfType("string")).Return()
	tx.On("Commit").Return(nil)

	render.On("JSON", http.StatusCreated, mock.AnythingOfType("AccountViewModel")).Return()

	Register(render, config, repositories, notificator, vm)

	render.Mock.AssertExpectations(t)
	accountRepo.Mock.AssertExpectations(t)
	personRepo.Mock.AssertExpectations(t)
	authRepo.Mock.AssertExpectations(t)
}
開發者ID:masom,項目名稱:doorbot,代碼行數:47,代碼來源:accounts_test.go

示例11: TestAuthPassword_UserNotFound

func TestAuthPassword_UserNotFound(t *testing.T) {

	requestBody, _ := json.Marshal(auth.PasswordRequest{
		Authentication: auth.PasswordAuthentication{
			Email:    "[email protected]",
			Password: "test",
		},
	})

	req, _ := http.NewRequest("POST", "/api/auth/password", bytes.NewBuffer(requestBody))
	req.Header.Add("Content-Type", "application/json")
	req.Header.Add("Host", "account.example.com")
	req.Header.Add("Authorization", "dashboard gatekeeper")

	rec := httptest.NewRecorder()
	server := newServer()

	account := &doorbot.Account{
		ID: 45,
	}

	var person *doorbot.Person

	accountRepo := new(tests.MockAccountRepository)
	authRepo := new(tests.MockAuthenticationRepository)
	personRepo := new(tests.MockPersonRepository)

	db := new(tests.MockExecutor)
	repos := getDependency(server, (*doorbot.Repositories)(nil)).(*tests.MockRepositories)
	repos.On("SetAccountScope", uint(45)).Return()
	repos.On("AccountRepository").Return(accountRepo)
	repos.On("AuthenticationRepository").Return(authRepo)
	repos.On("PersonRepository").Return(personRepo)
	repos.On("DB").Return(db)

	accountRepo.On("FindByHost", db, "account").Return(account, nil)
	personRepo.On("FindByEmail", db, "[email protected]").Return(person, nil)

	server.ServeHTTP(rec, req)

	assert.Equal(t, http.StatusUnauthorized, rec.Code)
	repos.AssertExpectations(t)
	personRepo.AssertExpectations(t)
	accountRepo.AssertExpectations(t)

}
開發者ID:masom,項目名稱:doorbot,代碼行數:46,代碼來源:api_auth_test.go

示例12: TestPut

func TestPut(t *testing.T) {
	render := new(tests.MockRender)
	repo := new(tests.MockPersonRepository)

	db := new(tests.MockExecutor)

	repositories := new(tests.MockRepositories)
	repositories.On("PersonRepository").Return(repo)
	repositories.On("DB").Return(db)
	repositories.On("AccountScope").Return(uint(1))

	params := martini.Params{
		"id": "5555",
	}

	postPerson := &doorbot.Person{
		Name: "Romanian Landlords",
	}

	repoPerson := &doorbot.Person{
		ID:          5555,
		Name:        "ACME",
		AccountType: doorbot.AccountOwner,
	}

	session := &auth.Authorization{
		Type:   auth.AuthorizationPerson,
		Person: repoPerson,
	}

	repo.On("Find", db, uint(5555)).Return(repoPerson, nil)
	repo.On("Update", db, repoPerson).Return(true, nil)

	render.On("JSON", http.StatusOK, PersonViewModel{Person: repoPerson}).Return()

	Put(render, repositories, params, PersonViewModel{Person: postPerson}, session)

	assert.Equal(t, "Romanian Landlords", repoPerson.Name)

	render.Mock.AssertExpectations(t)
	repo.Mock.AssertExpectations(t)
	repositories.Mock.AssertExpectations(t)
}
開發者ID:masom,項目名稱:doorbot,代碼行數:43,代碼來源:people_test.go

示例13: TestPutFailed

func TestPutFailed(t *testing.T) {
	render := new(tests.MockRender)
	repo := new(tests.MockPersonRepository)

	db := new(tests.MockExecutor)

	repositories := new(tests.MockRepositories)
	repositories.On("PersonRepository").Return(repo)
	repositories.On("DB").Return(db)
	repositories.On("AccountScope").Return(uint(1))

	params := martini.Params{
		"id": "5555",
	}

	postPerson := &doorbot.Person{
		Name: "Romanian Landlords",
	}

	repoPerson := &doorbot.Person{
		ID:          5555,
		Name:        "ACME",
		AccountType: doorbot.AccountOwner,
	}

	session := &auth.Authorization{
		Type:   auth.AuthorizationPerson,
		Person: repoPerson,
	}

	repo.On("Find", db, uint(5555)).Return(repoPerson, nil)
	repo.On("Update", db, repoPerson).Return(false, errors.New("failed"))

	render.On("JSON", http.StatusInternalServerError, doorbot.NewInternalServerErrorResponse([]string{})).Return()

	Put(render, repositories, params, PersonViewModel{Person: postPerson}, session)

	render.Mock.AssertExpectations(t)
	repo.Mock.AssertExpectations(t)
	repositories.Mock.AssertExpectations(t)
}
開發者ID:masom,項目名稱:doorbot,代碼行數:41,代碼來源:people_test.go

示例14: TestDeleteFailed

func TestDeleteFailed(t *testing.T) {
	repo := new(tests.MockPersonRepository)
	render := new(tests.MockRender)

	db := new(tests.MockExecutor)

	repositories := new(tests.MockRepositories)
	repositories.On("PersonRepository").Return(repo)
	repositories.On("DB").Return(db)
	repositories.On("AccountScope").Return(uint(1))

	params := martini.Params{
		"id": "55",
	}

	person := &doorbot.Person{
		ID:   55,
		Name: "ACME",
	}

	account := &doorbot.Account{}
	session := &auth.Authorization{
		Type: auth.AuthorizationPerson,
		Person: &doorbot.Person{
			AccountType: doorbot.AccountOwner,
		},
	}

	repo.On("Find", db, uint(55)).Return(person, nil)
	repo.On("Delete", db, person).Return(false, errors.New("error"))

	render.On("Status", http.StatusInternalServerError).Return()

	Delete(render, repositories, params, account, session)

	render.Mock.AssertExpectations(t)
	repo.Mock.AssertExpectations(t)
	repositories.Mock.AssertExpectations(t)
}
開發者ID:masom,項目名稱:doorbot,代碼行數:39,代碼來源:people_test.go

示例15: TestDelete

func TestDelete(t *testing.T) {
	render := new(tests.MockRender)
	repo := new(tests.MockPersonRepository)

	db := new(tests.MockExecutor)

	repositories := new(tests.MockRepositories)
	repositories.On("PersonRepository").Return(repo)
	repositories.On("DB").Return(db)
	repositories.On("AccountScope").Return(uint(1))

	params := martini.Params{
		"id": "33",
	}

	person := &doorbot.Person{
		ID:   33,
		Name: "ACME",
	}

	account := &doorbot.Account{}
	session := &auth.Authorization{
		Type: auth.AuthorizationPerson,
		Person: &doorbot.Person{
			AccountType: doorbot.AccountOwner,
		},
	}

	repo.On("Find", db, uint(33)).Return(person, nil)
	repo.On("Delete", db, person).Return(true, nil)

	render.On("Status", http.StatusNoContent).Return()

	Delete(render, repositories, params, account, session)

	render.Mock.AssertExpectations(t)
	repo.Mock.AssertExpectations(t)
	repositories.Mock.AssertExpectations(t)
}
開發者ID:masom,項目名稱:doorbot,代碼行數:39,代碼來源:people_test.go


注:本文中的bitbucket/org/msamson/doorbot-api/tests.MockPersonRepository.On方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。