public void GeneratorAddSingleColumnTestDuplicateTo() { Configuration configuration = new Configuration(new[] { "-g", "addcustomernametoUsers" }); TestFileWriter file_writer = new TestFileWriter(); IHumpbackCommand target = new Generator(configuration, Settings, file_writer); target.Execute(); Assert.Null(file_writer.FileContents); }
public void GeneratorAddTableNoColumnsSpecified() { Configuration configuration = new Configuration(new[] { "-g", "Users" }); TestFileWriter file_writer = new TestFileWriter(); IHumpbackCommand target = new Generator(configuration, Settings, file_writer); target.Execute(); Assert.True(file_writer.FileName.Contains("Users")); Assert.True(file_writer.FileContents.Contains("create_table")); Assert.True(file_writer.FileContents.Contains("drop_table")); }
public void GeneratorFileTest() { Configuration configuration = new Configuration(new[] { "-g", "File", "mysqlfile" }); TestFileWriter file_writer = new TestFileWriter(); IHumpbackCommand target = new Generator(configuration, Settings, file_writer); target.Execute(); Assert.True(file_writer.FileName.Contains("File")); Assert.True(file_writer.FileContents.Contains("file")); Assert.True(file_writer.FileContents.Contains("mysqlfile")); Assert.True(file_writer.FileContents.Contains("up")); }
public void GeneratorRemoveColumn() { Configuration configuration = new Configuration(new[] { "-g", "Removefirst_nameFromUsers" }); TestFileWriter file_writer = new TestFileWriter(); IHumpbackCommand target = new Generator(configuration, Settings, file_writer); target.Execute(); Assert.True(file_writer.FileName.Contains("Users")); Assert.True(file_writer.FileName.Contains("RemoveColumn")); Assert.True(file_writer.FileContents.Contains("remove_column")); Assert.True(file_writer.FileContents.Contains("up")); Assert.True(file_writer.FileContents.Contains("first_name")); }
public void GeneratorDropTable() { Configuration configuration = new Configuration(new[] { "-g", "DropUsers" }); TestFileWriter file_writer = new TestFileWriter(); IHumpbackCommand target = new Generator(configuration, Settings, file_writer); target.Execute(); Assert.IsTrue(file_writer.FileName.Contains("Users")); Assert.IsTrue(file_writer.FileName.Contains("DropTable")); Assert.IsTrue(file_writer.FileContents.Contains("drop_table")); Assert.IsTrue(file_writer.FileContents.Contains("up")); Assert.IsTrue(file_writer.FileContents.Contains("Users")); }
public void GeneratorAddSingleColumnTest_Escaped_To() { Configuration configuration = new Configuration(new[] { "-g", "addcustomer_name_to_Users" }); TestFileWriter file_writer = new TestFileWriter(); IHumpbackCommand target = new Generator(configuration, Settings, file_writer); target.Execute(); Assert.True(file_writer.FileName.Contains("Users")); Assert.True(file_writer.FileName.Contains("AddColumn")); Assert.True(file_writer.FileContents.Contains("add_column")); Assert.True(file_writer.FileContents.Contains("up")); Assert.True(file_writer.FileContents.Contains("customer_name")); }
public void GeneratorSqlTest() { Configuration configuration = new Configuration(new[] { "-g", "SQL", "CREATE TABLE Users (ID {pk}, first_name {string} NOT NULL, price_paid {money})" }); TestFileWriter file_writer = new TestFileWriter(); IHumpbackCommand target = new Generator(configuration, Settings, file_writer); target.Execute(); Assert.True(file_writer.FileName.Contains("SQL")); Assert.True(file_writer.FileContents.Contains("CREATE TABLE Users (ID {pk}, first_name {string} NOT NULL, price_paid {money})")); Assert.True(file_writer.FileContents.Contains("up")); Assert.True(file_writer.FileContents.Contains("down")); Assert.True(file_writer.FileContents.Contains("\"down\":\"\"")); }
public void GeneratorDropIndexTest() { Configuration configuration = new Configuration(new[] { "-g", "removeindexfromUsers", "first_name", "last_name" }); TestFileWriter file_writer = new TestFileWriter(); IHumpbackCommand target = new Generator(configuration, Settings, file_writer); target.Execute(); Assert.True(file_writer.FileName.Contains("Users")); Assert.True(file_writer.FileName.Contains("RemoveIndex")); Assert.True(file_writer.FileContents.Contains("remove_index")); Assert.True(file_writer.FileContents.Contains("up")); Assert.True(file_writer.FileContents.Contains("first_name")); Assert.True(file_writer.FileContents.Contains("last_name")); }
public void GeneratorAddReferenceColumnTest() { Configuration configuration = new Configuration(new[] { "-g", "AddUserToOrders", "User:reference" }); TestFileWriter file_writer = new TestFileWriter(); IHumpbackCommand target = new Generator(configuration, Settings, file_writer); target.Execute(); Assert.True(file_writer.FileName.Contains("AddColumn_Orders_UserId")); Assert.True(file_writer.FileContents.Contains("add_column")); Assert.True(file_writer.FileContents.Contains("up")); Assert.True(file_writer.FileContents.Contains("\"name\":\"User\",\"type\":\"reference\"}]")); Assert.True(file_writer.FileContents.Contains("remove_column")); Assert.True(file_writer.FileContents.Contains("\"column\":\"UserId\"")); }
public void GeneratorChangeSingleColumnTest() { Configuration configuration = new Configuration(new[] { "-g", "ChangeUsers", "first_name:string" }); TestFileWriter file_writer = new TestFileWriter(); IHumpbackCommand target = new Generator(configuration, Settings, file_writer); target.Execute(); Assert.True(file_writer.FileName.Contains("Users")); Assert.True(file_writer.FileName.Contains("ChangeColumn")); Assert.True(file_writer.FileContents.Contains("change_column")); Assert.True(file_writer.FileContents.Contains("up")); Assert.True(file_writer.FileContents.Contains("first_name")); Assert.True(file_writer.FileContents.Contains("down")); }
public void SqlFormatterDropIndexTest() { Configuration configuration = new Configuration(new[] { "-s", "7" }); TestFileWriter file_writer = new TestFileWriter(); ISqlFormatter formatter = new SQLServerFormatter(configuration, Settings); IMigrationProvider migrations = new TestMigrationProvider(); IHumpbackCommand target = new GenerateSQL(configuration, Settings, formatter, file_writer, migrations); migrations.SetMigrationNumber(6); // add index target.Execute(); Console.WriteLine(file_writer.FileContents); Assert.True(file_writer.FileName.Contains("7")); Assert.True(file_writer.FileContents.Contains("DROP INDEX [categories].[IX_categories_title_slug]")); }
public void SqlFormatterDropTableTest() { Configuration configuration = new Configuration(new[] { "-s", "2" }); TestFileWriter file_writer = new TestFileWriter(); ISqlFormatter formatter = new SQLServerFormatter(configuration, Settings); IMigrationProvider migrations = new TestMigrationProvider(); IHumpbackCommand target = new GenerateSQL(configuration, Settings, formatter, file_writer, migrations); migrations.SetMigrationNumber(2); // drop table target.Execute(); Console.WriteLine(file_writer.FileContents); Assert.True(file_writer.FileName.Contains("2")); Assert.True(file_writer.FileContents.Contains("DROP TABLE [tname]")); }
public void SqlFormatterAddIndexTest() { Configuration configuration = new Configuration(new[] { "-s", "6" }); TestFileWriter file_writer = new TestFileWriter(); ISqlFormatter formatter = new SQLServerFormatter(configuration, Settings); IMigrationProvider migrations = new TestMigrationProvider(); IHumpbackCommand target = new GenerateSQL(configuration, Settings, formatter, file_writer, migrations); migrations.SetMigrationNumber(5); // add index target.Execute(); Console.WriteLine(file_writer.FileContents); Assert.True(file_writer.FileName.Contains("6")); Assert.True(file_writer.FileContents.Contains("CREATE NONCLUSTERED INDEX [IX_categories_title_slug] ON [categories] ( [title] ASC, [slug] ASC )")); }
public void GeneratorAddMultipleColumnTest() { Configuration configuration = new Configuration(new[] { "-g", "addfirst_nametoUsers", "first_name:string", "last_name:string" }); TestFileWriter file_writer = new TestFileWriter(); IHumpbackCommand target = new Generator(configuration, Settings, file_writer); target.Execute(); Assert.True(file_writer.FileName.Contains("Users")); Assert.True(file_writer.FileName.Contains("AddColumn")); Assert.True(file_writer.FileContents.Contains("add_column")); Assert.True(file_writer.FileContents.Contains("up")); Assert.True(file_writer.FileContents.Contains("first_name")); Assert.True(file_writer.FileContents.Contains("last_name")); }
public void GeneratorAddTable1Column() { Configuration configuration = new Configuration(new[] { "-g", "Users", "first_name:string" }); TestFileWriter file_writer = new TestFileWriter(); IHumpbackCommand target = new Generator(configuration, Settings, file_writer); target.Execute(); Assert.IsTrue(file_writer.FileName.Contains("Users")); Assert.IsTrue(file_writer.FileContents.Contains("up")); Assert.IsTrue(file_writer.FileContents.Contains("down")); Assert.IsTrue(file_writer.FileContents.Contains("create_table")); Assert.IsTrue(file_writer.FileContents.Contains("Users")); Assert.IsTrue(file_writer.FileContents.Contains("drop_table")); Assert.IsTrue(file_writer.FileContents.Contains("first_name")); }
public void TestGeneratePlainSQLStringArrayDown() { var json = "{\"down\":[\"DELETE FROM [Control] WHERE ControlName LIKE '%Date Label'\",\"DELETE FROM [Control] WHERE ControlName LIKE '%Date Label'\"]}"; //json = "{\"down\":[\"DELETE FROM [Control] WHERE ControlName = 'Facebook Status'\",\"DELETE FROM [ControlType] WHERE ControlTypeName = 'Facebook'\"]}"; Configuration configuration = new Configuration(new[] { "-s", "1" }); TestFileWriter file_writer = new TestFileWriter(); ISqlFormatter formatter = new SQLServerFormatter(configuration, Settings); TestSQLDatabaseProvider _database_provider = new TestSQLDatabaseProvider(configuration, Settings, formatter); dynamic migration_object = Helpers.DeserializeMigration(json); _database_provider.ExecuteDownCommand(migration_object); Assert.AreEqual("DELETE FROM [Control] WHERE ControlName LIKE '%Date Label'DELETE FROM [Control] WHERE ControlName LIKE '%Date Label'", _database_provider.LastCommand); }
public void TestGeneratePlainSQLString() { var json = "{\"up\":\"DELETE FROM [Control] WHERE ControlName LIKE '%Date Label'\"}"; Configuration configuration = new Configuration(new[] { "-s", "1" }); TestFileWriter file_writer = new TestFileWriter(); ISqlFormatter formatter = new SQLServerFormatter(configuration, Settings); TestSQLDatabaseProvider _database_provider = new TestSQLDatabaseProvider(configuration, Settings, formatter); dynamic migration_object = Helpers.DeserializeMigration(json); _database_provider.ExecuteUpCommand(migration_object); Assert.Equal("DELETE FROM [Control] WHERE ControlName LIKE '%Date Label'", _database_provider.LastCommand); }
public void SqlFormatterDropColumnTest() { Configuration configuration = new Configuration(new[] { "-s", "5" }); TestFileWriter file_writer = new TestFileWriter(); ISqlFormatter formatter = new SQLServerFormatter(configuration, Settings); IMigrationProvider migrations = new TestMigrationProvider(); IHumpbackCommand target = new GenerateSQL(configuration, Settings, formatter, file_writer, migrations); migrations.SetMigrationNumber(4); // change col target.Execute(); Console.WriteLine(file_writer.FileContents); Assert.IsTrue(file_writer.FileName.Contains("5")); Assert.IsTrue(file_writer.FileContents.Contains("ALTER TABLE [tname]")); Assert.IsTrue(file_writer.FileContents.Contains("DROP COLUMN [name]")); }
public void SqlFormatterAddColumnTest() { Configuration configuration = new Configuration(new[] { "-s", "3" }); TestFileWriter file_writer = new TestFileWriter(); ISqlFormatter formatter = new SQLServerFormatter(configuration, Settings); IMigrationProvider migrations = new TestMigrationProvider(); IHumpbackCommand target = new GenerateSQL(configuration, Settings, formatter, file_writer, migrations); migrations.SetMigrationNumber(3); // add col target.Execute(); Console.WriteLine(file_writer.FileContents); Assert.True(file_writer.FileName.Contains("3")); Assert.True(file_writer.FileContents.Contains("ALTER TABLE [tname]")); Assert.True(file_writer.FileContents.Contains("ADD [name]")); Assert.True(file_writer.FileContents.Contains("nvarchar(255)")); }
public void SqlFormatterAddColumnReferenceTest() { Configuration configuration = new Configuration(new[] { "-s", "9" }); TestFileWriter file_writer = new TestFileWriter(); ISqlFormatter formatter = new SQLServerFormatter(configuration, Settings); IMigrationProvider migrations = new TestMigrationProvider(); IHumpbackCommand target = new GenerateSQL(configuration, Settings, formatter, file_writer, migrations); //migrations.SetMigrationNumber(9); // add col target.Execute(); Console.WriteLine(file_writer.FileContents); Assert.True(file_writer.FileName.Contains("9")); Assert.True(file_writer.FileContents.Contains("FK_orders_user_userid")); Assert.True(file_writer.FileContents.Contains("ALTER TABLE [Orders] ADD [UserId] INT NOT NULL")); Assert.True(file_writer.FileContents.Contains("ALTER TABLE [Orders] ADD CONSTRAINT [FK_orders_user_userid] FOREIGN KEY ([UserId]) REFERENCES [User] ([Id]) ON DELETE NO ACTION ON UPDATE NO ACTION")); }
public void BuildAndSaveFile_DependentUsingCalculatorIsCorrect() { var fileWriter = new TestFileWriter(); var validationMock = new Mock <IValidationHelper>(); var res = new List <ValidationResult>() as ICollection <ValidationResult>; validationMock.Setup(x => x.IsModelValid(It.IsAny <object>(), out res)).Returns(true); var bldr = new CSVImportBuilder(validationMock.Object); bldr.SetWriter(fileWriter); var delimiter = ','; var opts = new string[] { "opt1", "opt2", "opt3" }; bldr.AddColumn(new RandomizedColumn("col1") { ColumnOrder = 1, RandomizationOptions = opts }); bldr.AddColumn(new DependentColumn("col2") { ColumnOrder = 1, DependsOn = "col1", Calculator = Dependent1Calc }); bldr.SetDelimiter(delimiter); bldr.SetRowCount(4); bldr.BuildAndSaveFile(); var file = fileWriter.InMemoryFileContents; using (StringReader rdr = new StringReader(file)) { rdr.ReadLine(); string line; while ((line = rdr.ReadLine()) != null) { var parts = line.Split(delimiter); if (parts[1] != depMap[parts[0]]) { throw new Exception(); } } } }
/// <summary> /// Deletes test from the list /// </summary> private void DeleteTest() { // Check if user has selected any test if (!TestListViewModel.Instance.IsAnySelected) { return; } // Confirm var vm = new DecisionDialogViewModel { Title = "Usuwanie testu", Message = "Czy jesteś pewny, że chcesz usunąć ten test?", AcceptText = LocalizationResource.Yes, CancelText = LocalizationResource.No }; DI.UI.ShowMessage(vm); // No if (!vm.UserResponse) { return; } try { // Finally try to delete selected test TestFileWriter.DeleteFile(TestListViewModel.Instance.SelectedItem); } catch (Exception ex) { // If an error occured, show info to the user DI.UI.ShowMessage(new MessageBoxDialogViewModel { Title = LocalizationResource.DeletionError, Message = "Nie udało się usunąć tego testu." + "\n" + LocalizationResource.ErrorContentSemicolon + ex.Message, OkText = LocalizationResource.Ok }); DI.Logger.Log("Unable to delete test from local folder, error message: " + ex.Message); } // Update test list TestListViewModel.Instance.LoadItems(); }
public void SqlFormatterAddTableReferenceTest() { Configuration configuration = new Configuration(new[] { "-s", "10" }); TestFileWriter file_writer = new TestFileWriter(); ISqlFormatter formatter = new SQLServerFormatter(configuration, Settings); IMigrationProvider migrations = new TestMigrationProvider(); IHumpbackCommand target = new GenerateSQL(configuration, Settings, formatter, file_writer, migrations); //migrations.SetMigrationNumber(10); // add col target.Execute(); Console.WriteLine(file_writer.FileContents); Assert.True(file_writer.FileName.Contains("10")); Assert.True(file_writer.FileContents.Contains("FK_applicationcontrol_applicationpage_applicationpageid")); Assert.True(file_writer.FileContents.Contains("FK_applicationcontrol_application_applicationid")); Assert.True(file_writer.FileContents.Contains("FOREIGN KEY ([ApplicationPageId]) REFERENCES [ApplicationPage] ([Id])")); Assert.True(file_writer.FileContents.Contains("FOREIGN KEY ([ApplicationId]) REFERENCES [Application] ([Id])")); }
public void GeneratorAddTableMultipleColumnWithNullable() { Configuration configuration = new Configuration(new[] { "-g", "Users", "first_name:string:false", "last_name:string:true:'welty'" }); TestFileWriter file_writer = new TestFileWriter(); IHumpbackCommand target = new Generator(configuration, Settings, file_writer); target.Execute(); Assert.True(file_writer.FileName.Contains("Users")); Assert.True(file_writer.FileContents.Contains("create_table")); Assert.True(file_writer.FileContents.Contains("up")); Assert.True(file_writer.FileContents.Contains("down")); Assert.True(file_writer.FileContents.Contains("drop_table")); Assert.True(file_writer.FileContents.Contains("first_name")); Assert.True(file_writer.FileContents.Contains("last_name")); Assert.True(file_writer.FileContents.Contains("\"nullable\":false")); Assert.True(file_writer.FileContents.Contains("\"default\":\"'welty'\"")); Assert.True(file_writer.FileContents.Contains("full_audit")); }
public void SqlFormatterAddTableTest() { Configuration configuration = new Configuration(new[] { "-s", "1" }); TestFileWriter file_writer = new TestFileWriter(); ISqlFormatter formatter = new SQLServerFormatter(configuration, Settings); IMigrationProvider migrations = new TestMigrationProvider(); IHumpbackCommand target = new GenerateSQL(configuration, Settings, formatter, file_writer, migrations); migrations.SetMigrationNumber(1); // create table target.Execute(); Console.WriteLine(file_writer.FileContents); Assert.True(file_writer.FileName.Contains("1")); Assert.True(file_writer.FileContents.Contains("CREATE TABLE [tname]")); Assert.True(file_writer.FileContents.Contains("[first_name] nvarchar(255)")); Assert.True(file_writer.FileContents.Contains("[last_name] decimal")); Assert.True(file_writer.FileContents.Contains("CreatedOn datetime DEFAULT getutcdate() NOT NULL")); Assert.True(file_writer.FileContents.Contains("Id")); Assert.True(file_writer.FileContents.Contains("PRIMARY KEY")); }
public void BuildAndSaveFile_AutoIncrementIsCorrect() { var fileWriter = new TestFileWriter(); var validationMock = new Mock <IValidationHelper>(); var res = new List <ValidationResult>() as ICollection <ValidationResult>; validationMock.Setup(x => x.IsModelValid(It.IsAny <object>(), out res)).Returns(true); var bldr = new CSVImportBuilder(validationMock.Object); bldr.SetWriter(fileWriter); var start = 1; var increment = 2; bldr.AddColumn(new AutoIncrementedColumn("col1") { ColumnOrder = 1, StartingSequenceNumber = start, IncrementValue = increment }); bldr.SetDelimiter(','); bldr.SetRowCount(4); bldr.BuildAndSaveFile(); var file = fileWriter.InMemoryFileContents; using (StringReader rdr = new StringReader(file)) { rdr.ReadLine(); string line = rdr.ReadLine(); int prev = Convert.ToInt32(line); while ((line = rdr.ReadLine()) != null) { var curr = Convert.ToInt32(line); if (curr != (prev + increment)) { throw new Exception(); } prev = curr; } } }
public void BuildAndSaveFile_RandomizedIsCorrect() { var fileWriter = new TestFileWriter(); var validationMock = new Mock <IValidationHelper>(); var res = new List <ValidationResult>() as ICollection <ValidationResult>; validationMock.Setup(x => x.IsModelValid(It.IsAny <object>(), out res)).Returns(true); var bldr = new CSVImportBuilder(validationMock.Object); bldr.SetWriter(fileWriter); var opts = new string[] { "opt1", "opt2", "opt3" }; bldr.AddColumn(new RandomizedColumn("col1") { ColumnOrder = 1, RandomizationOptions = opts }); bldr.SetDelimiter(','); bldr.SetRowCount(4); bldr.BuildAndSaveFile(); var file = fileWriter.InMemoryFileContents; using (StringReader rdr = new StringReader(file)) { rdr.ReadLine(); string line; while ((line = rdr.ReadLine()) != null) { if (!opts.Any(x => x == line)) { throw new Exception(); } } } }
public void BuildAndSaveFile_IncompleteModelValidationError() { var fileWriter = new TestFileWriter(); var validationMock = new Mock <IValidationHelper>(); var res = new List <ValidationResult>() as ICollection <ValidationResult>; validationMock.Setup(x => x.IsModelValid(It.IsAny <object>(), out res)).Returns(false); var bldr = new CSVImportBuilder(validationMock.Object); bldr.SetWriter(fileWriter); var start = 1; var increment = 2; bldr.AddColumn(new AutoIncrementedColumn("col1") { ColumnOrder = 1, StartingSequenceNumber = start, IncrementValue = increment }); bldr.BuildAndSaveFile(); }
public static int numDistinctContractViolPlans = 0; // counts the # of plans that violates contract (may violate same contract) public PlanManager(RandoopConfiguration config) { this.config = config; builderPlans = new PlanDataBase("builderPlans", config.typematchingmode); exceptionPlans = new PlanDataBase("exceptionThrowingPlans", config.typematchingmode); observerPlans = new PlanDataBase("observerPlans", config.typematchingmode); Plan.UniqueIdCounter = config.planstartid; switch (config.directoryStrategy) { case DirectoryStrategy.Single: testFileWriter = new SingleDirectoryTestFileWriter(new DirectoryInfo(config.outputdir), config.useRandoopContracts); break; case DirectoryStrategy.ClassifyingByBehavior: testFileWriter = new ClassifyingByBehaviorTestFileWriter(new DirectoryInfo(config.outputdir), config.useRandoopContracts); break; case DirectoryStrategy.ClassifyingByClass: testFileWriter = new ClassifyingByClassTestFileWriter(new DirectoryInfo(config.outputdir), config.useRandoopContracts); break; } }
public void should_output_expected_json_when_writing_test_file() { // given var contract = new SerializationContract(); var testFile = new TestFile { Filename = "I SHOULD ALSO NOT EXIST", EngineVersion = 3, Variables = new List <Variable> { new Variable { Environment = new Environment { Name = "Env1", Order = 1234 }, Name = "Variable 1", Value = "Value 1" }, new Variable { Environment = new Environment { Name = "Env2", Order = 4321 }, Name = "Variable 2", Value = "Value 2" } }, Tests = new List <Test> { new Test { Method = "POST", AvailableVariables = new List <Variable> { new Variable { Name = _blackListText } }, Assertions = new List <Assertion> { new Assertion { Value = "Awesome Value", AssertionMethod = AssertionMethod.CssSelector, AssertionType = AssertionType.Negative, Description = "I SHOULD DO A THING", Log = _blackListText, Success = true, TransformedValue = _blackListText } }, Description = "Some Test", ScriptSnippets = new ScriptSnippets() { BeforeExecuteFilename = "uploadfile.snippet" }, CapturedVariables = new List <CapturedVariable> { new CapturedVariable { Name = "Captured Var 1", Regex = "/w/t/SOMETHING", PostProcessorType = VariablePostProcessorType.HtmlDecode } }, ExpectedHttpStatusCode = HttpStatusCode.BadRequest, Headers = new List <HeaderItem> { new HeaderItem { Key = "Some Key", Value = "Some Value" } }, PostBody = "SOOOO MANY PROPERTIES, I am getting bored", Url = "FML", TestConditions = new TestConditions { RequiredEnvironments = new List <string> { "int", "prod" } } } } }; // when var writer = new TestFileWriter(contract); string result = writer.Write(testFile); // then string expectedJson = TestHelpers.ReadEmbeddedFile("full-test-file.json", _jsonExamplesFolder); Assert.That(result.Replace("\r\n", "\n"), Is.EqualTo(expectedJson.Replace("\r\n", "\n"))); Assert.That(result, Does.Not.Contain(_blackListText)); }