Example #1
0
        public void Koan04_delegate_have_invocation_list()
        {
            using (var console = new ConsoleCapture())
            {
                SayYourName sayYourName = _bastien.SayYourName;
                sayYourName += _emeric.SayYourName;

                sayYourName();

                console.ToString().Should().Be("FILL_ME_IN\n");
            }
        }
Example #2
0
        public void Koan06_events_are_delegates_with_restrictions()
        {
            using (var console = new ConsoleCapture())
            {
                var newBorn = new Person("baby");
                newBorn.NameChanged += (name) => Console.WriteLine($"{name} is born!");

                newBorn.SetName("Imen");

                console.ToString().Should().Be("FILL ME IN\n");

                // newBorn.NameChanged = (n) => { Console.WriteLine("you cannot affect an event with operator equal" );}
                // newBorn.NameChanged(); // you cannot invoke event from outside it class
            }
        }
Example #3
0
        public void Koan07_events_are_null_until_they_are_affected()
        {
            using (var console = new ConsoleCapture())
            {
                KoanFinished.Should().BeNull();
                KoanFinished += Finished;

                KoanFinished.Invoke();

                console.ToString().Should().Be("FILL ME IN\n");

                KoanFinished -= Finished;
                KoanFinished.Should().BeNull();
            }
        }