From ae5b27fd2f3b6c538d2632830bb03165f4d60b60 Mon Sep 17 00:00:00 2001 From: "jason.zhu" Date: Mon, 22 Feb 2021 10:11:30 +0000 Subject: [PATCH] Finished Defining a Delegate --- gradebook/test/GradeBook.Tests/TypeTests.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/gradebook/test/GradeBook.Tests/TypeTests.cs b/gradebook/test/GradeBook.Tests/TypeTests.cs index 7b63549..db76876 100644 --- a/gradebook/test/GradeBook.Tests/TypeTests.cs +++ b/gradebook/test/GradeBook.Tests/TypeTests.cs @@ -4,8 +4,26 @@ using Xunit; namespace GradeBook.Tests { using GradeBook; + + public delegate string WriteLogDelegate(string logMessage); + public class TypeTests { + [Fact] + public void WriteLogDelegateCanPointToMethod() + { + string msg = "test"; + + WriteLogDelegate log = new WriteLogDelegate(ReturnMessage); // Instantiate a delegate + var result = log(msg); // Invoking a delegate + Assert.Equal(result, msg); + } + + string ReturnMessage(string message) + { + return message; + } + [Fact] public void ValueTypesAlsoPassByValue() {