Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mock Data By reflection all Dataset , Locale and methods are shown #3838

Merged
merged 6 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ limitations under the License.
using Amdocs.Ginger.Plugin.Core;
using Ginger.Actions;
using Ginger.UserControlsLib.TextEditor.Common;
using GingerCore;
using GingerCore.Variables;
using ICSharpCode.AvalonEdit.CodeCompletion;
using ICSharpCode.AvalonEdit.Highlighting;
Expand Down Expand Up @@ -193,6 +194,15 @@ private Page GetPageFor(SelectedContentArgs SelectedContentArgs)
}
}

if(txt.StartsWith("{MockDataExp Fun="))
{
Mockdata expParams = GingerCore.ValueExpression.GetMockDataDatasetsFunction(txt);
if (expParams != null)
{
p = new ValueExpressionMockDataEditorPage(mContext, SelectedContentArgs,expParams.MockDataDatasets, expParams.Function, expParams.Locale, expParams.MockExpression);
}
}
Comment on lines +197 to +204
Copy link
Contributor

@coderabbitai coderabbitai bot Jul 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New Logic to Handle {MockDataExp Fun= Expressions

The added logic to handle expressions starting with {MockDataExp Fun= is well-integrated within the GetPageFor method. This method now checks for the specific pattern and, if matched, uses GingerCore.ValueExpression.GetMockDataDatasetsFunction to parse the expression and create a new instance of ValueExpressionMockDataEditorPage.

  • Correctness: The implementation correctly checks for null values before proceeding with the creation of the page, which prevents potential null reference exceptions.
  • Performance: Ensure that the GetMockDataDatasetsFunction method is optimized for performance, especially if it involves complex parsing or external data fetching.

Overall, the implementation follows good practices, but it's recommended to add unit tests to cover these new scenarios to ensure stability and correctness.

Would you like me to help in writing unit tests for this new functionality?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes please

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@prashelke, here are the unit tests for the new functionality handling {MockDataExp Fun= expressions in the GetPageFor method. These tests will help ensure that the method behaves as expected under various scenarios:

using NUnit.Framework;
using Ginger.UserControlsLib.TextEditor.ValueExpression;
using GingerCoreNET.ValueExpressionLib;
using amdocs.ginger.GingerCoreNET;
using Amdocs.Ginger.Common;

namespace GingerCoreNETUnitTest.ValueExpressionTests
{
    [TestFixture]
    public class ValueExpressionEditorTests
    {
        private ValueExpressionEditor editor;
        private Context context;

        [SetUp]
        public void Setup()
        {
            context = new Context();
            editor = new ValueExpressionEditor(context);
        }

        [Test]
        public void GetPageFor_ValidMockDataExp_ReturnsMockDataEditorPage()
        {
            // Arrange
            string expression = "{MockDataExp Fun=ValidFunction}";
            SelectedContentArgs args = new SelectedContentArgs { TextEditor = new MockTextEditor(expression) };

            // Act
            Page result = editor.GetPageFor(args);

            // Assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOf<ValueExpressionMockDataEditorPage>(result);
        }

        [Test]
        public void GetPageFor_InvalidMockDataExp_ReturnsNull()
        {
            // Arrange
            string expression = "{MockDataExp Fun=}";
            SelectedContentArgs args = new SelectedContentArgs { TextEditor = new MockTextEditor(expression) };

            // Act
            Page result = editor.GetPageFor(args);

            // Assert
            Assert.IsNull(result);
        }

        [Test]
        public void GetPageFor_NullInput_ThrowsNoException()
        {
            // Arrange
            SelectedContentArgs args = null;

            // Act & Assert
            Assert.DoesNotThrow(() => editor.GetPageFor(args));
        }
    }
    
    // Mock implementation of TextEditor to simulate user input
    public class MockTextEditor : ITextEditor
    {
        public string Text { get; set; }

        public MockTextEditor(string text)
        {
            Text = text;
        }
    }
}

These tests check for valid input, invalid input, and null input scenarios. Feel free to adjust the test cases or add more to cover additional cases you might be concerned about.


if (txt.StartsWith("{EnvURL App="))
{
//TODO: impl get page for Env
Expand Down Expand Up @@ -221,17 +231,28 @@ private Page GetPageFor(SelectedContentArgs SelectedContentArgs)

public override void UpdateSelectedContent()
{
if (p.GetType() == typeof(ValueExpressionVariableEditorPage))
{
((ValueExpressionVariableEditorPage)p).UpdateContent();
}
else if (p.GetType() == typeof(ActDataSourcePage))
try
{
((ActDataSourcePage)p).UpdateContent();
if (p.GetType() == typeof(ValueExpressionVariableEditorPage))
{
((ValueExpressionVariableEditorPage)p).UpdateContent();
}
else if (p.GetType() == typeof(ActDataSourcePage))
{
((ActDataSourcePage)p).UpdateContent();
}
else if (p.GetType() == typeof(ValueExpressionFlowDetailsEditorPage))
{
((ValueExpressionFlowDetailsEditorPage)p).UpdateContent();
}
else if (p.GetType() == typeof(ValueExpressionMockDataEditorPage))
{
((ValueExpressionMockDataEditorPage)p).UpdateContent();
}
}
else if (p.GetType() == typeof(ValueExpressionFlowDetailsEditorPage))
catch (Exception ex)
{
((ValueExpressionFlowDetailsEditorPage)p).UpdateContent();
Reporter.ToLog(eLogLevel.ERROR, "Failed to update the selected content", ex);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Page x:Class="Ginger.UserControlsLib.TextEditor.ValueExpression.ValueExpressionMockDataEditorPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Ginger.UserControlsLib.TextEditor.ValueExpression"
xmlns:GingerCore="clr-namespace:GingerCore;assembly=GingerCore"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300"
Title="ValueExpressionMockDataEditorPage">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="3*"/>
<RowDefinition Height="15*"/>
</Grid.RowDefinitions>

<Label x:Name="lbl" Grid.Row="0" Style="{StaticResource $LabelStyle}">
<GingerCore:ucTextDicResource Text="Select Alternative Functions:"/>
</Label>
<ListView x:Name="FunctionsList" Grid.Row="1" Style="{StaticResource $ListBoxStyle}" Foreground="{StaticResource $SelectionColor_Pink}" BorderThickness="0">
prashelke marked this conversation as resolved.
Show resolved Hide resolved

</ListView>
</Grid>
</Page>
Loading
Loading