public static void CodeFixAddingDocumentWhenExpectedAddedDocIsNotProvided() { var before = @" namespace N { class C { public static C Create() => ↓new C(); } }"; var after = @" namespace N { class C { public static C Create() => new C().Id(); } }"; var analyzer = new CallIdAnalyzer(); var fix = new CallIdFix(); var exception = Assert.Throws <AssertException>(() => RoslynAssert.CodeFix(analyzer, fix, before, after)); CodeAssert.AreEqual("Expected 1 documents the fixed solution has 2 documents.", exception.Message); exception = Assert.Throws <AssertException>(() => RoslynAssert.CodeFix(analyzer, fix, new[] { before }, after)); CodeAssert.AreEqual("Expected 1 documents the fixed solution has 2 documents.", exception.Message); exception = Assert.Throws <AssertException>(() => RoslynAssert.CodeFix(analyzer, fix, new[] { before }, new[] { after })); CodeAssert.AreEqual("Expected 1 documents the fixed solution has 2 documents.", exception.Message); }
public static void CodeFixAddingDocument() { var before = @" namespace N { class C { public static C Create() => ↓new C(); } }"; var after = @" namespace N { class C { public static C Create() => new C().Id(); } }"; var extensionMethodCode = @"namespace N { public static class Extensions { public static T Id<T>(this T t) => t; } }"; var analyzer = new CallIdAnalyzer(); var fix = new CallIdFix(); RoslynAssert.CodeFix(analyzer, fix, new[] { before }, new[] { after, extensionMethodCode }); RoslynAssert.CodeFix(analyzer, fix, new[] { before }, new[] { after, extensionMethodCode }, fixTitle: "Call ID()"); }
public static void CodeFixAddingDocument() { var before = @" namespace N { class C { public static C Create() => ↓new C(); } }"; var after = @" namespace N { class C { public static C Create() => new C().Id(); } }"; var extensionMethodCode = @"namespace N { public static class Extensions { } }"; var analyzer = new CallIdAnalyzer(); var fix = new CallIdFix(); var expected = "Mismatch on line 5 of file Extensions.cs.\r\n" + "Expected: }\r\n" + "Actual: public static T Id<T>(this T t) => t;\r\n" + " ^\r\n" + "Expected:\r\n" + "namespace N\r\n" + "{\r\n" + " public static class Extensions\r\n" + " {\r\n" + " }\r\n" + "}\r\n" + "Actual:\r\n" + "namespace N\r\n" + "{\r\n" + " public static class Extensions\r\n" + " {\r\n" + " public static T Id<T>(this T t) => t;\r\n" + " }\r\n" + "}\r\n"; var exception = Assert.Throws <AssertException>(() => RoslynAssert.CodeFix(analyzer, fix, new[] { before }, new[] { after, extensionMethodCode })); CodeAssert.AreEqual(expected, exception.Message); exception = Assert.Throws <AssertException>(() => RoslynAssert.CodeFix(analyzer, fix, new[] { before }, new[] { after, extensionMethodCode })); CodeAssert.AreEqual(expected, exception.Message); exception = Assert.Throws <AssertException>(() => RoslynAssert.CodeFix(analyzer, fix, new[] { before }, new[] { after, extensionMethodCode }, fixTitle: "Call ID()")); CodeAssert.AreEqual(expected, exception.Message); exception = Assert.Throws <AssertException>(() => RoslynAssert.CodeFix(analyzer, fix, new[] { before }, new[] { after, extensionMethodCode }, fixTitle: "Call ID()")); CodeAssert.AreEqual(expected, exception.Message); extensionMethodCode = @"namespace N { public static class Extensions { public static T Id<T>(this T t) => t; } }"; expected = "Mismatch on line 6 of file C.cs.\r\n" + "Expected: public static C Create() => ↓new C();\r\n" + "Actual: public static C Create() => new C().Id();\r\n" + " ^\r\n" + "Expected:\r\n" + "\r\n" + "namespace N\r\n" + "{\r\n" + " class C\r\n" + " {\r\n" + " public static C Create() => ↓new C();\r\n" + " }\r\n" + "}\r\n" + "Actual:\r\n" + "\r\n" + "namespace N\r\n" + "{\r\n" + " class C\r\n" + " {\r\n" + " public static C Create() => new C().Id();\r\n" + " }\r\n" + "}\r\n"; exception = Assert.Throws <AssertException>(() => RoslynAssert.CodeFix(analyzer, fix, new[] { before }, new[] { before, extensionMethodCode })); CodeAssert.AreEqual(expected, exception.Message); exception = Assert.Throws <AssertException>(() => RoslynAssert.CodeFix(analyzer, fix, new[] { before }, new[] { before, extensionMethodCode })); CodeAssert.AreEqual(expected, exception.Message); exception = Assert.Throws <AssertException>(() => RoslynAssert.CodeFix(analyzer, fix, new[] { before }, new[] { before, extensionMethodCode }, fixTitle: "Call ID()")); CodeAssert.AreEqual(expected, exception.Message); exception = Assert.Throws <AssertException>(() => RoslynAssert.CodeFix(analyzer, fix, new[] { before }, new[] { before, extensionMethodCode }, fixTitle: "Call ID()")); CodeAssert.AreEqual(expected, exception.Message); }