public void TestCreateMatchMethodsWhereClassIsInsideANamespace() { //Arrange var methodsClassCode = @"[CreateMatchMethods(typeof(SumType))] public static class Methods { }"; var expectedMethodsClassCodeAfterRefactoring = @"[CreateMatchMethods(typeof(SumType))] public static class Methods { public static TResult Match<TResult>(this Namespace1.SumType instance, System.Func<Namespace1.SumType.Option1, TResult> option1Case, System.Func<Namespace1.SumType.Option2, TResult> option2Case) { if (instance is Namespace1.SumType.Option1 option1) return option1Case(option1); if (instance is Namespace1.SumType.Option2 option2) return option2Case(option2); throw new System.Exception(""Invalid SumType type""); } public static void Match(this Namespace1.SumType instance, System.Action<Namespace1.SumType.Option1> option1Case, System.Action<Namespace1.SumType.Option2> option2Case) { if (instance is Namespace1.SumType.Option1 option1) { option1Case(option1); return; } if (instance is Namespace1.SumType.Option2 option2) { option2Case(option2); return; } throw new System.Exception(""Invalid SumType type""); } }"; var content = Utilities.InNamespace( Utilities.MergeParts(createMatchMethodsAttributeCode, sumTypeClassCode, methodsClassCode), "Namespace1"); var expectedContentAfterRefactoring = Utilities.NormalizeCode(Utilities.InNamespace( Utilities.MergeParts(createMatchMethodsAttributeCode, sumTypeClassCode, expectedMethodsClassCodeAfterRefactoring), "Namespace1")); //Act var actualContentAfterRefactoring = Utilities.NormalizeCode(Utilities.ApplyRefactoring(content, SelectSpanWhereCreateMatchMethodsAttributeIsApplied)); //Assert Assert.AreEqual(expectedContentAfterRefactoring, actualContentAfterRefactoring); }
public void TestCreateWithMethodsWhereClassIsInsideANamespace() { //Arrange var methodsClassCode = @"[CreateWithMethods(typeof(ProductType))] public static class Methods { }"; var expectedMethodsClassCodeAfterRefactoring = @"[CreateWithMethods(typeof(ProductType))] public static class Methods { public static Namespace1.ProductType WithAge(this Namespace1.ProductType instance, System.Int32 newValue) { return new Namespace1.ProductType(age: newValue, name: instance.Name); } public static Namespace1.ProductType WithName(this Namespace1.ProductType instance, System.String newValue) { return new Namespace1.ProductType(age: instance.Age, name: newValue); } }"; var content = Utilities.InNamespace( Utilities.MergeParts( createWithMethodsAttributeCode, productTypeClassCode, methodsClassCode), "Namespace1"); var expectedContentAfterRefactoring = Utilities.NormalizeCode( Utilities.InNamespace( Utilities.MergeParts( createWithMethodsAttributeCode, productTypeClassCode, expectedMethodsClassCodeAfterRefactoring), "Namespace1")); //Act var actualContentAfterRefactoring = Utilities.NormalizeCode( Utilities.ApplyRefactoring( content, SelectSpanWhereCreateWithMethodsAttributeIsApplied)); //Assert Assert.AreEqual(expectedContentAfterRefactoring, actualContentAfterRefactoring); }