How to use FakeSessionFactory class of NBi.Testing.Core.Query.Execution package

Best NBi code snippet using NBi.Testing.Core.Query.Execution.FakeSessionFactory

ServiceLocatorTest.cs

Source:ServiceLocatorTest.cs Github

copy

Full Screen

...22{23 public class ServiceLocatorTest24 {25 #region Fake26 private class FakeSessionFactory : IClientFactory27 {28 public bool CanHandle(string connectionString) => true;29 public IClient Instantiate(string connectionString) => throw new NotImplementedException();30 }31 private class FakeCommandFactory : ICommandFactory32 {33 public bool CanHandle(IClient session) => true;34 public IClient Instantiate(string connectionString) => throw new NotImplementedException();35 public ICommand Instantiate(IClient session, IQuery query, ITemplateEngine engine) => throw new NotImplementedException();36 }37 [SupportedCommandType(typeof(object))]38 private class FakeExecutionEngine : IExecutionEngine39 {40 public DataSet Execute() => throw new NotImplementedException();41 public IEnumerable<T> ExecuteList<T>() => throw new NotImplementedException();42 public object ExecuteScalar() => throw new NotImplementedException();43 }44 #endregion45 [Test]46 public void GetSessionFactory_Instance()47 {48 var locator = new ServiceLocator();49 var obj = locator.GetSessionFactory();50 Assert.That(obj, Is.Not.Null);51 Assert.IsInstanceOf<ClientProvider>(obj);52 }53 [Test]54 public void GetSessionFactory_Singleton()55 {56 var locator = new ServiceLocator();57 var obj1 = locator.GetSessionFactory();58 var obj2 = locator.GetSessionFactory();59 Assert.That(obj1, Is.EqualTo(obj2));60 }61 [Test]62 public void GetSessionFactory_CantAddTwiceTheSameFactory()63 {64 var locator = new ServiceLocator();65 var obj1 = locator.GetSessionFactory();66 var obj2 = locator.GetSessionFactory();67 obj1.RegisterFactories(new[] { typeof(FakeSessionFactory) });68 Assert.Throws<ArgumentException>(() => obj2.RegisterFactories(new[] { typeof(FakeSessionFactory) }));69 }70 [Test]71 public void GetCommandFactory_Instance()72 {73 var locator = new ServiceLocator();74 var obj = locator.GetCommandFactory();75 Assert.That(obj, Is.Not.Null);76 Assert.IsInstanceOf<CommandProvider>(obj);77 }78 [Test]79 public void GetCommandFactory_Singleton()80 {81 var locator = new ServiceLocator();82 var obj1 = locator.GetCommandFactory();83 var obj2 = locator.GetCommandFactory();84 Assert.That(obj1, Is.EqualTo(obj2));85 }86 [Test]87 public void GetResultSetResolverFactory_Instance()88 {89 var locator = new ServiceLocator();90 var obj = locator.GetResultSetResolverFactory();91 Assert.That(obj, Is.Not.Null);92 Assert.IsInstanceOf<ResultSetResolverFactory>(obj);93 }94 [Test]95 public void GetResultSetResolverFactory_NotSingleton()96 {97 var locator = new ServiceLocator();98 var obj1 = locator.GetResultSetResolverFactory();99 var obj2 = locator.GetResultSetResolverFactory();100 Assert.That(obj1, Is.Not.EqualTo(obj2));101 }102 [Test]103 public void GetResultSetResolverFactory_UnderlyingServiceLocatorIsSingleton()104 {105 var locator = new ServiceLocator();106 var obj1 = locator.GetResultSetResolverFactory();107 var obj2 = locator.GetResultSetResolverFactory();108 var field = typeof(ResultSetResolverFactory).GetField("serviceLocator", BindingFlags.NonPublic | BindingFlags.Instance);109 var serviceLocator1 = field.GetValue(obj1);110 var serviceLocator2 = field.GetValue(obj2);111 Assert.That(serviceLocator1, Is.EqualTo(serviceLocator2));112 }113 [Test]114 public void GetQueryResolverFactory_Instance()115 {116 var locator = new ServiceLocator();117 var obj = locator.GetQueryResolverFactory();118 Assert.That(obj, Is.Not.Null);119 Assert.IsInstanceOf<QueryResolverFactory>(obj);120 }121 [Test]122 public void GetQueryResolverFactory_NotSingleton()123 {124 var locator = new ServiceLocator();125 var obj1 = locator.GetQueryResolverFactory();126 var obj2 = locator.GetQueryResolverFactory();127 Assert.That(obj1, Is.Not.EqualTo(obj2));128 }129 [Test]130 public void GetQueryResolverFactory_UnderlyingServiceLocatorIsSingleton()131 {132 var locator = new ServiceLocator();133 var obj1 = locator.GetQueryResolverFactory();134 var obj2 = locator.GetQueryResolverFactory();135 var field = typeof(QueryResolverFactory).GetField("serviceLocator", BindingFlags.NonPublic | BindingFlags.Instance);136 var serviceLocator1 = field.GetValue(obj1);137 var serviceLocator2 = field.GetValue(obj2);138 Assert.That(serviceLocator1, Is.EqualTo(serviceLocator2));139 }140 [Test]141 public void GetScalarResolverFactory_Instance()142 {143 var locator = new ServiceLocator();144 var obj = locator.GetScalarResolverFactory();145 Assert.That(obj, Is.Not.Null);146 Assert.IsInstanceOf<ScalarResolverFactory>(obj);147 }148 [Test]149 public void GetScalarResolverFactory_NotSingleton()150 {151 var locator = new ServiceLocator();152 var obj1 = locator.GetScalarResolverFactory();153 var obj2 = locator.GetScalarResolverFactory();154 Assert.That(obj1, Is.Not.EqualTo(obj2));155 }156 [Test]157 public void GetFormatterFactory_Instance()158 {159 var locator = new ServiceLocator();160 var obj = locator.GetFormatterFactory();161 Assert.That(obj, Is.Not.Null);162 Assert.IsInstanceOf<FormatterFactory>(obj);163 }164 [Test]165 public void GetFormatterFactory_NotSingleton()166 {167 var locator = new ServiceLocator();168 var obj1 = locator.GetFormatterFactory();169 var obj2 = locator.GetFormatterFactory();170 Assert.That(obj1, Is.Not.EqualTo(obj2));171 }172 [Test]173 public void GetScalarResolverFactory_UnderlyingServiceLocatorIsSingleton()174 {175 var locator = new ServiceLocator();176 var obj1 = locator.GetScalarResolverFactory();177 var obj2 = locator.GetScalarResolverFactory();178 var field = typeof(ScalarResolverFactory).GetField("serviceLocator", BindingFlags.NonPublic | BindingFlags.Instance);179 var serviceLocator1 = field.GetValue(obj1);180 var serviceLocator2 = field.GetValue(obj2);181 Assert.That(serviceLocator1, Is.EqualTo(serviceLocator2));182 }183 [Test]184 public void GetConfiguration_Instance()185 {186 var locator = new ServiceLocator();187 var obj = locator.GetConfiguration();188 Assert.That(obj, Is.Not.Null);189 Assert.IsInstanceOf<IConfiguration>(obj);190 }191 [Test]192 public void GetConfiguration_Singleton()193 {194 var locator = new ServiceLocator();195 var obj1 = locator.GetConfiguration();196 var obj2 = locator.GetConfiguration();197 Assert.That(obj1, Is.EqualTo(obj2));198 }199 [Test]200 public void GetExecutionEngineFactory_NoConfig_Instance()201 {202 var locator = new ServiceLocator();203 var obj = locator.GetExecutionEngineFactory();204 Assert.That(obj, Is.Not.Null);205 Assert.IsInstanceOf<ExecutionEngineFactory>(obj);206 }207 [Test]208 public void GetExecutionEngineFactory_NoConfig_NotSingleton()209 {210 var locator = new ServiceLocator();211 var obj1 = locator.GetExecutionEngineFactory();212 var obj2 = locator.GetExecutionEngineFactory();213 Assert.That(obj1, Is.Not.EqualTo(obj2));214 }215 [Test]216 public void GetExecutionEngineFactory_Config_ConfigAvailable()217 {218 var locator = new ServiceLocator();219 var obj1 = locator.GetExecutionEngineFactory();220 Assert.That(obj1.ExtensionCount, Is.EqualTo(0));221 var config = locator.GetConfiguration();222 var extensions = new Dictionary<Type, IDictionary<string, string>>223 {224 { typeof(FakeSessionFactory), new Dictionary<string, string>() },225 { typeof(FakeCommandFactory), new Dictionary<string, string>() },226 { typeof(FakeExecutionEngine), new Dictionary<string, string>() },227 };228 config.LoadExtensions(extensions);229 var obj2 = locator.GetExecutionEngineFactory();230 Assert.That(obj2.ExtensionCount, Is.EqualTo(1));231 }232 }233}...

Full Screen

Full Screen

ExecutionEngineFactoryTest.cs

Source:ExecutionEngineFactoryTest.cs Github

copy

Full Screen

...68 public string ConnectionString => "fake://MyConnectionString";69 public Type UnderlyingSessionType => typeof(object);70 public object CreateNew() => throw new NotImplementedException();71 }72 public class FakeSessionFactory : IClientFactory73 {74 public bool CanHandle(string connectionString) => connectionString.StartsWith("fake://");75 public IClient Instantiate(string connectionString) => new FakeSession();76 }77 public class FakeCommand : ICommand78 {79 public object Implementation => new FakeImplementationCommand();80 public object Client => new FakeSession();81 public object CreateNew() => throw new NotImplementedException();82 }83 public class FakeImplementationCommand84 { }85 public class FakeCommandFactory : ICommandFactory86 {87 public bool CanHandle(IClient session) => session is FakeSession;88 public ICommand Instantiate(IClient session, IQuery query, ITemplateEngine engine) => new FakeCommand();89 }90 [SupportedCommandType(typeof(FakeImplementationCommand))]91 private class FakeExecutionEngine : IExecutionEngine92 {93 public FakeExecutionEngine(FakeSession session, object command)94 { }95 public DataSet Execute() => throw new NotImplementedException();96 public IEnumerable<T> ExecuteList<T>() => throw new NotImplementedException();97 public object ExecuteScalar() => throw new NotImplementedException();98 }99 #endregion100 [Test]101 public void Instantiate_FakeConnectionString_FakeExecutionEngine()102 {103 var localServiceLocator = new ServiceLocator();104 var query = Mock.Of<IQuery>(x => x.ConnectionString == "fake://MyConnectionString");105 var sessionFactory = localServiceLocator.GetSessionFactory();106 sessionFactory.RegisterFactories(new[] { typeof(FakeSessionFactory) });107 var commandFactory = localServiceLocator.GetCommandFactory();108 commandFactory.RegisterFactories(new[] { typeof(FakeCommandFactory) });109 var factory = new ExecutionEngineFactory(sessionFactory, commandFactory);110 factory.RegisterEngines(new[] { typeof(FakeExecutionEngine) });111 var engine = factory.Instantiate(query);112 Assert.IsInstanceOf<FakeExecutionEngine>(engine);113 }114 [Test]115 public void Instantiate_FakeConnectionStringExtensions_FakeExecutionEngine()116 {117 var localServiceLocator = new ServiceLocator();118 var setupConfig = localServiceLocator.GetConfiguration();119 var extensions = new Dictionary<Type, IDictionary<string, string>>120 {121 { typeof(FakeSessionFactory), new Dictionary<string, string>() },122 { typeof(FakeCommandFactory), new Dictionary<string, string>() },123 { typeof(FakeExecutionEngine), new Dictionary<string, string>() },124 };125 setupConfig.LoadExtensions(extensions);126 var query = Mock.Of<IQuery>(x => x.ConnectionString == "fake://MyConnectionString");127 var factory = localServiceLocator.GetExecutionEngineFactory();128 var engine = factory.Instantiate(query);129 Assert.IsInstanceOf<FakeExecutionEngine>(engine);130 }131 }132}...

Full Screen

Full Screen

FakeSessionFactory

Using AI Code Generation

copy

Full Screen

1using NBi.Testing.Core.Query.Execution;2using NBi.Core.Query.Execution;3using NBi.Core.Query;4using NBi.Core.Query.Resolver;5using NBi.Core.Query.Command;6using NBi.Core.Query.Client;7using NBi.Core.Query.Format;8using NBi.Core.Query.Execution;9using NBi.Core.Decoration.DataEngineering;10using NBi.Core;11using NBi.Core.Calculation;12using NBi.Core.ResultSet;13using NBi.Core.ResultSet.Resolver;14using NBi.Core.ResultSet.Alteration.Renaming;15using NBi.Core.ResultSet.Alteration.Projection;16using NBi.Core.ResultSet.Alteration.Duplication;17using NBi.Core.ResultSet.Alteration.Summarization;18using NBi.Core.ResultSet.Alteration.Aggregation;19using NBi.Core.ResultSet.Alteration.Filtering;20using NBi.Core.ResultSet.Alteration.Sorting;21using NBi.Core.ResultSet.Alteration.Pivot;22using NBi.Core.ResultSet.Alteration.Extension;23using NBi.Core.ResultSet.Alteration.Type;24using NBi.Core.ResultSet.Alteration;25using NBi.Core.ResultSet.Lookup.Violation;26using NBi.Core.ResultSet.Comparer;27using NBi.Core.ResultSet.Equivalence;28using NBi.Core.ResultSet.Lookup;29using NBi.Core.ResultSet.Lookup.Violation;30using NBi.Core.ResultSet.Comparer;31using NBi.Core.ResultSet;32using NBi.Core.ResultSet.Resolver;33using NBi.Core.ResultSet.Alteration.Renaming;34using NBi.Core.ResultSet.Alteration.Projection;35using NBi.Core.ResultSet.Alteration.Duplication;36using NBi.Core.ResultSet.Alteration.Summarization;37using NBi.Core.ResultSet.Alteration.Aggregation;38using NBi.Core.ResultSet.Alteration.Filtering;39using NBi.Core.ResultSet.Alteration.Sorting;40using NBi.Core.ResultSet.Alteration.Pivot;41using NBi.Core.ResultSet.Alteration.Extension;42using NBi.Core.ResultSet.Alteration.Type;43using NBi.Core.ResultSet.Alteration;44using NBi.Core.ResultSet.Lookup.Violation;45using NBi.Core.ResultSet.Comparer;46using NBi.Core.ResultSet.Equivalence;47using NBi.Core.ResultSet.Lookup;48using NBi.Core.ResultSet.Lookup.Violation;49using NBi.Core.ResultSet.Comparer;50using NBi.Core.ResultSet;51using NBi.Core.ResultSet.Resolver;52using NBi.Core.ResultSet.Alteration.Renaming;53using NBi.Core.ResultSet.Alteration.Projection;54using NBi.Core.ResultSet.Alteration.Duplication;55using NBi.Core.ResultSet.Alteration.Summarization;56using NBi.Core.ResultSet.Alteration.Aggregation;

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful