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


Golang MockRender.On方法代碼示例

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


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

示例1: TestPutFailed

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

	db := new(tests.MockExecutor)

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

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

	postDoor := &doorbot.Door{
		Name: "Romanian Landlords",
	}

	repoDoor := &doorbot.Door{
		ID:   5555,
		Name: "ACME",
	}

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

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

	Put(render, repositories, params, DoorViewModel{Door: postDoor})

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

示例2: TestPost

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

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

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

	door := &doorbot.Door{
		Name: "ACME",
	}

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

	render.On("JSON", http.StatusCreated, DoorViewModel{Door: door}).Return()

	Post(render, repositories, DoorViewModel{Door: door})

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

示例3: TestPostCreateError

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

	db := new(tests.MockExecutor)

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

	door := &doorbot.Door{
		Name: "ACME",
	}

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

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

	Post(render, repositories, DoorViewModel{Door: door})

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

示例4: TestDisable

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

	db := new(tests.MockExecutor)

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

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

	device := &doorbot.Device{
		ID:        4443,
		IsEnabled: false,
	}

	repo.On("Find", db, uint64(4443)).Return(device, nil)
	repo.On("Enable", db, device, false).Return(true, nil)

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

	Disable(render, repositories, params)

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

示例5: TestIndex

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

	render := new(tests.MockRender)
	repo := new(tests.MockDoorRepository)
	db := new(tests.MockExecutor)

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

	repo.On("All", db).Return(doors, nil)
	render.On("JSON", http.StatusOK, DoorsViewModel{Doors: doors}).Return()

	Index(render, repositories)

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

示例6: TestGetNotFound

func TestGetNotFound(t *testing.T) {

	var device *doorbot.Device

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

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

	db := new(tests.MockExecutor)

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

	repo.On("Find", db, uint64(33)).Return(device, nil)
	render.On("JSON", http.StatusNotFound, doorbot.NewEntityNotFoundResponse([]string{"The specified device does not exists"})).Return()

	Get(render, repositories, params)

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

示例7: TestPutNotFound

func TestPutNotFound(t *testing.T) {
	var device *doorbot.Device

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

	db := new(tests.MockExecutor)

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

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

	postDevice := &doorbot.Device{
		Name: "Chicken Nick",
	}

	repo.On("Find", db, uint64(44)).Return(device, nil)
	render.On("JSON", http.StatusNotFound, doorbot.NewEntityNotFoundResponse([]string{"The specified device does not exists"})).Return()

	Put(render, repositories, params, DeviceViewModel{Device: postDevice})

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

示例8: 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

示例9: 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

示例10: 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

示例11: TestDelete

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

	db := new(tests.MockExecutor)

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

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

	door := &doorbot.Door{
		ID:   33,
		Name: "ACME",
	}

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

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

	Delete(render, repositories, params)

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

示例12: TestDeleteFailed

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

	db := new(tests.MockExecutor)

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

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

	door := &doorbot.Door{
		ID:   55,
		Name: "ACME",
	}

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

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

	Delete(render, repositories, params)

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

示例13: 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

示例14: TestDelete

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

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

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

	account := &doorbot.Account{
		ID:   33,
		Name: "ACME",
	}

	admin := &doorbot.Administrator{}

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

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

	Delete(render, repositories, params, admin)

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

示例15: TestDeleteNotFound

func TestDeleteNotFound(t *testing.T) {
	var account *doorbot.Account
	admin := &doorbot.Administrator{}

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

	repositories := new(tests.MockRepositories)
	repositories.On("AccountRepository").Return(repo)
	repositories.On("AccountScope").Return(1)

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

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

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

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

	Delete(render, repositories, params, admin)

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


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