public void AccountsForHungarianNamesAndMemberPrefix(string inputName, string expectedPropertyName, string expectedFieldName)
        {
            var sut = new EncapsulationIdentifiers(inputName);

            Assert.AreEqual(expectedPropertyName, sut.DefaultPropertyName);
            Assert.AreEqual(expectedFieldName, sut.DefaultNewFieldName);
        }
        public void EncapsulatePublicField_FieldHasReferences()
        {
            var inputCode =
                @"|Public fizz As Integer

Sub Foo()
    fizz = 0
    Bar fizz
End Sub

Sub Bar(ByVal name As Integer)
End Sub";

            var presenterAction = Support.SetParametersForSingleTarget("fizz", "Name");

            var enapsulationIdentifiers = new EncapsulationIdentifiers("fizz")
            {
                Property = "Name"
            };

            var actualCode = Support.RefactoredCode(inputCode.ToCodeString(), presenterAction);

            StringAssert.AreEqualIgnoringCase(enapsulationIdentifiers.TargetFieldName, "fizz");
            StringAssert.Contains($"Private {enapsulationIdentifiers.TargetFieldName} As Integer", actualCode);
            StringAssert.Contains("Property Get Name", actualCode);
            StringAssert.Contains("Property Let Name", actualCode);
            StringAssert.Contains($"Name = {enapsulationIdentifiers.TargetFieldName}", actualCode);
            StringAssert.Contains($"{enapsulationIdentifiers.TargetFieldName} = {Support.RHSIdentifier}", actualCode);
        }
        public TestEncapsulationAttributes(string fieldName, bool encapsulationFlag = true, bool isReadOnly = false)
        {
            var validator = EncapsulateFieldValidationsProvider.NameOnlyValidator(NameValidators.Default);

            _identifiers    = new EncapsulationIdentifiers(fieldName, validator);
            EncapsulateFlag = encapsulationFlag;
            IsReadOnly      = isReadOnly;
        }
        public void AccountsForHungarianNamesAndMemberPrefix(string inputName, string expectedPropertyName, string expectedFieldName)
        {
            var validator = EncapsulateFieldValidationsProvider.NameOnlyValidator(NameValidators.Default);
            var sut       = new EncapsulationIdentifiers(inputName, validator);

            Assert.AreEqual(expectedPropertyName, sut.DefaultPropertyName);
            Assert.AreEqual(expectedFieldName, sut.DefaultNewFieldName);
        }
        public void UserDefinedType_TwoFields(bool encapsulateThis, bool encapsulateThat)
        {
            string inputCode =
                $@"
Private Type TBar
    First As String
    Second As Long
End Type

Public th|is As TBar
Public that As TBar";

            var validator    = EncapsulateFieldValidationsProvider.NameOnlyValidator(NameValidators.Default);
            var expectedThis = new EncapsulationIdentifiers("this", validator);
            var expectedThat = new EncapsulationIdentifiers("that", validator);

            var userInput = new UserInputDataObject()
                            .AddUserInputSet(expectedThis.TargetFieldName, encapsulationFlag: encapsulateThis)
                            .AddUserInputSet(expectedThat.TargetFieldName, encapsulationFlag: encapsulateThat);

            var presenterAction = Support.SetParameters(userInput);

            var actualCode = Support.RefactoredCode(inputCode.ToCodeString(), presenterAction);

            if (encapsulateThis && encapsulateThat)
            {
                StringAssert.Contains($"Private {expectedThis.TargetFieldName} As TBar", actualCode);
                StringAssert.Contains($"First = {expectedThis.TargetFieldName}.First", actualCode);
                StringAssert.Contains($"Second = {expectedThis.TargetFieldName}.Second", actualCode);
                StringAssert.Contains($"{expectedThis.TargetFieldName}.First = {Support.RHSIdentifier}", actualCode);
                StringAssert.Contains($"{expectedThis.TargetFieldName}.Second = {Support.RHSIdentifier}", actualCode);
                StringAssert.Contains($"Property Get First", actualCode);
                StringAssert.Contains($"Property Get Second", actualCode);

                StringAssert.Contains($"Private {expectedThat.TargetFieldName} As TBar", actualCode);
                StringAssert.Contains($"First_1 = {expectedThat.TargetFieldName}.First", actualCode);
                StringAssert.Contains($"Second_1 = {expectedThat.TargetFieldName}.Second", actualCode);
                StringAssert.Contains($"{expectedThat.TargetFieldName}.First = {Support.RHSIdentifier}", actualCode);
                StringAssert.Contains($"{expectedThat.TargetFieldName}.Second = {Support.RHSIdentifier}", actualCode);
                StringAssert.Contains($"Property Get First_1", actualCode);
                StringAssert.Contains($"Property Get Second_1", actualCode);

                StringAssert.Contains($"Private {expectedThis.TargetFieldName} As TBar", actualCode);
                StringAssert.Contains($"Private {expectedThat.TargetFieldName} As TBar", actualCode);
            }
            else if (encapsulateThis && !encapsulateThat)
            {
                StringAssert.Contains($"First = {expectedThis.TargetFieldName}.First", actualCode);
                StringAssert.Contains($"Second = {expectedThis.TargetFieldName}.Second", actualCode);
                StringAssert.Contains($"{expectedThis.TargetFieldName}.First = {Support.RHSIdentifier}", actualCode);
                StringAssert.Contains($"{expectedThis.TargetFieldName}.Second = {Support.RHSIdentifier}", actualCode);
                StringAssert.Contains($"Property Get First", actualCode);
                StringAssert.Contains($"Property Get Second", actualCode);

                StringAssert.Contains($"Private {expectedThis.TargetFieldName} As TBar", actualCode);
                StringAssert.Contains($"Public {expectedThat.TargetFieldName} As TBar", actualCode);
            }
            else if (!encapsulateThis && encapsulateThat)
            {
                StringAssert.Contains($"First = {expectedThat.TargetFieldName}.First", actualCode);
                StringAssert.Contains($"Second = {expectedThat.TargetFieldName}.Second", actualCode);
                StringAssert.Contains($"{expectedThat.TargetFieldName}.First = {Support.RHSIdentifier}", actualCode);
                StringAssert.Contains($"{expectedThat.TargetFieldName}.Second = {Support.RHSIdentifier}", actualCode);
                StringAssert.Contains($"Property Get First", actualCode);
                StringAssert.Contains($"Property Get Second", actualCode);

                StringAssert.Contains($"Public {expectedThis.TargetFieldName} As TBar", actualCode);
                StringAssert.Contains($"Private {expectedThat.TargetFieldName} As TBar", actualCode);
            }
            else
            {
                StringAssert.Contains($"Public {expectedThis.TargetFieldName} As TBar", actualCode);
                StringAssert.Contains($"Public {expectedThat.TargetFieldName} As TBar", actualCode);
            }
        }