public Task InvokeCallsWriter() { const string value = "test"; var helpWriterMock = new Mock <IHelpWriter>(); helpWriterMock.Setup(m => m.WriteContent(It.IsAny <IReadOnlyCollection <string> >())) .Callback <IReadOnlyCollection <string> >(content => content.Single().ShouldBe(value)); var providerMock = new Mock <IProvider <IReadOnlyCollection <string> > >(); providerMock.Setup(m => m.GetInstance()).Returns(new[] { value }); var helpProgram = new HelpProgram(helpWriterMock.Object, providerMock.Object); helpProgram.Invoke(null !); return(helpProgram.InvokeAsync(null !, CancellationToken.None)); }
static void Exo02_14() { Point po = new Point(3, 3); WriteLine($"{po.X} {po.Y}"); HelpProgram.Exo02_14BadFonc(po); po.Translate(2, 2); //** WriteLine($"{po.X} {po.Y}"); //1. 'Point' class is not immutable because the method 'Exo02_14BadFonc()' that itself calls the method 'Translate()'can change the axis values of a Point, which makes this class mutable. Circle ce = new Circle(2, po); WriteLine($"{ce.Centre.X} {ce.Centre.Y}"); HelpProgram.Exo02_14BadFonc2(ce); ce.Centre.Translate(1, 1); WriteLine($"{ce.Centre.X} {ce.Centre.Y}"); //2. As the circle includes a Point object as one of its members, that makes this class mutable too, even if it is a structure. ReadKey(true); //3. If we change the class Point for a Structure, it will make this object immutable before methods but it's still mutable. //Exo02_15 This is because of the "Translate" member function, which uses the same instance of the object changing it's values, as we can see in ** comment. //To make this an immutable structure, we have to make the "Translate" function create and return a new instance of the object. }