public void RespectExistingCustomInterfaceIImplementation() { var tb = new GeneratorTestBed(new INPCGenerator(), $@"namespace NS {{ public interface INot:INotifyPropertyChanged{{ void OnPropertyChanged(string name); }} public partial class C:INot {{ void INot.OnPropertyChanged(string name){{}} private int intProp; [Melville.INPC.AutoNotifyAttribute] private int ip2; }}}}"); tb.AssertNoDiagnostics(); tb.FileContains("C.INPC.cs", "((NS.INot)this).OnPropertyChanged(\"Ip2\")"); tb.FileDoesNotContain("C.INPC.cs", "void NS.INot.OnPropertyChanged(string"); tb.FileDoesNotContain("C.INPC.cs", "IExternalNotifyPropertyChange"); }
public void IncludeAttribute() { var tb = new GeneratorTestBed(new INPCGenerator(), @"using Melville.INPC; using System.Collections.Generic; public partial class C { [AutoNotify(Attributes=""[NewProp(1)]"")]private int integer; }"); tb.AssertNoDiagnostics(); tb.FileContains("C.INPC.cs", "[NewProp(1)]\r\n public int Integer"); tb.FileDoesNotContain("C.INPC.cs", "[AutoNotify]"); }
public void UseExistingNotifyMethod() { var tb = new GeneratorTestBed(new INPCGenerator(), @" public partial class C { public void OnPropertyChanged(string name){} private int intProp; [Melville.INPC.AutoNotifyAttribute] private int ip2; }"); tb.AssertNoDiagnostics(); tb.FileDoesNotContain("C.INPC.cs", "IExternalNotifyPropertyChange"); }
public void AllowExplicitAttribute() { var tb = new GeneratorTestBed(new INPCGenerator(), @" public partial class C { private int intProp; [Melville.INPC.AutoNotifyAttribute] private int ip2; }"); tb.AssertNoDiagnostics(); tb.FileContains("C.INPC.cs", "public int Ip2"); tb.FileDoesNotContain("C.INPC.cs", "public int IntProp"); }
public void DoNotPropegateOtherCalls() { var tb = new GeneratorTestBed(new INPCGenerator(), @"using Melville.INPC; public partial class ImplementInheritedINPC { protected void OnPropertyChanged(string property) {} [AutoNotify] private int y; private ImplementInheritedINPC other; [AutoNotify] public int FindY {get {return other?.Y;}} }"); tb.FileDoesNotContain("ImplementInheritedINPC.INPC.cs", @"OnPropertyChanged(""FindY"");"); }
void DoNotTouchUnmarkedField() { var tb = new GeneratorTestBed(new INPCGenerator(), @" using Melville.INPC; public partial class C { private int intProp; [AutoNotify] private int ip2; }"); tb.AssertNoDiagnostics(); tb.FileContains("C.INPC.cs", "public int Ip2"); tb.FileDoesNotContain("C.INPC.cs", "public int IntProp"); }
public void ElaborateMarkedClass() { var tb = new GeneratorTestBed(new INPCGenerator(), @" using Melville.INPC; [AutoNotify] public partial class C { private int intProp,ip2; }"); tb.AssertNoDiagnostics(); tb.FileDoesNotContain("C.INPC.cs", "AutoNotify"); tb.FileContains("C.INPC.cs", "void Melville.INPC.IExternalNotifyPropertyChanged.OnPropertyChanged(string propertyName)"); }
public void OnPropertyChanged(string methodDecl, string included, string excluded) { var tb = new GeneratorTestBed(new INPCGenerator(), $@" using Melville.INPC; namespace NM {{ public class C {{ {methodDecl} [AutoNotify] private int ip; }} }}"); tb.FileContains("C.INPC.cs", included); tb.FileDoesNotContain("C.INPC.cs", excluded); }
public void ImplementCustomInterface() { var tb = new GeneratorTestBed(new INPCGenerator(), $@" public interface INot:INotifyPropertyChanged{{ public void OnPropertyChanged(string name); }} public partial class C:INot {{ private int intProp; [Melville.INPC.AutoNotifyAttribute] private int ip2; }}"); tb.AssertNoDiagnostics(); tb.FileContains("C.INPC.cs", "void INot.OnPropertyChanged(string"); tb.FileDoesNotContain("C.INPC.cs", "IExternalNotifyPropertyChange"); }
public void UseInheritedInterfaceMethod() { var tb = new GeneratorTestBed(new INPCGenerator(), $@" namespace NS {{ public interface I {{ void OnPropertyChanged(string name);}} public class A: I {{ void I.OnPropertyChanged(string name){{}} }} public partial class C: A {{ private int intProp; [Melville.INPC.AutoNotifyAttribute] private int ip2; }}}}"); tb.AssertNoDiagnostics(); tb.FileDoesNotContain("C.INPC.cs", "IExternalNotifyPropertyChange"); tb.FileContains("C.INPC.cs", "((NS.I)this).OnPropertyChanged"); }