private void BuildToolsPackages(ITestOutputHelper logger)
        {
            if (_toolsBuilt)
            {
                return;
            }
            _toolsBuilt = true;
            var start        = new DateTime(2015, 1, 1);
            var seconds      = (long)(DateTime.UtcNow - start).TotalSeconds;
            var suffix       = "t" + seconds.ToString("x").PadLeft(9, (char)'0');
            var toolsProject = JsonConvert.DeserializeAnonymousType(
                File.ReadAllText(
                    Path.Combine(_solutionDir, "src", "Microsoft.EntityFrameworkCore.Tools", Constants.ProjectFileName)),
                new { version = "" });

            _toolVersion = toolsProject.version.Replace("*", suffix);


            foreach (var pkg in PackagesToBuild)
            {
                logger?.WriteLine($"Building {pkg} version {_toolVersion}");
                // TODO can remove when https://github.com/NuGet/Home/issues/2469 is available
                AssertCommand.Pass(
                    new PackCommand(
                        Path.Combine(_solutionDir, "src", pkg, Constants.ProjectFileName),
                        _localArtifacts,
                        logger)
                    .Execute($"--version-suffix {suffix}"));
            }
        }
Esempio n. 2
0
        private void AddAndApplyMigrationImpl(
            string project,
            string contextName,
            string migrationName)
        {
            var targetProject = Path.Combine(_fixture.TestProjectRoot, project, "project.json");
            var migrationDir  = Path.Combine(Path.GetDirectoryName(targetProject), "Migrations");
            var snapshotFile  = contextName + "ModelSnapshot.cs";

            if (Directory.Exists(migrationDir))
            {
                Assert.False(Directory.EnumerateFiles(migrationDir, snapshotFile, SearchOption.AllDirectories).Any());
            }

            _fixture.InstallTool(targetProject, _output, _fixture.TestProjectRoot);

            var args = $" --context {contextName}";

            AssertCommand.Pass(new MigrationAddCommand(targetProject, migrationName, _output)
                               .Execute(args));

            Assert.True(Directory.EnumerateFiles(migrationDir, snapshotFile, SearchOption.AllDirectories).Any());

            AssertCommand.Pass(new DatabaseUpdateCommand(targetProject, _output)
                               .Execute(args));
        }
Esempio n. 3
0
        public void MigrationsForAspNetApp()
        {
            var libraryProject = Path.Combine(_fixture.TestProjectRoot, "LibraryUsingSqlite", "project.json");

            AssertCommand.Pass(new RestoreCommand(libraryProject, _output)
                               .Execute(" --verbosity error "));

            AddAndApplyMigrationImpl("AspNetHostingPortableApp", "LibraryContext", "initialLibrary");
            AddAndApplyMigrationImpl("AspNetHostingPortableApp", "TestContext", "initialTest");
        }
Esempio n. 4
0
        public void AddMigrationToDifferentFolder()
        {
            var libraryProject = Path.Combine(_fixture.TestProjectRoot, "PortableApp", "project.json");

            Assert.False(Directory.Exists(Path.Combine(_fixture.TestProjectRoot, "SomeOtherDir")));

            _fixture.InstallTool(libraryProject, _output, _fixture.TestProjectRoot);

            AssertCommand.Pass(new MigrationAddCommand(libraryProject, "OtherFolderMigration", _output)
                               .Execute($" --context TestContext --output-dir ../SomeOtherDir"));

            Assert.True(Directory.Exists(Path.Combine(_fixture.TestProjectRoot, "SomeOtherDir")));
            Assert.True(Directory.EnumerateFiles(Path.Combine(_fixture.TestProjectRoot, "SomeOtherDir"), "*.cs").Any());
        }
        public void InstallTool(string projectPath, ITestOutputHelper logger, params string[] fallbackRestoreLocations)
        {
            BuildToolsPackages(logger);

            var json = File.ReadAllText(projectPath);

            File.WriteAllText(projectPath, json.Replace("$toolVersion$", _toolVersion));
            var fallbacks = new[] { _localArtifacts }
            .Concat(fallbackRestoreLocations ?? Enumerable.Empty <string>())
            .Select(s => "--fallbacksource " + s);

            AssertCommand.Pass(
                new RestoreCommand(projectPath, logger)
                .Execute(" --verbosity error " + string.Join(" ", fallbacks))
                );
        }
Esempio n. 6
0
        private void AddAndApplyMigrationImpl(
            string targetProjectName,
            string contextName,
            string migrationName,
            string startupProjectName = null)
        {
            var targetProject  = Path.Combine(_fixture.TestProjectRoot, targetProjectName, "project.json");
            var startupProject = startupProjectName != null
                ? Path.Combine(_fixture.TestProjectRoot, startupProjectName, "project.json")
                : null;

            _output.WriteLine("Target dir = " + targetProject);

            var migrationDir = Path.Combine(Path.GetDirectoryName(targetProject), "Migrations");
            var snapshotFile = contextName + "ModelSnapshot.cs";

            if (Directory.Exists(migrationDir))
            {
                Assert.False(Directory.EnumerateFiles(migrationDir, snapshotFile, SearchOption.AllDirectories).Any());
            }

            _fixture.InstallTool(targetProject, _output, _fixture.TestProjectRoot);

            if (startupProject != null)
            {
                _fixture.InstallTool(startupProject, _output, _fixture.TestProjectRoot);
            }

            var args = $"--context {contextName}";

            AssertCommand.Pass(new MigrationAddCommand(targetProject, migrationName, _output, startupProject)
                               .Execute(args));

            Assert.True(Directory.EnumerateFiles(migrationDir, snapshotFile, SearchOption.AllDirectories).Any());

            AssertCommand.Pass(new DatabaseUpdateCommand(targetProject, _output, startupProject)
                               .Execute(args));

            AssertCommand.Pass(new MigrationScriptCommand(targetProject, _output, startupProject)
                               .Execute("--output " + Path.Combine(Path.GetDirectoryName(targetProject), "obj/dotnet-ef/migrations.sql")));
        }