public override UpgradeEngine Given() { scriptProvider = Substitute.For <IScriptProvider>(); scriptProvider.GetScripts(Arg.Any <IConnectionManager>()).Returns(new List <SqlScript> { new SqlScript("1234", "foo") }); versionTracker = Substitute.For <IJournal>(); dbConnection = Substitute.For <IDbConnection>(); dbCommand = Substitute.For <IDbCommand>(); dbConnection.CreateCommand().Returns(dbCommand); var connectionManager = new TestConnectionManager(dbConnection); scriptExecutor = new SqlScriptExecutor(() => connectionManager, () => Substitute.For <IUpgradeLog>(), null, () => true, null, () => versionTracker); var builder = new UpgradeEngineBuilder() .WithScript(new SqlScript("1234", "create table $var$ (Id int)")) .JournalTo(versionTracker) .WithVariable("var", "sub"); builder.Configure(c => c.ScriptExecutor = scriptExecutor); builder.Configure(c => c.ConnectionManager = connectionManager); var upgrader = builder.Build(); return(upgrader); }
protected override void When() { var testConnectionManager = new TestConnectionManager(Substitute.For <IDbConnection>()); testConnectionManager.OperationStarting(new ConsoleUpgradeLog(), new List <SqlScript>()); scriptsToExecute = Subject.GetScripts(testConnectionManager).ToArray(); }
public void creates_a_new_journal_table_when_not_exist() { // Given var dbConnection = Substitute.For <IDbConnection>(); var connectionManager = new TestConnectionManager(dbConnection, true); var command = Substitute.For <IDbCommand>(); var param1 = Substitute.For <IDbDataParameter>(); var param2 = Substitute.For <IDbDataParameter>(); var param3 = Substitute.For <IDbDataParameter>(); dbConnection.CreateCommand().Returns(command); command.CreateParameter().Returns(param1, param2, param3); command.ExecuteScalar().Returns(x => 0); var consoleUpgradeLog = new ConsoleUpgradeLog(); var journal = new SQLiteTableJournal(() => connectionManager, () => consoleUpgradeLog, () => new Sha256Hasher(), "SchemaVersions"); // When journal.StoreExecutedScript(new SqlScript("test", "select 1"), () => command); // Expect command.Received(3).CreateParameter(); param1.ParameterName.ShouldBe("scriptName"); param3.ParameterName.ShouldBe("hash"); param2.ParameterName.ShouldBe("applied"); command.Received().ExecuteNonQuery(); }
public void CrudIntegrationTest() { //Read sample file IOrganizationService organisationService = new TestConnectionManager().CreateConnection(); DataImportManager importer = new DataImportManager(organisationService, new TestLogger()); var result = importer.ImportFile(@"..\..\..\Xrm.Framework.CI.Extensions\Schema\CRUD.sample.json"); }
public void ConnectionString_SetToEmptyThrows() { var target = new TestConnectionManager("Server=server1;Dabase=DB1"); Action a = () => target.SetConnectionString(""); a.Should().Throw <ArgumentException>(); }
public void Ctor_WithConnectionStringWorks() { var expectedString = "Server=server1;Database=DB1"; var target = new TestConnectionManager(expectedString); target.ConnectionString.Should().Be(expectedString); }
internal static SqlPersistence CreateSqlPersistence(ConnectionManager connectionManager) { var icons = TestConnectionManager.CreateTestFavoriteIcons(); var persistence = new SqlPersistence(icons, connectionManager); persistence.Initialize(); return(persistence); }
public void TestInvertedRange() { TestConnectionManager mgr = TestCommon.ObtainConnectionManager(); mgr.InjectChannelMessage(TestChannelName, "OneUser", "the quick brown fox jumps over the lazy dog"); mgr.InjectChannelMessage(TestChannelName, "AnotherUser", "tr/z-a/Z-A/"); Assert.Equal(0, mgr.EventLog.Count); }
public void TestUnterminatedPattern() { TestConnectionManager mgr = TestCommon.ObtainConnectionManager(); mgr.InjectChannelMessage(TestChannelName, "OneUser", "the quick brown fox jumps over the lazy dog"); mgr.InjectChannelMessage(TestChannelName, "AnotherUser", "s_the"); Assert.Equal(0, mgr.EventLog.Count); }
public void TestIndexTooEarly() { TestConnectionManager mgr = TestCommon.ObtainConnectionManager(); mgr.InjectChannelMessage(TestChannelName, "OneUser", "the quick brown fox jumps over the lazy dog"); mgr.InjectChannelMessage(TestChannelName, "AnotherUser", "s_the_a_-15"); Assert.Equal(0, mgr.EventLog.Count); }
public void TestRepeatNoLastTo() { TestConnectionManager mgr = TestCommon.ObtainConnectionManager(); mgr.InjectChannelMessage(TestChannelName, "OneUser", "the quick brown fox jumps over the lazy dog"); mgr.InjectChannelMessage(TestChannelName, "AnotherUser", "tr/a//r"); Assert.Equal(0, mgr.EventLog.Count); }
public void TestUnmatchedTransposition() { TestConnectionManager mgr = TestCommon.ObtainConnectionManager(); mgr.InjectChannelMessage(TestChannelName, "OneUser", "what is this i don't even"); mgr.InjectChannelMessage(TestChannelName, "AnotherUser", "tr/q/m/"); Assert.Equal(0, mgr.EventLog.Count); }
public void TestSetup() { this.sourceFavorite = this.AddFavorite("SourceFavorite"); this.sourceFavoriteNode = new FavoriteTreeNode(TestConnectionManager.CreateTestFavoriteIcons(), sourceFavorite, string.Empty); this.sourceGroup = this.AddNewGroup("SourceGroup"); this.sourceGroupNode = new GroupTreeNode(sourceGroup); this.targetFavorite = this.AddFavorite("TargetFavorite"); this.targetGroup = this.AddNewGroup("TargetGroup"); }
public void TestInvalidSeparator() { TestConnectionManager mgr = TestCommon.ObtainConnectionManager(); mgr.InjectChannelMessage(TestChannelName, "OneUser", "the quick brown fox jumps over the lazy dog"); mgr.InjectChannelMessage(TestChannelName, "AnotherUser", "s\\the\\a\\g"); Assert.Equal(0, mgr.EventLog.Count); }
public void TestUnmatchedReplacement() { TestConnectionManager mgr = TestCommon.ObtainConnectionManager(); mgr.InjectChannelMessage(TestChannelName, "OneUser", "the quick brown fox jumps over the lazy dog"); mgr.InjectChannelMessage(TestChannelName, "AnotherUser", "s+tiny++"); Assert.Equal(0, mgr.EventLog.Count); }
public void TestOverlongRange() { TestConnectionManager mgr = TestCommon.ObtainConnectionManager(); mgr.InjectChannelMessage(TestChannelName, "OneUser", "the quick brown fox jumps over the lazy dog"); mgr.InjectChannelMessage(TestChannelName, "AnotherUser", "tr/\u1000-\u2000/\u3000-\u4000/"); Assert.Equal(0, mgr.EventLog.Count); }
public void TestSkipTextAfterSpace() { TestConnectionManager mgr = TestCommon.ObtainConnectionManager(); mgr.InjectChannelMessage(TestChannelName, "OneUser", "the quick brown box jumps over the lazy dog"); mgr.InjectChannelMessage(TestChannelName, "AnotherUser", "s/box/fox/ dude duude"); mgr.InjectChannelMessage(TestChannelName, "AnotherUser", "s/box/fox/ dude"); Assert.Equal(0, mgr.EventLog.Count); }
public void ConnectionString_WithConnectionStringWorks() { var expected = "Server=server2;Dabase=db2"; var target = new TestConnectionManager("Server=server1;Dabase=DB1"); target.SetConnectionString(expected); target.ConnectionString.Should().Be(expected); }
public static TestConnectionManager ObtainConnectionManager() { var mgr = new TestConnectionManager(); var sedConfig = new JObject { ["RememberLastMessages"] = new JValue(50) }; var sed = new SedPlugin(mgr, sedConfig); return(mgr); }
public void CreateTestTreeStructure() { var favoriteIcons = TestConnectionManager.CreateTestFavoriteIcons(); this.treeView.AssignServices(this.Persistence, favoriteIcons, TestConnectionManager.Instance); this.CreateData(); // loaded tree is needed for all tests, if if there is a "load all test", which tests next line only this.treeLoader = new FavoriteTreeListLoader(this.treeView, this.Persistence, favoriteIcons); this.treeLoader.LoadRootNodes(); this.treeView.ExpandAllTreeNodes(); }
public void SetUp() { this.propertiesControl = new FavoritePropertiesControl(); Mock <IPersistence> persistenceStub = TestMocksFactory.CreatePersistence(); persistenceStub.SetupGet(p => p.Factory) .Returns(new Mock <IFactory>().Object); this.irelevantPersistence = persistenceStub.Object; FavoriteIcons favoriteIcons = TestConnectionManager.CreateTestFavoriteIcons(); this.propertiesControl.AssignServices(this.irelevantPersistence, TestConnectionManager.Instance, favoriteIcons); }
public void Ctor_WithConnectionStringNameWorks() { var connName = "Name1"; var expectedString = "Server=server1;Database=db1"; var mockProvider = new MemoryDataConfigurationProvider(); mockProvider.ConnectionStrings[connName] = expectedString; var target = new TestConnectionManager(connName, mockProvider); target.ConnectionString.Should().Be(expectedString); }
public void TestDeleteMissingTo() { TestConnectionManager mgr = TestCommon.ObtainConnectionManager(); mgr.InjectChannelMessage(TestChannelName, "OneUser", "the quick brown fox jumps over the lazy dog"); mgr.InjectChannelMessage(TestChannelName, "AnotherUser", "tr/aeiouy//d"); Assert.Equal(1, mgr.EventLog.Count); TestMessage sentMessage = Assert.IsType <TestMessage>(mgr.EventLog[0]); Assert.Equal(MessageType.Message, sentMessage.Type); Assert.Equal(TestChannelName, sentMessage.Target); Assert.Equal("th qck brwn fx jmps vr th lz dg", sentMessage.Body); }
public void TestRangeTransposition() { TestConnectionManager mgr = TestCommon.ObtainConnectionManager(); mgr.InjectChannelMessage(TestChannelName, "OneUser", "the quick brown fox jumps over the lazy dog"); mgr.InjectChannelMessage(TestChannelName, "AnotherUser", "tr_a-z_A-Z_"); Assert.Equal(1, mgr.EventLog.Count); TestMessage sentMessage = Assert.IsType <TestMessage>(mgr.EventLog[0]); Assert.Equal(MessageType.Message, sentMessage.Type); Assert.Equal(TestChannelName, sentMessage.Target); Assert.Equal("THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG", sentMessage.Body); }
public void TestEscapedSeparator() { TestConnectionManager mgr = TestCommon.ObtainConnectionManager(); mgr.InjectChannelMessage(TestChannelName, "OneUser", "how and/or why?"); mgr.InjectChannelMessage(TestChannelName, "YetAnotherUser", "s/and\\/or/and\\/or\\/xor\\/nand\\/n\\or/"); Assert.Equal(1, mgr.EventLog.Count); TestMessage sentMessage = Assert.IsType <TestMessage>(mgr.EventLog[0]); Assert.Equal(MessageType.Message, sentMessage.Type); Assert.Equal(TestChannelName, sentMessage.Target); Assert.Equal("how and/or/xor/nand/nor why?", sentMessage.Body); }
public void TestRangeMix() { TestConnectionManager mgr = TestCommon.ObtainConnectionManager(); mgr.InjectChannelMessage(TestChannelName, "OneUser", "the quick brown fox jumps over the lazy dog"); mgr.InjectChannelMessage(TestChannelName, "AnotherUser", "tr_a-bc-d_A-D_"); Assert.Equal(1, mgr.EventLog.Count); TestMessage sentMessage = Assert.IsType <TestMessage>(mgr.EventLog[0]); Assert.Equal(MessageType.Message, sentMessage.Type); Assert.Equal(TestChannelName, sentMessage.Target); Assert.Equal("the quiCk Brown fox jumps over the lAzy Dog", sentMessage.Body); }
public void TestMultipleReplacement() { TestConnectionManager mgr = TestCommon.ObtainConnectionManager(); mgr.InjectChannelMessage(TestChannelName, "OneUser", "the quick brown fox jumps over the lazy dog"); mgr.InjectChannelMessage(TestChannelName, "AnotherUser", "s_the_a_g"); Assert.Equal(1, mgr.EventLog.Count); TestMessage sentMessage = Assert.IsType <TestMessage>(mgr.EventLog[0]); Assert.Equal(MessageType.Message, sentMessage.Type); Assert.Equal(TestChannelName, sentMessage.Target); Assert.Equal("a quick brown fox jumps over a lazy dog", sentMessage.Body); }
public void TestRepeatLastTo() { TestConnectionManager mgr = TestCommon.ObtainConnectionManager(); mgr.InjectChannelMessage(TestChannelName, "OneUser", "the quick brown fox jumps over the lazy dog"); mgr.InjectChannelMessage(TestChannelName, "AnotherUser", "tr/aeiouy/q/r"); Assert.Equal(1, mgr.EventLog.Count); TestMessage sentMessage = Assert.IsType <TestMessage>(mgr.EventLog[0]); Assert.Equal(MessageType.Message, sentMessage.Type); Assert.Equal(TestChannelName, sentMessage.Target); Assert.Equal("thq qqqck brqwn fqx jqmps qvqr thq lqzq dqg", sentMessage.Body); }
public void TestMultiplePatterns() { TestConnectionManager mgr = TestCommon.ObtainConnectionManager(); mgr.InjectChannelMessage(TestChannelName, "OneUser", "a one, a two, a three, a four"); mgr.InjectChannelMessage(TestChannelName, "YetAnotherUser", " s_e_o_g s/a/e/g "); Assert.Equal(1, mgr.EventLog.Count); TestMessage sentMessage = Assert.IsType <TestMessage>(mgr.EventLog[0]); Assert.Equal(MessageType.Message, sentMessage.Type); Assert.Equal(TestChannelName, sentMessage.Target); Assert.Equal("e ono, e two, e throo, e four", sentMessage.Body); }
public void TestReplacementReferenceToGroup() { TestConnectionManager mgr = TestCommon.ObtainConnectionManager(); mgr.InjectChannelMessage(TestChannelName, "OneUser", "a one, a two, a three, a four"); mgr.InjectChannelMessage(TestChannelName, "YetAnotherUser", "s_(,)( a)_\\1 and\\2_g"); Assert.Equal(1, mgr.EventLog.Count); TestMessage sentMessage = Assert.IsType <TestMessage>(mgr.EventLog[0]); Assert.Equal(MessageType.Message, sentMessage.Type); Assert.Equal(TestChannelName, sentMessage.Target); Assert.Equal("a one, and a two, and a three, and a four", sentMessage.Body); }
public void creates_a_new_journal_table_when_not_exist() { // Given var dbConnection = Substitute.For<IDbConnection>(); var connectionManager = new TestConnectionManager(dbConnection, true); var command = Substitute.For<IDbCommand>(); var param = Substitute.For<IDbDataParameter>(); dbConnection.CreateCommand().Returns(command); command.CreateParameter().Returns(param); command.ExecuteScalar().Returns(x => { throw new SQLiteException("table not found"); }); var consoleUpgradeLog = new ConsoleUpgradeLog(); var journal = new SQLiteTableJournal(() => connectionManager, () => consoleUpgradeLog, "SchemaVersions"); // When journal.StoreExecutedScript(new SqlScript("test", "select 1")); // Expect command.Received().CreateParameter(); Assert.AreEqual("scriptName", param.ParameterName); command.Received().ExecuteNonQuery(); }
public DatabaseConnectionManagerTests() { connection = Substitute.For<IDbConnection>(); sut = new TestConnectionManager(connection); }