Esempio n. 1
0
        public void EncapsulateTwoFields()
        {
            var text     = @"
class Program
{
    [|static int A = 1;
    static int B = A;|]
 
    static void Main(string[] args)
    {
        System.Console.WriteLine(A);
        System.Console.WriteLine(B);
    }
}
";
            var expected = @"
class Program
{
    static int A = 1;
    static int B = A1;

    public static int A1
    {
        get
        {
            return A;
        }

        set
        {
            A = value;
        }
    }

    public static int B1
    {
        get
        {
            return B;
        }

        set
        {
            B = value;
        }
    }

    static void Main(string[] args)
    {
        System.Console.WriteLine(A1);
        System.Console.WriteLine(B1);
    }
}
";

            using (var state = new EncapsulateFieldTestState(text))
            {
                state.AssertEncapsulateAs(expected);
            }
        }
        public void DialogShownIfNotFieldsFound()
        {
            var text = @"
class$$ C
{
    private int field;

    private void goo()
    {
        field = 3;
    }
}";

            using var state = EncapsulateFieldTestState.Create(text);
            state.AssertError();
        }
Esempio n. 3
0
        public async Task DialogShownIfNotFieldsFound()
        {
            var text = @"
class$$ C
{
    private int field;

    private void foo()
    {
        field = 3;
    }
}";

            using (var state = await EncapsulateFieldTestState.CreateAsync(text))
            {
                state.AssertError();
            }
        }
Esempio n. 4
0
        public void EncapsulateNonPrivateField()
        {
            var text     = @"
class C
{
    protected int fi$$eld;

    private void foo()
    {
        field = 3;
    }
}";
            var expected = @"
class C
{
    private int field;

    protected int Field
    {
        get
        {
            return field;
        }

        set
        {
            field = value;
        }
    }

    private void foo()
    {
        Field = 3;
    }
}";

            using (var state = new EncapsulateFieldTestState(text))
            {
                state.AssertEncapsulateAs(expected);
            }
        }
Esempio n. 5
0
        public void EncapsulatePrivateField()
        {
            var text     = @"
class C
{
    private int f$$ield;

    private void goo()
    {
        field = 3;
    }
}";
            var expected = @"
class C
{
    private int field;

    public int Field
    {
        get
        {
            return field;
        }

        set
        {
            field = value;
        }
    }

    private void goo()
    {
        Field = 3;
    }
}";

            using (var state = EncapsulateFieldTestState.Create(text))
            {
                state.AssertEncapsulateAs(expected);
            }
        }
        public void EncapsulatePrivateField()
        {
            var text = @"
class C
{
    private int f$$ield;

    private void foo()
    {
        field = 3;
    }
}";
            var expected = @"
class C
{
    private int field;

    public int Field
    {
        get
        {
            return field;
        }

        set
        {
            field = value;
        }
    }

    private void foo()
    {
        Field = 3;
    }
}";

            using (var state = new EncapsulateFieldTestState(text))
            {
                state.AssertEncapsulateAs(expected);
            }
        }
        public async Task EncapsulateNonPrivateField()
        {
            var text     = @"
class C
{
    protected int fi$$eld;

    private void goo()
    {
        field = 3;
    }
}";
            var expected = @"
class C
{
    private int field;

    protected int Field
    {
        get
        {
            return field;
        }

        set
        {
            field = value;
        }
    }

    private void goo()
    {
        Field = 3;
    }
}";

            using var state = EncapsulateFieldTestState.Create(text);
            await state.AssertEncapsulateAsAsync(expected);
        }
        public void EncapsulateTwoFields()
        {
            var text = @"
class Program
{
    [|static int A = 1;
    static int B = A;|]
 
    static void Main(string[] args)
    {
        System.Console.WriteLine(A);
        System.Console.WriteLine(B);
    }
}
";
            var expected = @"
class Program
{
    static int A = 1;
    static int B = A1;

    public static int A1
    {
        get
        {
            return A;
        }

        set
        {
            A = value;
        }
    }

    public static int B1
    {
        get
        {
            return B;
        }

        set
        {
            B = value;
        }
    }

    static void Main(string[] args)
    {
        System.Console.WriteLine(A1);
        System.Console.WriteLine(B1);
    }
}
";

            using (var state = new EncapsulateFieldTestState(text))
            {
                state.AssertEncapsulateAs(expected);
            }
        }
        public void DialogShownIfNotFieldsFound()
        {
            var text = @"
class$$ C
{
    private int field;

    private void foo()
    {
        field = 3;
    }
}";

            using (var state = new EncapsulateFieldTestState(text))
            {
                state.AssertError();
            }
        }