/// <summary> /// Enable the assembly resolver to get the right versions in the same directory as this assembly. /// </summary> static HostServices() { if (RuntimeInformation.FrameworkDescription.StartsWith(".NET Framework")) { AssemblyResolver.Enable(); } LoggingCommand.Initialize(); }
public void Command() { using (var conn = new System.Data.SQLite.SQLiteConnection("Data Source=:memory:")) { conn.Open(); using (var command = new LoggingCommand(new System.Data.SQLite.SQLiteCommand())) { command.CommandText = "select 1"; Assert.Throws<InvalidOperationException>(() => command.ExecuteReader()); Assert.Equal(LogLevel.Error, logger.Last.Level); Assert.Equal(@"クエリ実行に失敗 --- SQLiteCommand --- CommandTimeout = 30 CommandType = Text UpdatedRowSource = None --- CommandText --- select 1 --- Parameters --- ", logger.Last.Message); command.Connection = conn; using (var reader = command.ExecuteReader()) { Assert.Equal(LogLevel.Trace, logger.Last.Level); Assert.Matches(@"ExecuteReader. 実行時間:\d\d:\d\d:\d\d\.\d+ --- CommandText --- select 1 --- Parameters --- ", logger.Last.Message); Assert.True(reader.Read()); Assert.Equal((long)1, reader[0]); } Assert.Equal((long)1, command.ExecuteScalar()); Assert.Matches(@"ExecuteScalar. result=1 実行時間:\d\d:\d\d:\d\d\.\d+ --- CommandText --- select 1 --- Parameters --- ", logger.Last.Message); command.CommandText = "select @p"; command.Parameters.Add(new System.Data.SQLite.SQLiteParameter("p", "abc")); Assert.Equal("abc", command.ExecuteScalar()); Assert.Matches(@"ExecuteScalar. result=abc 実行時間:\d\d:\d\d:\d\d\.\d+ --- CommandText --- select @p --- Parameters --- p\(String\)=abc ", logger.Last.Message); Assert.IsType<System.Data.SQLite.SQLiteParameter>(command.CreateParameter()); } Assert.Equal("コマンドが破棄(Dispose)されました。", logger.Last.Message); } }
public void CanConfigureInjectionForNonGenericMethodOnGenericClass() { Container.RegisterType(typeof(ICommand <>), typeof(LoggingCommand <>), new InjectionConstructor(), new InjectionMethod("InjectMe")); ICommand <Account> result = Container.Resolve <ICommand <Account> >(); LoggingCommand <Account> logResult = (LoggingCommand <Account>)result; Assert.IsTrue(logResult.WasInjected); }
public void Injection_CanChainGenericTypesViaRegisterTypeMethod() { // Setup Container .RegisterType(typeof(ICommand <>), typeof(LoggingCommand <>), new InjectionConstructor(Resolve.Parameter(typeof(ICommand <>), "concrete"))) .RegisterType(typeof(ICommand <>), typeof(ConcreteCommand <>), "concrete"); // Act ICommand <User> cmd = Container.Resolve <ICommand <User> >(); LoggingCommand <User> logCmd = (LoggingCommand <User>)cmd; // Verify Assert.IsNotNull(logCmd.Inner); Assert.IsInstanceOfType(logCmd.Inner, typeof(ConcreteCommand <User>)); }
public void GenericInjectionIsCalled() { // Setup Container .RegisterType(typeof(ICommand <>), typeof(LoggingCommand <>), Invoke.Constructor(Resolve.Parameter(typeof(ICommand <>), "concrete")), Invoke.Method("ChainedExecute", Resolve.Parameter(typeof(ICommand <>), "inner"))) .RegisterType(typeof(ICommand <>), typeof(ConcreteCommand <>), "concrete") .RegisterType(typeof(ICommand <>), typeof(ConcreteCommand <>), "inner"); // Act ICommand <Account> result = Container.Resolve <ICommand <Account> >(); LoggingCommand <Account> lc = (LoggingCommand <Account>)result; // Verify Assert.IsTrue(lc.ChainedExecuteWasCalled); }
public void Injection_GenericPropertyIsActuallyInjected() { // Setup Container .RegisterType(typeof(ICommand <>), typeof(LoggingCommand <>), new InjectionConstructor(), Inject.Property("Inner", Resolve.Parameter(typeof(ICommand <>), "inner"))) .RegisterType(typeof(ICommand <>), typeof(ConcreteCommand <>), "inner"); // Act ICommand <Account> result = Container.Resolve <ICommand <Account> >(); // Verify LoggingCommand <Account> actualResult = (LoggingCommand <Account>)result; Assert.IsNotNull(actualResult.Inner); Assert.IsInstanceOfType(actualResult.Inner, typeof(ConcreteCommand <Account>)); }