The Gemara Yoma 28B says that Avraham kept the entire Torah even rabbinical laws:
אָמַר (רַב), וְאִיתֵּימָא רַב אָשֵׁי: קִיֵּים אַבְרָהָם אָבִינוּ אֲפִילּוּ עֵירוּבֵי תַבְשִׁילִין, שֶׁנֶּאֱמַר: ״תּוֹרוֹתָי״, אַחַת תּוֹרָה שֶׁבִּכְתָב וְאַחַת תּוֹרָה שֶׁבְּעַל פֶּה.
Rav said, and some say Rav Ashi said: Abraham our Patriarch fulfilled the entire Torah, even the mitzva of the joining of cooked foods, a rabbinic ordinance instituted later, as it is stated: My Torahs. Since the term is in the plural, it indicates that Abraham kept two Torahs; one, the Written Torah, and one, the Oral Torah. In the course of fulfilling the Oral Torah, he fulfilled all the details and parameters included therein.
The Ramban on Chumash Bereishis 26:5 explains what this means at length;
וישמור משמרתי לשון רש"י (רש"י על בראשית כ״ו:ה׳) בקולי כשנסיתי אותו משמרתי גזירות להרחקה כגון שניות לעריות שבות לשבת מצותי מצות שאלו לא נכתבו דין הוא שיכתבו כגון גזל ושפיכות דמים חקותי דברים שיצר הרע ועו"ג משיבין עליהם כגון אכילת חזיר ולבישת שעטנז שאין טעם בדבר אלא המלך גזר חקו על עבדיו ותורתי להביא תורה שבעל פה הלכה למשה מסיני ואם כן יהיה כל זה בנוי על דעת שהיה אברהם מקיים ומשמר את התורה עד שלא נתנה וכך אמרו (ב"ר צד ג) בפסוק ויתן להם יוסף עגלות (בראשית מ״ה:כ״א) שפירש ממנו בפרשת עגלה ערופה שהיה עוסק בתורה כשם שהיו אבותיו ועד עכשו לא נתנה תורה והרי כתוב וישמור משמרתי מצותי חקותי ותורותי ושם אמרו שהיה משמר אפילו דקדוקי תורה והיה מלמד לבניו וכו' ויש לשאול אם כן איך הקים יעקב מצבה (בראשית כ״ח:י״ח) ונשא שתי אחיות וכדעת רבותינו (ב"ר עד יא) ארבע ועמרם נשא דודתו (שמות ו כ) ומשה רבינו הקים שתים עשרה מצבה (שם כד ד) והאיך אפשר שיהיו נוהגים היתר בתורה במה שאסר אברהם אביהם על עצמו וקבע לו השם שכר על הדבר והוא יצוה את בניו ואת ביתו אחריו ללכת בדרכיו וביעקב דרשו (ב"ר עט ו) ששמר את השבת וקבע תחומין ואפשר שיהיה זה בשבת מפני שהיא שקולה ככל התורה כולה (ירושלמי ברכות פ"א ה"ה) שהיא מעידה על מעשה בראשית ואולי נאמר משמרתי שניות לעריות של בני נח ומצותי גזל ושפיכות דמים חקותי אבר מן החי וכלאים של הרבעת בהמה והרכבת אילן ותורותי דינין ואסורי עבודה זרה שאלו כולן נצטוו בהן בני נח והוא השומר והעושה רצון בוראו ומשמר אפילו דקדוקין וחומרות במצות שלהן וכמו שהזכירו ע"ז של אברהם אבינו ארבע מאה פרקי הוות (ע"ז יד) ודרשו ב"מאה שערים" שמדדוה למעשרות (ב"ר סד ו) כי היו האבות נדיבי עמים לתת מעשרות לעניים או לכהני ה' כגון שם ועבר ותלמידיהם כענין והוא כהן לאל עליון (בראשית י״ד:י״ח) והנראה אלי מדעת רבותינו שלמד אברהם אבינו התורה כלה ברוח הקדש ועסק בה ובטעמי מצותיה וסודותיה ושמר אותה כולה כמי שאינו מצווה ועושה ושמירתו אותה היה בארץ בלבד ויעקב בחוצה לארץ נשא האחיות וכן עמרם כי המצות משפט אלהי הארץ הן אף על פי שהוזהרנו בחובת הגוף בכל מקום (קדושין לו) וכבר רמזו רבותינו הסוד הזה (בספרי דברים פסקא מג) ואני אעירך בו בעזרת השם (ויקרא יח כה דברים יא יח) והמצבה מצוה שנתחדשה בזמן ידוע היא כמו שדרשו (בספרי) באשר שנא ה' אלהיך (דברים טז כב) ששנאה אחר היותה אהובה בימי האבות וביוסף דרשו (ב"ר צב ד) שהיה משמר את השבת אפילו במצרים מפני שהיא שקולה כנגד כל המצות לפי שהיא עדות על חדוש העולם והיה עושה כן ללמד את בניו אמונת בריאת העולם להוציא מלבם כונת עבודה זרה ודעות המצרים וזאת כונתם ועל דרך הפשט נאמר שיהא משמרתי אמונת האלהות שהאמין בשם המיוחד ושמר משמרת זו בלבו וחלק בה על עובדי העבודה זרה וקרא בשם ה' להשיב רבים לעבודתו מצותי ככל אשר צוהו בלך לך מארצך ועולת בנו וגרישת האמה ואת בנה חקותי ללכת בדרכי השם להיות חנון ורחום ועושה צדקה ומשפט ולצות את בניו ואת ביתו בהם ותורותי המילה בעצמו ובניו ועבדיו ומצות בני נח כלן שהן תורה להם
AND HE KEPT MY CHARGE. Rashi comments: “As a reward that Abraham hearkened to My voice when I tested him. And he kept My charge — these are the precautionary decrees instituted by the Sages, which are intended to make us avoid the violation of Biblical laws, such as Second Degrees of forbidden marriages and certain prohibited acts on the Sabbath. My commandments — these are precepts which, had they not been written in the Torah, were requisite to have been written, such as robbery and murder. My statutes — these are matters against which the evil inclination and the heathen nations argue, such as the prohibitions against eating the swine and the wearing of garments woven of wool and linen, there being no apparent rationale for them except that they are decrees of the King imposed on His subjects. And My laws — the plural is intended to include, [besides the Written Law], the Oral Law as well as those rules given to Moses from Sinai.” [Thus far the words of Rashi.]
Now if so, all this interpretation is posited on the opinion that Abraham fulfilled and observed the Torah before it was given on Sinai. This is indeed what the Sages of the Midrash said in connection with the verse, And Joseph gave them ‘agaloth’ (wagons), thereby indicating to his father that when he left him they were studying the section dealing with Eglah Arufah. Thus Joseph occupied himself with Torah just as his fathers did. Though the Torah had not yet been given, it is still written of Abraham, And he kept My charge, My commandments, My statutes, and My laws. There the Sages also said that Abraham observed the details of the Torah, which he taught to his children, etc.
The question presents itself: If it be the case [that the laws of the Torah were observed by our ancestors before the Torah was given on Sinai], how did Jacob erect a pillar and marry two sisters in their lifetime, and, in the opinion of our Rabbis, four sisters. Also, Amram [Moses’ father] married his aunt, and Moses our teacher erected twelve pillars. How then was it possible that they should be permissive in matters of Torah which Abraham their ancestor had prohibited on himself, and for which G-d appointed him reward, when he [Abraham] was wont to command his children and his household after him to walk in His ways? In the case of Jacob the Sages taught that he observed the Sabbath and established borders for Sabbath distances. In this matter of the Sabbath it is possible though that Jacob observed it because it is equal in importance to the entire Torah since it testifies to the act of Creation.
Perhaps then we should say that My charge refers to the Second Degree of marriages which were forbidden to the Sons of Noah; My commandments applies to robbery and murder; My statutes refers to the laws against eating a limb torn off from a live animal, as well as breeding mixed kinds of cattle or grafting together different species of trees; and My laws refer to civil statutes and the prohibitions against idol worship. The Sons of Noah were commanded concerning all of these matters, and Abraham observed and fulfilled the Will of his Creator, observing even the details and the strictures of their commandments, even as the Sages mentioned: “The tractate of idolatry of our father Abraham contained four hundred chapters.” They further expounded [on the verse referring to Isaac, which says], And he found in that year a hundredfold, that he measured the produce for the purpose of tithing, since the patriarchs were the generous ones of the peoples, giving tithes to the poor or the priests of G-d, such as Shem and Eber and their disciples, just as it is said, And he was a priest of the most high G-d.
Now it appears to me from a study of the opinions of our Rabbis that Abraham our father learned the entire Torah by Ruach Hakodesh and occupied himself with its study and the reason for its commandments and its secrets, and he observed it in its entirety as “one who is not commanded but nevertheless observes it.” Furthermore, his observance of the Torah applied only in the Land of Israel, whereas Jacob married two sisters only when outside the Land, and similarly with Amram who married his aunt. For the Commandments are the ordinance of the G-d of the land, even though we have been charged with personal duties in all places. Our Rabbis have already alluded to this secret, and I will yet call your attention to it with the help of G-d. And the matter of the erection of the pillar [by Jacob and Moses referred to above] was a commandment that was innovated at a certain time, as the Sages expounded from the verse, “Neither shalt thou set up a pillar which the Eternal thy G-d hateth, He hated it although it was pleasing to Him in the days of the ancestors.” And with respect to Joseph concerning whom the Sages expounded that he observed the Sabbath even in Egypt, it was because it is equal in importance to all the commandments, constituting, as it does, a testimony to Creatio ex nihilo. Therefore Joseph would do so in order to teach his children faith in the Creation of the world, to remove from their hearts the false doctrine of idolatry and the opinion of the Egyptians. This then is the intent [of the Sages when speaking of the patriarchs and their children observing the Torah].
In accordance with the literal meaning of Scripture, you may say that My charge means faith in the Deity, implying that Abraham believed in the unique Divine Name and kept vigilant guard over it in his heart, differing thereby with the worshippers of idols, and calling by the name of the Eternal to bring many to His worship. My commandments refers to all that G-d commanded Abraham: Go out of thy land, the bringing of his son as a burnt-offering, and the expulsion of the maid-servant and her son. My statutes refers to walking in the paths of G-d by being gracious and merciful, doing righteousness and judgment, and commanding his children and his household concerning them. And My Laws refers to the circumcision of Abraham himself and his sons and his servants, as well as all Commandments of the Sons of Noah which constitute their Law.
The Shem M’shmuel in Parshas Shmini offers another interpretation, that it means they kept the Torah in a different dimension, but not practically:
דהנה מה שאמרו שאברהם קיים את התורה כולה, שבודאי אין הפירוש במעשה המצוות כמו שהן עתה, שזה אי אפשר ברוב מצוות התורה כמובן, מה גם שרובן תלויין ביציאת מצרים, אלא הפירוש אור המצוות, כענין שבזוהר הקדש שיעקב קיים במקלות אשר פצל סוד התפילין, וממנו תקיש אל השאר, ועל דרך זה היה אפשר להם לקיים כל התורה, אך בכלים ולבושים שונים מאשר הם אחר נתינת התורה