Best NBi code snippet using NBi.NUnit.TestCaseFactory.BuilderRegistration
TestCaseFactory.cs
Source:TestCaseFactory.cs  
...13namespace NBi.NUnit14{15    public class TestCaseFactory16    {17        private readonly ICollection<BuilderRegistration> registrations;18        private readonly IConfiguration configuration;19        private readonly IDictionary<string, IVariable> variables;20        private readonly ServiceLocator serviceLocator;2122        public TestCaseFactory()23            : this(Configuration.Default, new Dictionary<string, IVariable>(), null)24        {25        }2627        public TestCaseFactory(IConfiguration configuration, IDictionary<string, IVariable> variables, ServiceLocator serviceLocator)28        {29            this.configuration = configuration;30            this.variables = variables;31            this.serviceLocator = serviceLocator;32            registrations = new List<BuilderRegistration>();33            RegisterDefault();34        }3536        /// <summary>37        /// Register the values for production usage38        /// </summary>39        private void RegisterDefault()40        {41            Register(typeof(ExecutionXml), typeof(FasterThanXml), new ExecutionFasterThanChooser());42            Register(typeof(ExecutionXml), typeof(SyntacticallyCorrectXml), new ExecutionSyntacticallyCorrectBuilder());43            Register(typeof(ExecutionXml), typeof(SuccessfulXml), new ExecutionNonQuerySuccessfulBuilder());4445            Register(typeof(ExecutionXml), typeof(MatchPatternXml), new ExecutionMatchPatternBuilder());46            Register(typeof(ExecutionXml), typeof(EvaluateRowsXml), new ExecutionEvaluateRowsBuilder());4748            Register(typeof(ExecutionXml), typeof(EqualToXml), new ResultSetEqualToBuilder());49            Register(typeof(ExecutionXml), typeof(SupersetOfXml), new ResultSetSupersetOfBuilder());50            Register(typeof(ExecutionXml), typeof(SubsetOfXml), new ResultSetSubsetOfBuilder());51            Register(typeof(ExecutionXml), typeof(RowCountXml), new ResultSetRowCountBuilder());52            Register(typeof(ExecutionXml), typeof(AllRowsXml), new ResultSetAllRowsBuilder());53            Register(typeof(ExecutionXml), typeof(NoRowsXml), new ResultSetNoRowsBuilder());54            Register(typeof(ExecutionXml), typeof(SomeRowsXml), new ResultSetSomeRowsBuilder());55            Register(typeof(ExecutionXml), typeof(SingleRowXml), new ResultSetSingleRowBuilder());56            Register(typeof(ExecutionXml), typeof(UniqueRowsXml), new ResultSetUniqueRowsBuilder());5758            Register(typeof(ResultSetSystemXml), typeof(EqualToXml), new ResultSetEqualToBuilder());59            Register(typeof(ResultSetSystemXml), typeof(SupersetOfXml), new ResultSetSupersetOfBuilder());60            Register(typeof(ResultSetSystemXml), typeof(SubsetOfXml), new ResultSetSubsetOfBuilder());61            Register(typeof(ResultSetSystemXml), typeof(IntersectionOfXml), new IntersectionOfBuilder());62            Register(typeof(ResultSetSystemXml), typeof(RowCountXml), new ResultSetRowCountBuilder());63            Register(typeof(ResultSetSystemXml), typeof(AllRowsXml), new ResultSetAllRowsBuilder());64            Register(typeof(ResultSetSystemXml), typeof(NoRowsXml), new ResultSetNoRowsBuilder());65            Register(typeof(ResultSetSystemXml), typeof(SomeRowsXml), new ResultSetSomeRowsBuilder());66            Register(typeof(ResultSetSystemXml), typeof(SingleRowXml), new ResultSetSingleRowBuilder());67            Register(typeof(ResultSetSystemXml), typeof(UniqueRowsXml), new ResultSetUniqueRowsBuilder());68            Register(typeof(ResultSetSystemXml), typeof(LookupExistsXml), new ResultSetLookupExistsBuilder());69            Register(typeof(ResultSetSystemXml), typeof(LookupMatchesXml), new ResultSetLookupMatchesBuilder());7071            Register(typeof(ScalarXml), typeof(ScoreXml), new ScalarScoreBuilder());7273            Register(typeof(MembersXml), typeof(CountXml), new MembersCountBuilder());74            Register(typeof(MembersXml), typeof(OrderedXml), new MembersOrderedBuilder());75            Register(typeof(MembersXml), typeof(ContainXml), new MembersContainBuilder());76            Register(typeof(MembersXml), typeof(ContainedInXml), new MembersContainedInBuilder());77            Register(typeof(MembersXml), typeof(SubsetOfOldXml), new MembersContainedInBuilder());78            Register(typeof(MembersXml), typeof(EquivalentToXml), new MembersEquivalentToBuilder());79            Register(typeof(MembersXml), typeof(MatchPatternXml), new MembersMatchPatternBuilder());8081            Register(typeof(StructureXml), typeof(ContainXml), new StructureContainBuilder());82            Register(typeof(StructureXml), typeof(ContainedInXml), new StructureContainedInBuilder());83            Register(typeof(StructureXml), typeof(SubsetOfOldXml), new StructureContainedInBuilder());84            Register(typeof(StructureXml), typeof(EquivalentToXml), new StructureEquivalentToBuilder());85            Register(typeof(StructureXml), typeof(ExistsXml), new StructureExistsBuilder());86            Register(typeof(StructureXml), typeof(LinkedToXml), new StructureLinkedToBuilder());8788            Register(typeof(DataTypeXml), typeof(IsXml), new DataTypeIsBuilder());89        }9091        /// <summary>92        /// Register a new builder for corresponding types. If a builder was already existing for this association, it's replaced by the new one93        /// </summary>94        /// <param name="sutType">Type of System Under Test</param>95        /// <param name="ctrType">Type of Constraint</param>96        /// <param name="builder">Instance of builder deicated for these types of System Under Test and Constraint</param>97        internal void Register(Type sutType, Type ctrType, ITestCaseBuilder builder)98        {99            if (IsHandling(sutType, ctrType))100                registrations.FirstOrDefault(reg => IsRegistered(reg, sutType, ctrType)).Builder = builder;101            else102                registrations.Add(new BuilderRegistration(sutType, ctrType, builder));103        }104105        internal void Register(Type sutType, Type ctrType, ITestCaseBuilderChooser chooser)106        {107            if (IsHandling(sutType, ctrType))108                registrations.FirstOrDefault(reg => reg.SystemUnderTestType.Equals(sutType) && reg.ConstraintType.Equals(ctrType)).Chooser = chooser;109            else110                registrations.Add(new BuilderRegistration(sutType, ctrType, chooser));111        }112113        internal bool IsHandling(Type sutType, Type ctrType) => registrations.Any(reg => IsRegistered(reg, sutType, ctrType));114115        private bool IsRegistered(BuilderRegistration reg, Type sutType, Type ctrType) 116            => (reg.SystemUnderTestType.Equals(sutType) || reg.SystemUnderTestType.Name == sutType.Name.Replace("OldXml", "Xml"))117                    && (reg.ConstraintType.Equals(ctrType) || reg.ConstraintType.Name == ctrType.Name.Replace("OldXml", "Xml"));118119        internal class BuilderRegistration120        {121            public Type SystemUnderTestType { get; set; }122            public Type ConstraintType { get; set; }123            public ITestCaseBuilder Builder { get; set; }124            public ITestCaseBuilderChooser Chooser { get; set; }125126            private BuilderRegistration(Type sutType, Type ctrType)127            {128                SystemUnderTestType = sutType;129                ConstraintType = ctrType;130            }131132            public BuilderRegistration(Type sutType, Type ctrType, ITestCaseBuilder builder)133                : this(sutType, ctrType)134            {135                Builder = builder;136            }137138            public BuilderRegistration(Type sutType, Type ctrType, ITestCaseBuilderChooser chooser)139                : this(sutType, ctrType)140            {141                Chooser = chooser;142                Chooser.Target = this;143            }144        }145146        /// <summary>147        /// Create a new instance of a test case148        /// </summary>149        /// <param name="sutXml"></param>150        /// <param name="ctrXml"></param>151        /// <returns></returns>152        public TestCase Instantiate(AbstractSystemUnderTestXml sutXml, AbstractConstraintXml ctrXml)
...ITestCaseBuilderChooser.cs
Source:ITestCaseBuilderChooser.cs  
...6namespace NBi.NUnit.Builder7{8    interface ITestCaseBuilderChooser9    {10        TestCaseFactory.BuilderRegistration Target { get; set; }11        void Choose(AbstractSystemUnderTestXml sut, AbstractConstraintXml ctr);12    }13}
...BuilderRegistration
Using AI Code Generation
1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using NBi.NUnit.TestCaseFactory;7using NUnit.Framework;8{9    {10        public void BuilderRegistration_DuplicateBuilder_Exception()11        {12            TestCaseFactory testCaseFactory = new TestCaseFactory();13            testCaseFactory.BuilderRegistration("myBuilder", typeof(MyBuilder));14            Assert.Throws<ArgumentException>(() => testCaseFactory.BuilderRegistration("myBuilder", typeof(MyBuilder)));15        }16    }17}18using System;19using System.Collections.Generic;20using System.Linq;21using System.Text;22using System.Threading.Tasks;23using NBi.NUnit.TestCaseFactory;24using NUnit.Framework;25{26    {27        public void BuilderRegistration_DuplicateBuilder_Exception()28        {29            TestCaseFactory testCaseFactory = new TestCaseFactory();30            testCaseFactory.BuilderRegistration("myBuilder", typeof(MyBuilder));31            Assert.Throws<ArgumentException>(() => testCaseFactory.BuilderRegistration("myBuilder", typeof(MyBuilder)));32        }33    }34}35using System;36using System.Collections.Generic;37using System.Linq;38using System.Text;39using System.Threading.Tasks;40using NBi.NUnit.TestCaseFactory;41using NUnit.Framework;42{43    {44        public void BuilderRegistration_DuplicateBuilder_Exception()45        {46            TestCaseFactory testCaseFactory = new TestCaseFactory();47            testCaseFactory.BuilderRegistration("myBuilder", typeof(MyBuilder));48            Assert.Throws<ArgumentException>(() => testCaseFactory.BuilderRegistration("myBuilder", typeof(MyBuilder)));49        }50    }51}52using System;53using System.Collections.Generic;54using System.Linq;55using System.Text;56using System.Threading.Tasks;57using NBi.NUnit.TestCaseFactory;58using NUnit.Framework;59{60    {BuilderRegistration
Using AI Code Generation
1using NBi.NUnit;2using NBi.NUnit.Builder;3using NBi.NUnit.Builder.Helper;4using NBi.NUnit.Execution;5using NBi.NUnit.Member;6using NBi.Xml.Constraints;7using NBi.Xml.Items;8using NBi.Xml.Settings;9using NBi.Xml.Systems;10using NBi.Xml.Systems.File;11using NBi.Xml.Systems.Oracle;12using NBi.Xml.Systems.SqlServer;13using NBi.Xml.Variables;14using NUnit.Framework;15using NUnit.Framework.Internal;16using System;17using System.Collections.Generic;18using System.Data;19using System.Linq;20using System.Text;21using System.Threading.Tasks;22{23    {24        public void BuilderRegistrationTest_OracleConnectionString()25        {26            var builder = new TestCaseFactory();27            var connectionString = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=BuilderRegistration
Using AI Code Generation
1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using NBi.NUnit;7{8    {9        public BuilderRegistration()10        {11            var factory = new NBi.NUnit.TestCaseFactory();12            factory.BuilderRegistration();13        }14    }15}16using System;17using System.Collections.Generic;18using System.Linq;19using System.Text;20using System.Threading.Tasks;21using NBi.NUnit.Builder;22using NBi.NUnit.Execution;23using NBi.Xml.Constraints;24using NBi.Xml.Items;25using NBi.Xml.Systems;26using NBi.Xml.Settings;27using NBi.Core.ResultSet;28using NBi.Core.ResultSet.Lookup.Violation;29using NBi.Core.ResultSet.Lookup;30{31    {32        public GetBuilder()33        {34            var factory = new NBi.NUnit.TestCaseFactory();35            factory.BuilderRegistration();36            var builder = factory.GetBuilder(new NBi.Xml.TestCase37            {38                {39                    ConnectionString = "Data Source=.;Initial Catalog=AdventureWorks2012;Integrated Security=True",40                },41                {42                    {43                        ConnectionString = "Data Source=.;Initial Catalog=AdventureWorks2012;Integrated Security=True",44                    }45                }46            });47        }48    }49}50using System;51using System.Collections.Generic;52using System.Linq;53using System.Text;54using System.Threading.Tasks;55using NBi.NUnit.Builder;56using NBi.NUnit.Execution;57using NBi.Xml.Constraints;58using NBi.Xml.Items;59using NBi.Xml.Systems;60using NBi.Xml.Settings;61using NBi.Core.ResultSet;62using NBi.Core.ResultSet.Lookup.Violation;63using NBi.Core.ResultSet.Lookup;64{65    {66        public GetBuilder()67        {68            var factory = new NBi.NUnit.TestCaseFactory();BuilderRegistration
Using AI Code Generation
1var factory = new NBi.NUnit.TestCaseFactory();2factory.BuilderRegistration("MyBuilder", typeof(MyBuilder));3var factory = new NBi.NUnit.TestCaseFactory();4factory.BuilderRegistration("MyBuilder", typeof(MyBuilder));5var factory = new NBi.NUnit.TestCaseFactory();6factory.BuilderRegistration("MyBuilder", typeof(MyBuilder));7var factory = new NBi.NUnit.TestCaseFactory();8factory.BuilderRegistration("MyBuilder", typeof(MyBuilder));9var factory = new NBi.NUnit.TestCaseFactory();10factory.BuilderRegistration("MyBuilder", typeof(MyBuilder));11var factory = new NBi.NUnit.TestCaseFactory();12factory.BuilderRegistration("MyBuilder", typeof(MyBuilder));13var factory = new NBi.NUnit.TestCaseFactory();14factory.BuilderRegistration("MyBuilder", typeof(MyBuilder));15var factory = new NBi.NUnit.TestCaseFactory();16factory.BuilderRegistration("MyBuilder", typeof(MyBuilder));17var factory = new NBi.NUnit.TestCaseFactory();18factory.BuilderRegistration("MyBuilder", typeof(MyBuilder));19var factory = new NBi.NUnit.TestCaseFactory();20factory.BuilderRegistration("MyBuilder", typeof(MyBuilder));21var factory = new NBi.NUnit.TestCaseFactory();22factory.BuilderRegistration("MyBuilder", typeof(MyBuilder));BuilderRegistration
Using AI Code Generation
1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using NBi.NUnit.TestCaseFactory;7using NUnit.Framework;8using NUnit.Framework.Interfaces;9using NUnit.Framework.Internal;10{11    {12        public IEnumerable<ITestCaseData> GetTestCases()13        {14            yield return new TestCaseData(1, 2).SetName("Addition");15            yield return new TestCaseData(1, 2).SetName("Multiplication");16        }17    }18    {19        [Test, TestCaseSource(typeof(MyTestCaseFactory))]20        public void Test(int a, int b)21        {22            Assert.That(a + b, Is.EqualTo(3));23        }24    }25}26using System;27using System.Collections.Generic;28using System.Linq;29using System.Text;30using System.Threading.Tasks;31using NBi.NUnit.TestCaseFactory;32using NUnit.Framework;33using NUnit.Framework.Interfaces;34using NUnit.Framework.Internal;35{36    {37        public IEnumerable<ITestCaseData> GetTestCases()38        {39            yield return new TestCaseData(1, 2).SetName("Addition");40            yield return new TestCaseData(1, 2).SetName("Multiplication");41        }42    }43    {44        [Test, TestCaseSource(typeof(MyTestCaseFactory))]45        public void Test(int a, int b)46        {47            Assert.That(a * b, Is.EqualTo(2));48        }49    }50}51using System;52using System.Collections.Generic;53using System.Linq;54using System.Text;55using System.Threading.Tasks;56using NBi.NUnit.TestCaseFactory;57using NUnit.Framework;58using NUnit.Framework.Interfaces;59using NUnit.Framework.Internal;60{61    {62        public IEnumerable<ITestCaseData> GetTestCases()63        {64            yield return new TestCaseData(1, 2).SetName("Addition");65            yield return new TestCaseData(1, 2).SetName("Multiplication");66        }67    }68    {69        [Test, TestCaseSource(typeof(MyTestCaseFactory))]70        public void Test(int a, int b)71        {BuilderRegistration
Using AI Code Generation
1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using NBi.NUnit.TestCaseFactory;6using NBi.NUnit.Builder;7using NBi.NUnit.Member;8using NBi.NUnit.Query;9{10    {11        public IEnumerable<TestCase> GetTestCases(object testObject)12        {13            var testCases = new List<TestCase>();14            var test = testObject as TestClass;15            testCases.Add(new TestCase("My first test case", test));16            testCases.Add(new TestCase("My second test case", test));17            return testCases;18        }19    }20    {21        public string Name { get; set; }22    }23    {24        static void Main(string[] args)25        {26            var factory = new TestCaseFactory();27            factory.BuilderRegistration<CustomTestCaseFactory, TestClass, MemberBuilder>();28            factory.BuilderRegistration<CustomTestCaseFactory, TestClass, QueryBuilder>();29            var testCases = factory.GetTestCases(new TestClass { Name = "Test" });30            foreach (var testCase in testCases)31            {32                Console.WriteLine(testCase.Name);33            }34        }35    }36}37using System;38using System.Collections.Generic;39using System.Linq;40using System.Text;41using NBi.NUnit.TestCaseFactory;42using NBi.NUnit.Builder;43using NBi.NUnit.Member;44using NBi.NUnit.Query;45{46    {47        public IEnumerable<TestCase> GetTestCases(object testObject)48        {49            var testCases = new List<TestCase>();50            var test = testObject as TestClass;51            testCases.Add(new TestCase("My first test case", test));52            testCases.Add(new TestCase("My second test case", test));53            return testCases;54        }55    }56    {57        public string Name { getBuilderRegistration
Using AI Code Generation
1[Category("Builder")]2{3    public TestCasesBuilder() : base(new BuilderRegistration("testcases", typeof(TestCasesBuilder)))4    { }5    protected override void SpecificBuild()6    {7    }8}9[Category("Builder")]10{11    public void Test()12    {13        Assert.Pass();14    }15}16[Category("Builder")]17{18    public void Test()19    {20        Assert.Pass();21    }22}23[Category("Builder")]24{25    public void Test()26    {27        Assert.Pass();28    }29}30[Category("Builder")]31{32    public void Test()33    {34        Assert.Pass();35    }36}37[Category("Builder")]38{39    public void Test()40    {41        Assert.Pass();42    }43}Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
