Skip to content

Commit

Permalink
Public Factory Method for Rule Parameter From Type (#529)
Browse files Browse the repository at this point in the history
Co-authored-by: YogeshPraj <[email protected]>
  • Loading branch information
cmeyertons and YogeshPraj authored Aug 23, 2024
1 parent d7c92c2 commit 6a747b3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/RulesEngine/Models/RuleParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ private void Init(string name, Type type)
ParameterExpression = Expression.Parameter(Type, Name);
}

public static RuleParameter Create(string name, Type type)
{
return new RuleParameter(name, type);
}

public static RuleParameter Create<T>(string name, T value)
{
var typedValue = Utils.GetTypedObject(value);
Expand Down
24 changes: 24 additions & 0 deletions test/RulesEngine.UnitTest/RuleParameterTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using AutoFixture;
using RulesEngine.Models;
using System;
using Xunit;

namespace RulesEngine.UnitTest;
public class RuleParameterTests
{
[Fact]
public void Create_SetsPropertiesCorrectly()
{
var fixture = new Fixture();
var name = fixture.Create<string>();
var type = fixture.Create<Type>();

var result = RuleParameter.Create(name, type);

Assert.Equal(name, result.Name);
Assert.Equal(type, result.Type);
}
}

0 comments on commit 6a747b3

Please sign in to comment.