func TestVerifyLogin(t *testing.T) {
	var valid bool
	var m *booking_model.Model
	var err error
	database := booking_database_sqlite.New("/tmp/booking_test.db", true)
	modelStorage := booking_model_storage.New(database)
	modelService := New(modelStorage, booking_tokengenerator.New())

	m, err = modelService.Create(&booking_model.Model{})
	if err = AssertThat(err, NilValue()); err != nil {
		t.Fatal(err)
	}
	token := m.Token

	valid, err = modelService.VerifyLogin(&booking_model.Model{Token: token})
	if err = AssertThat(err, NilValue()); err != nil {
		t.Fatal(err)
	}
	if err = AssertThat(valid, Is(true)); err != nil {
		t.Fatal(err)
	}

	valid, err = modelService.VerifyLogin(&booking_model.Model{Token: "wrong"})
	if err = AssertThat(err, NilValue()); err != nil {
		t.Fatal(err)
	}
	if err = AssertThat(valid, Is(false)); err != nil {
		t.Fatal(err)
	}
}
func TestPutDate(t *testing.T) {
	resp := server_mock.NewHttpResponseWriterMock()
	db := booking_database_sqlite.New("/tmp/booking_test.db", false)
	userService := booking_user_service.New(booking_user_storage.New(db))
	dateStorage := booking_date_storage.New(db)
	err := dateStorage.Truncate()
	if err := AssertThat(err, NilValue()); err != nil {
		t.Fatal(err)
	}
	handler := createHandler(db, userService)
	req, err := createRequest("/date", userService)
	if err := AssertThat(err, NilValue()); err != nil {
		t.Fatal(err)
	}
	now, err := time.Parse(time.RFC3339, fmt.Sprintf("%d-01-02T15:04:05+01:00", time.Now().Year()+1))
	if err := AssertThat(err, NilValue()); err != nil {
		t.Fatal(err)
	}
	start := now.Add(1 * time.Hour).Format("2006-01-02T15:04:05Z")
	end := now.Add(2 * time.Hour).Format("2006-01-02T15:04:05Z")
	req.Body = ioutil.NopCloser(bytes.NewBufferString(`{"start":"` + start + `","end":"` + end + `","user_ids":[1]}`))
	req.Method = "PUT"
	handler.ServeHTTP(resp, req)
	if err := AssertThat(resp.Status(), Is(200)); err != nil {
		t.Fatal(err)
	}
}
func TestNewHandlerImplementsHttpHandler(t *testing.T) {
	db := booking_database_sqlite.New("/tmp/booking_test.db", false)
	userService := booking_user_service.New(booking_user_storage.New(db))
	handler := createHandler(db, userService)
	var i (*http.Handler) = nil
	err := AssertThat(handler, Implements(i).Message("check implements server.Server"))
	if err != nil {
		t.Fatal(err)
	}
}
func TestDate(t *testing.T) {
	resp := server_mock.NewHttpResponseWriterMock()
	db := booking_database_sqlite.New("/tmp/booking_test.db", false)
	userService := booking_user_service.New(booking_user_storage.New(db))
	handler := createHandler(db, userService)
	req, err := createRequest("/date", userService)
	if err := AssertThat(err, NilValue()); err != nil {
		t.Fatal(err)
	}
	handler.ServeHTTP(resp, req)
	if err := AssertThat(resp.Status(), Is(200)); err != nil {
		t.Fatal(err)
	}
}
func TestVerifyLoginUser(t *testing.T) {
	var err error
	var valid bool
	name := "testuser"
	password := "******"
	database := booking_database_sqlite.New("/tmp/booking_test.db", false)

	userStorage := user_storage.New(database)
	userService := user_service.New(userStorage)

	modelStorage := model_storage.New(database)
	modelService := model_service.New(modelStorage, booking_tokengenerator.New())

	if err := userStorage.Truncate(); err != nil {
		t.Fatal(err)
	}

	_, err = userService.Create(&booking_user.User{Login: name, Password: password})
	if err := AssertThat(err, NilValue()); err != nil {
		t.Fatal(err)
	}
	authenticationService := New(userService, modelService)

	valid, err = authenticationService.VerifyLogin(&booking_authentication.Authentication{Login: name, Password: password})
	if err := AssertThat(err, NilValue()); err != nil {
		t.Fatal(err)
	}
	if err := AssertThat(valid, Is(true)); err != nil {
		t.Fatal(err)
	}

	valid, err = authenticationService.VerifyLogin(&booking_authentication.Authentication{Login: name, Password: "******"})
	if err := AssertThat(err, NilValue()); err != nil {
		t.Fatal(err)
	}
	if err := AssertThat(valid, Is(false)); err != nil {
		t.Fatal(err)
	}

	valid, err = authenticationService.VerifyLogin(&booking_authentication.Authentication{Login: "******", Password: password})
	if err := AssertThat(err, NilValue()); err != nil {
		t.Fatal(err)
	}
	if err := AssertThat(valid, Is(false)); err != nil {
		t.Fatal(err)
	}
}
func TestVerifyLoginAndPassword(t *testing.T) {
	var err error
	var valid bool
	username := "******"
	password := "******"

	userStorage := booking_user_storage.New(booking_database_sqlite.New("/tmp/booking_test.db", false))
	if err := userStorage.Truncate(); err != nil {
		t.Fatal(err)
	}

	s := New(userStorage)

	_, err = s.Create(&booking_user.User{Login: username, Password: password})
	if err := AssertThat(err, NilValue()); err != nil {
		t.Fatal(err)
	}

	valid, err = s.VerifyLoginAndPassword(&booking_user.User{Login: "******", Password: password})
	if err := AssertThat(err, NilValue()); err != nil {
		t.Fatal(err)
	}
	if err := AssertThat(valid, Is(false)); err != nil {
		t.Fatal(err)
	}

	valid, err = s.VerifyLoginAndPassword(&booking_user.User{Login: username, Password: "******"})
	if err := AssertThat(err, NilValue()); err != nil {
		t.Fatal(err)
	}
	if err := AssertThat(valid, Is(false)); err != nil {
		t.Fatal(err)
	}

	valid, err = s.VerifyLoginAndPassword(&booking_user.User{Login: username, Password: password})
	if err := AssertThat(err, NilValue()); err != nil {
		t.Fatal(err)
	}
	if err := AssertThat(valid, Is(true)); err != nil {
		t.Fatal(err)
	}
}
func TestVerifyLoginHandlerFound(t *testing.T) {
	resp := server_mock.NewHttpResponseWriterMock()
	db := booking_database_sqlite.New("/tmp/booking_test.db", false)
	userService := booking_user_service.New(booking_user_storage.New(db))
	_, err := userService.Create(&booking_user.User{Login: "******", Password: "******"})
	if err := AssertThat(err, NilValue()); err != nil {
		t.Fatal(err)
	}
	handler := createHandler(db, userService)
	req, err := createRequest("/authentication/verifyLogin", userService)
	if err := AssertThat(err, NilValue()); err != nil {
		t.Fatal(err)
	}
	req.Body = ioutil.NopCloser(bytes.NewBufferString(`{"login":"******","password":"******"}`))
	req.Method = "POST"
	handler.ServeHTTP(resp, req)
	if err := AssertThat(resp.Status(), Is(200)); err != nil {
		t.Fatal(err)
	}
}
func createStorage() *storage {
	return New(booking_database_sqlite.New("/tmp/booking_test.db", false))
}
func createService() *userService {
	return New(booking_user_storage.New(booking_database_sqlite.New("/tmp/booking_test.db", false)))
}
func createDatabase() booking_database.Database {
	return booking_database_sqlite.New("/tmp/booking_test.db", false)
}