public async Task TestAttributeReplacedWithFact()
        {
            var source =
                @"using NUnit.Framework;

namespace NUnitToXUnitTests
{
    public class UnitTests
    {
        [Test]
        public void Test1()
        {
        }
    }
}";

            var fixtest =
                @"using Xunit;

namespace NUnitToXUnitTests
{
    public class UnitTests
    {
        [Fact]
        public void Test1()
        {
        }
    }
}";

            var expected = Verify.Diagnostic("NXunitConverterAnalyzer").WithLocation(7, 9).WithArguments("Test1");
            await VerifyCodeFix.VerifyFixAsync(source, fixtest, expected);
        }
        public async Task NotZero()
        {
            var source =
                @"using NUnit.Framework;

namespace NUnitToXUnitTests
{
    public class UnitTests
    {
        [Test]
        public void TestAssertNotZero()
        {
            Assert.NotZero(1);
        }
    }
}";

            var fixtest =
                @"using Xunit;

namespace NUnitToXUnitTests
{
    public class UnitTests
    {
        [Fact]
        public void TestAssertNotZero()
        {
            Assert.NotEqual(0, 1);
        }
    }
}";

            var expected = Verify.Diagnostic("NXunitConverterAnalyzer").WithLocation(7, 9).WithArguments("TestAssertNotZero");
            await VerifyCodeFix.VerifyFixAsync(source, fixtest, expected);
        }
        public async Task IsNotNull()
        {
            var source =
                @"using NUnit.Framework;

namespace NUnitToXUnitTests
{
    public class UnitTests
    {
        [Test]
        public void TestAssertNull()
        {
            Assert.IsNotNull(new object(), ""some message"");
        }
    }
}";

            var fixtest =
                @"using Xunit;

namespace NUnitToXUnitTests
{
    public class UnitTests
    {
        [Fact]
        public void TestAssertNull()
        {
            Assert.NotNull(new object());
        }
    }
}";

            var expected = Verify.Diagnostic("NXunitConverterAnalyzer").WithLocation(7, 9).WithArguments("TestAssertNull");
            await VerifyCodeFix.VerifyFixAsync(source, fixtest, expected);
        }
Пример #4
0
        public async Task ThatBoolWithMessage()
        {
            var source =
                @"using NUnit.Framework;

namespace NUnitToXUnitTests
{
    public class UnitTests
    {
        [Test]
        public void TestAssertThat()
        {
            Assert.That(true, ""error"", ""param"");
        }
    }
}";

            var fixtest =
                @"using Xunit;

namespace NUnitToXUnitTests
{
    public class UnitTests
    {
        [Fact]
        public void TestAssertThat()
        {
            Assert.True(true);
        }
    }
}";

            var expected = Verify.Diagnostic("NXunitConverterAnalyzer").WithLocation(7, 9).WithArguments("TestAssertThat");
            await VerifyCodeFix.VerifyFixAsync(source, fixtest, expected);
        }
        public async Task FalseWithMessage()
        {
            var source =
                @"using NUnit.Framework;

namespace NUnitToXUnitTests
{
    public class UnitTests
    {
        [Test]
        public void TestAssertFalse()
        {
            Assert.False(false, ""should be ok"", ""param"");
        }
    }
}";

            var fixtest =
                @"using Xunit;

namespace NUnitToXUnitTests
{
    public class UnitTests
    {
        [Fact]
        public void TestAssertFalse()
        {
            Assert.False(false, ""should be ok"");
        }
    }
}";

            var expected = Verify.Diagnostic("NXunitConverterAnalyzer").WithLocation(7, 9).WithArguments("TestAssertFalse");
            await VerifyCodeFix.VerifyFixAsync(source, fixtest, expected);
        }
Пример #6
0
        public async Task AssertContainsWithMessage()
        {
            var source =
                @"using NUnit.Framework;

namespace NUnitToXUnitTests
{
    public class UnitTests
    {
        [Test]
        public void TestAssertContains()
        {
            Assert.Contains(5, new[] { 1, 3, 5, 7 }, ""some message"");
        }
    }
}";

            var fixtest =
                @"using Xunit;

namespace NUnitToXUnitTests
{
    public class UnitTests
    {
        [Fact]
        public void TestAssertContains()
        {
            Assert.Contains(5, new[] { 1, 3, 5, 7 });
        }
    }
}";

            var expected = Verify.Diagnostic("NXunitConverterAnalyzer").WithLocation(7, 9).WithArguments("TestAssertContains");
            await VerifyCodeFix.VerifyFixAsync(source, fixtest, expected);
        }
Пример #7
0
        public async Task IsEmptyString()
        {
            var source =
                @"using NUnit.Framework;

namespace NUnitToXUnitTests
{
    public class UnitTests
    {
        [Test]
        public void TestAssertEmpty()
        {
            Assert.IsEmpty("""");
        }
    }
}";

            var fixtest =
                @"using Xunit;

namespace NUnitToXUnitTests
{
    public class UnitTests
    {
        [Fact]
        public void TestAssertEmpty()
        {
            Assert.Equal(string.Empty, """");
        }
    }
}";

            var expected = Verify.Diagnostic("NXunitConverterAnalyzer").WithLocation(7, 9).WithArguments("TestAssertEmpty");
            await VerifyCodeFix.VerifyFixAsync(source, fixtest, expected);
        }
Пример #8
0
        public async Task TestCaseSourceAndTestAttributeReplacedWithMemberData()
        {
            var source =
                @"using NUnit.Framework;
using System.Collections.Generic;

namespace NUnitToXUnitTests
{
    public class UnitTests
    {
        public static IEnumerable<TestCaseData> TestData
        {
            get
            {
                yield return new TestCaseData(""v"", 3);
                yield return new TestCaseData(""a"", 2);
                yield return new TestCaseData(""l"", 4);
            }
        }

        [Test]
        [TestCaseSource(nameof(TestData))]
        public void TestCaseSource(string value, int value2)
        {
        }
    }
}";

            var fixtest =
                @"using Xunit;
using System.Collections.Generic;

namespace NUnitToXUnitTests
{
    public class UnitTests
    {
        public static IEnumerable<object[]> TestData
        {
            get
            {
                yield return new object[] { ""v"", 3 };
                yield return new object[] { ""a"", 2 };
                yield return new object[] { ""l"", 4 };
            }
        }

        [Theory]
        [MemberData(nameof(TestData))]
        public void TestCaseSource(string value, int value2)
        {
        }
    }
}";

            var expected = Verify.Diagnostic("NXunitConverterAnalyzer").WithLocation(18, 9).WithArguments("TestCaseSource");
            await VerifyCodeFix.VerifyFixAsync(source, fixtest, expected);
        }
Пример #9
0
        public async Task TearDown_Converted_Dispose()
        {
            var source =
                @"using NUnit.Framework;

namespace NUnitToXUnitTests
{
    public class MyTestClass
    {
        private bool _param;
        [TearDown]
        public void TearDown()
        {
            _param = true;
        }

        [Test]
        public void Test()
        {
            Assert.True(_param);
        }
    }
}";


            var fixtest =
                @"using System;
using Xunit;

namespace NUnitToXUnitTests
{
    public class MyTestClass
: IDisposable
    {
        private bool _param;

        public void Dispose()
        {
            _param = true;
        }

        [Fact]
        public void Test()
        {
            Assert.True(_param);
        }
    }
}";
            var expected = Verify.Diagnostic("NXunitConverterAnalyzer").WithLocation(14, 9).WithArguments("Test");
            await VerifyCodeFix.VerifyFixAsync(source, fixtest, expected);
        }
        public async Task SetUp_Converted_Ctor()
        {
            var source =
                @"using NUnit.Framework;

namespace NUnitToXUnitTests
{
    public class MyTestClass
    {
        private bool _param;
        [SetUp]
        public void Setup()
        {
            _param = true;
        }

        [Test]
        public void Test()
        {
            Assert.True(_param);
        }
    }
}";


            var fixtest =
                @"using Xunit;

namespace NUnitToXUnitTests
{
    public class MyTestClass
    {
        private bool _param;

        public MyTestClass()
        {
            _param = true;
        }

        [Fact]
        public void Test()
        {
            Assert.True(_param);
        }
    }
}";
            var expected = Verify.Diagnostic("NXunitConverterAnalyzer").WithLocation(14, 9).WithArguments("Test");
            await VerifyCodeFix.VerifyFixAsync(source, fixtest, expected);
        }
Пример #11
0
        public async Task ThrowsAsyncBlock()
        {
            var source =
                @"using NUnit.Framework;
using System;
using System.Threading.Tasks;

namespace NUnitToXUnitTests
{
    public class UnitTests
    {
        [Test]
        public async Task TestAssertThrowsAsync()
        {
            await Task.Yield();
            Assert.ThrowsAsync<Exception>(async () =>
            {
                throw new Exception();
            }, ""some message"");
        }
    }
}";

            var fixtest =
                @"using Xunit;
using System;
using System.Threading.Tasks;

namespace NUnitToXUnitTests
{
    public class UnitTests
    {
        [Fact]
        public async Task TestAssertThrowsAsync()
        {
            await Task.Yield();
            await Assert.ThrowsAsync<Exception>(async () =>
            {
                throw new Exception();
            });
        }
    }
}";

            var expected = Verify.Diagnostic("NXunitConverterAnalyzer").WithLocation(9, 9).WithArguments("TestAssertThrowsAsync");
            await VerifyCodeFix.VerifyFixAsync(source, fixtest, expected);
        }
Пример #12
0
        public async Task DoesNotThrowAsyncBlock()
        {
            var source =
                @"using NUnit.Framework;
using System;
using System.Threading.Tasks;

namespace NUnitToXUnitTests
{
    public class UnitTests
    {
        [Test]
        public async Task TestAssertNotThrowsAsync()
        {
            Assert.DoesNotThrowAsync(async () =>
            {
                await Task.Yield();
                Console.WriteLine(""hello"");
                Console.WriteLine(""world"");
            });
        }
    }
}";

            var fixtest =
                @"using Xunit;
using System;
using System.Threading.Tasks;

namespace NUnitToXUnitTests
{
    public class UnitTests
    {
        [Fact]
        public async Task TestAssertNotThrowsAsync()
        {
            await Task.Yield();
            Console.WriteLine(""hello"");
            Console.WriteLine(""world"");
        }
    }
}";

            var expected = Verify.Diagnostic("NXunitConverterAnalyzer").WithLocation(9, 9).WithArguments("TestAssertNotThrowsAsync");
            await VerifyCodeFix.VerifyFixAsync(source, fixtest, expected);
        }
Пример #13
0
        public async Task DoesNotThrowWithContextAround()
        {
            var source =
                @"using NUnit.Framework;
using System;

namespace NUnitToXUnitTests
{
    public class UnitTests
    {
        [Test]
        public void TestAssertNotThrows()
        {
            int i = 0;
            Assert.DoesNotThrow(() =>
            {
                Console.WriteLine(""hello"");
                Console.WriteLine(""world"");
            });
            i++;
        }
    }
}";

            var fixtest =
                @"using Xunit;
using System;

namespace NUnitToXUnitTests
{
    public class UnitTests
    {
        [Fact]
        public void TestAssertNotThrows()
        {
            int i = 0;
            Console.WriteLine(""hello"");
            Console.WriteLine(""world"");
            i++;
        }
    }
}";

            var expected = Verify.Diagnostic("NXunitConverterAnalyzer").WithLocation(8, 9).WithArguments("TestAssertNotThrows");
            await VerifyCodeFix.VerifyFixAsync(source, fixtest, expected);
        }
Пример #14
0
        public async Task IsNotEmptyCollection()
        {
            var source =
                @"using NUnit.Framework;
using System.Collections.Generic;

namespace NUnitToXUnitTests
{
    public class UnitTests
    {
        [Test]
        public void TestAssertNotEmpty()
        {
            Assert.IsNotEmpty(new List<object>());
        }
    }
}";

            var fixtest =
                @"using Xunit;
using System.Collections.Generic;

namespace NUnitToXUnitTests
{
    public class UnitTests
    {
        [Fact]
        public void TestAssertNotEmpty()
        {
            Assert.NotEmpty(new List<object>());
        }
    }
}";


            var expected = Verify.Diagnostic("NXunitConverterAnalyzer").WithLocation(8, 9).WithArguments("TestAssertNotEmpty");
            await VerifyCodeFix.VerifyFixAsync(source, fixtest, expected);
        }
Пример #15
0
        public async Task ThrowsBlock()
        {
            var source =
                @"using NUnit.Framework;
using System;

namespace NUnitToXUnitTests
{
    public class UnitTests
    {
        [Test]
        public void TestAssertThrows()
        {
            Assert.Throws<Exception>(() => { throw new Exception(); }, ""some message"");
        }
    }
}";

            var fixtest =
                @"using Xunit;
using System;

namespace NUnitToXUnitTests
{
    public class UnitTests
    {
        [Fact]
        public void TestAssertThrows()
        {
            Assert.Throws<Exception>(new Action(() => { throw new Exception(); }));
        }
    }
}";

            var expected = Verify.Diagnostic("NXunitConverterAnalyzer").WithLocation(8, 9).WithArguments("TestAssertThrows");
            await VerifyCodeFix.VerifyFixAsync(source, fixtest, expected);
        }
        public async Task TestAndTestCaseAttributeReplacedWithInlineData()
        {
            var source =
                @"using NUnit.Framework;

namespace NUnitToXUnitTests
{
    public class UnitTests
    {
        [Test]
        [TestCase(""value"")]
        [TestCase(""value1"")]
        public void TestCase(string value)
        {
        }
    }
}";

            var fixtest =
                @"using Xunit;

namespace NUnitToXUnitTests
{
    public class UnitTests
    {
        [Theory]
        [InlineData(""value"")]
        [InlineData(""value1"")]
        public void TestCase(string value)
        {
        }
    }
}";

            var expected = Verify.Diagnostic("NXunitConverterAnalyzer").WithLocation(7, 9).WithArguments("TestCase");
            await VerifyCodeFix.VerifyFixAsync(source, fixtest, expected);
        }
Пример #17
0
        public async Task ThatIsTypeOfToDelegete()
        {
            var source =
                @"using NUnit.Framework;
using System;

namespace NUnitToXUnitTests
{
    public class UnitTests
    {
        [Test]
        public void TestAssertThat()
        {
            Assert.That(() => 5, Is.TypeOf<int>());
        }
    }
}";

            var fixtest =
                @"using Xunit;
using System;

namespace NUnitToXUnitTests
{
    public class UnitTests
    {
        [Fact]
        public void TestAssertThat()
        {
            Assert.IsType<int>(new Func<Int32>(() => 5).Invoke());
        }
    }
}";

            var expected = Verify.Diagnostic("NXunitConverterAnalyzer").WithLocation(8, 9).WithArguments("TestAssertThat");
            await VerifyCodeFix.VerifyFixAsync(source, fixtest, expected);
        }
Пример #18
0
        public async Task ThatIsEmpty()
        {
            var source =
                @"using NUnit.Framework;
using System;

namespace NUnitToXUnitTests
{
    public class UnitTests
    {
        [Test]
        public void TestAssertThat()
        {
            Assert.That(new int[] { }, Is.Empty);
        }
    }
}";

            var fixtest =
                @"using Xunit;
using System;

namespace NUnitToXUnitTests
{
    public class UnitTests
    {
        [Fact]
        public void TestAssertThat()
        {
            Assert.Empty(new int[] { });
        }
    }
}";

            var expected = Verify.Diagnostic("NXunitConverterAnalyzer").WithLocation(8, 9).WithArguments("TestAssertThat");
            await VerifyCodeFix.VerifyFixAsync(source, fixtest, expected);
        }
Пример #19
0
        public async Task ThatIsNotFalse()
        {
            var source =
                @"using NUnit.Framework;
using System;

namespace NUnitToXUnitTests
{
    public class UnitTests
    {
        [Test]
        public void TestAssertThat()
        {
            Assert.That(true, Is.Not.False.And.TypeOf<bool>());
        }
    }
}";

            var fixtest =
                @"using Xunit;
using System;

namespace NUnitToXUnitTests
{
    public class UnitTests
    {
        [Fact]
        public void TestAssertThat()
        {
            Assert.True(true);
        }
    }
}";

            var expected = Verify.Diagnostic("NXunitConverterAnalyzer").WithLocation(8, 9).WithArguments("TestAssertThat");
            await VerifyCodeFix.VerifyFixAsync(source, fixtest, expected);
        }
Пример #20
0
        public async Task ThatThrowsArgumentNullExceptionWithDetails()
        {
            var source =
                @"using NUnit.Framework;
using System;

namespace NUnitToXUnitTests
{
    public class UnitTests
    {
        [Test]
        public void TestAssertThat()
        {
            Assert.That(() => throw new ArgumentNullException(), Throws.ArgumentNullException.With.Message.Not.Null);
        }
    }
}";

            var fixtest =
                @"using Xunit;
using System;

namespace NUnitToXUnitTests
{
    public class UnitTests
    {
        [Fact]
        public void TestAssertThat()
        {
            Assert.Throws<ArgumentNullException>(new Action(() => throw new ArgumentNullException()));
        }
    }
}";

            var expected = Verify.Diagnostic("NXunitConverterAnalyzer").WithLocation(8, 9).WithArguments("TestAssertThat");
            await VerifyCodeFix.VerifyFixAsync(source, fixtest, expected);
        }
Пример #21
0
        public async Task ThatThrowsNothing()
        {
            var source =
                @"using NUnit.Framework;
using System;

namespace NUnitToXUnitTests
{
    public class UnitTests
    {
        [Test]
        public void TestAssertThat()
        {
            Assert.That(() => Console.WriteLine(""hello""), Throws.Nothing);
        }
    }
}";

            var fixtest =
                @"using Xunit;
using System;

namespace NUnitToXUnitTests
{
    public class UnitTests
    {
        [Fact]
        public void TestAssertThat()
        {
            new Action(() => Console.WriteLine(""hello"")).Invoke();
        }
    }
}";

            var expected = Verify.Diagnostic("NXunitConverterAnalyzer").WithLocation(8, 9).WithArguments("TestAssertThat");
            await VerifyCodeFix.VerifyFixAsync(source, fixtest, expected);
        }
        public async Task IsNotInstanceOfTest()
        {
            var source =
                @"using NUnit.Framework;
using System;

namespace NUnitToXUnitTests
{
    public class UnitTests
    {
        [Test]
        public void TestAssertIsNotInstanceOf()
        {
            Assert.IsNotInstanceOf<ArgumentNullException>(new Exception());
        }
    }
}";

            var fixtest =
                @"using Xunit;
using System;

namespace NUnitToXUnitTests
{
    public class UnitTests
    {
        [Fact]
        public void TestAssertIsNotInstanceOf()
        {
            Assert.False(new Exception() is ArgumentNullException);
        }
    }
}";

            var expected = Verify.Diagnostic("NXunitConverterAnalyzer").WithLocation(8, 9).WithArguments("TestAssertIsNotInstanceOf");
            await VerifyCodeFix.VerifyFixAsync(source, fixtest, expected);
        }
Пример #23
0
        public async Task ThatBoolFuncErrorDelegate()
        {
            var source =
                @"using NUnit.Framework;
using System;

namespace NUnitToXUnitTests
{
    public class UnitTests
    {
        [Test]
        public void TestAssertThat()
        {
            Assert.That(() => true, () => ""error"");
        }
    }
}";

            var fixtest =
                @"using Xunit;
using System;

namespace NUnitToXUnitTests
{
    public class UnitTests
    {
        [Fact]
        public void TestAssertThat()
        {
            Assert.True(new Func<Boolean>(() => true).Invoke());
        }
    }
}";

            var expected = Verify.Diagnostic("NXunitConverterAnalyzer").WithLocation(8, 9).WithArguments("TestAssertThat");
            await VerifyCodeFix.VerifyFixAsync(source, fixtest, expected);
        }
        public async Task IsAssignableFromTest()
        {
            var source =
                @"using NUnit.Framework;
using System;

namespace NUnitToXUnitTests
{
    public class UnitTests
    {
        [Test]
        public void TestAssertIsAssignableFrom()
        {
            Assert.IsAssignableFrom<ArgumentNullException>(new Exception(), ""some message"");
        }
    }
}";

            var fixtest =
                @"using Xunit;
using System;

namespace NUnitToXUnitTests
{
    public class UnitTests
    {
        [Fact]
        public void TestAssertIsAssignableFrom()
        {
            Assert.True(new Exception().GetType().IsAssignableFrom(typeof(ArgumentNullException)));
        }
    }
}";

            var expected = Verify.Diagnostic("NXunitConverterAnalyzer").WithLocation(8, 9).WithArguments("TestAssertIsAssignableFrom");
            await VerifyCodeFix.VerifyFixAsync(source, fixtest, expected);
        }