Ejemplo n.º 1
0
        public void ConnectToServer()
        {
            var hicProjDir = LoadDirectory.CreateDirectoryStructure(new DirectoryInfo(TestContext.CurrentContext.TestDirectory), "MDFAttacherTest", true);

            var db = DiscoveredServerICanCreateRandomDatabasesAndTablesOn.ExpectDatabase("MyImaginaryDB_RAW");

            Assert.IsFalse(db.Exists());

            var mdf = new MDFAttacher();

            mdf.Initialize(hicProjDir, db);
            try
            {
                var memory = new ToMemoryCheckNotifier(new ThrowImmediatelyCheckNotifier());
                mdf.Check(memory);
                Assert.IsTrue(memory.Messages.Any(m => m.Message.Contains("Found server DATA folder") && m.Result == CheckResult.Success));
            }
            catch (Exception e)
            {
                if (!e.Message.Contains("Proposed server DATA folder (that we will copy mdf/ldf files to) was not found"))//this message is allowed too if the SQL server is remote and not localhost then it is quite likely that the DATA path is inaccessible from the unit test server
                {
                    throw;
                }
            }

            var memory2 = new ToMemoryCheckNotifier(new ThrowImmediatelyCheckNotifier());

            mdf.OverrideMDFFileCopyDestination = TestContext.CurrentContext.WorkDirectory;
            mdf.Check(memory2);
            Assert.IsTrue(memory2.Messages.Any(m => Regex.IsMatch(m.Message, @"Found server DATA folder .*" + Regex.Escape(TestContext.CurrentContext.WorkDirectory)) && m.Result == CheckResult.Success));

            hicProjDir.RootPath.Delete(true);
        }
Ejemplo n.º 2
0
        public void Test_MDFFile_AlreadyExists()
        {
            var workingDir = new DirectoryInfo(TestContext.CurrentContext.TestDirectory);

            var data = workingDir.CreateSubdirectory("data");

            var testDir       = workingDir.CreateSubdirectory("MDFAttacherTests");
            var loadDirectory = LoadDirectory.CreateDirectoryStructure(testDir, "TestNoMDFFileFoundException", true);

            try
            {
                // create mdf and ldf files (in ForLoading
                File.WriteAllText(Path.Combine(loadDirectory.ForLoading.FullName, "MyFile.mdf"), "fish");
                File.WriteAllText(Path.Combine(loadDirectory.ForLoading.FullName, "MyFile_log.ldf"), "fish");

                //create an already existing file in the 'data' directory (immitates the copy to location)
                File.WriteAllText(Path.Combine(data.FullName, "MyFile.mdf"), "fish");


                var attacher = new MDFAttacher();
                attacher.OverrideMDFFileCopyDestination = data.FullName;

                attacher.Initialize(loadDirectory, GetCleanedServer(FAnsi.DatabaseType.MicrosoftSQLServer));

                //should be a warning since overwritting is default behaviour
                var ex = Assert.Throws <Exception>(() =>
                                                   attacher.Attach(
                                                       new ThrowImmediatelyDataLoadJob(new ThrowImmediatelyDataLoadEventListener()
                {
                    ThrowOnWarning = true
                })
                                                       , new GracefulCancellationToken())
                                                   );

                StringAssert.Contains("mdf already exists", ex.Message);
            }
            finally
            {
                try
                {
                    testDir.Delete(true);
                }
                catch (IOException e)
                {
                    Console.WriteLine(e);
                }
            }
        }
Ejemplo n.º 3
0
        public void TestNoMDFFileFoundException()
        {
            var workingDir    = new DirectoryInfo(TestContext.CurrentContext.TestDirectory);
            var testDir       = workingDir.CreateSubdirectory("MDFAttacherTests");
            var loadDirectory = LoadDirectory.CreateDirectoryStructure(testDir, "TestNoMDFFileFoundException", true);

            try
            {
                var attacher = new MDFAttacher();
                attacher.Initialize(loadDirectory, GetCleanedServer(FAnsi.DatabaseType.MicrosoftSQLServer));
                Assert.Throws <FileNotFoundException>(() => attacher.Attach(new ThrowImmediatelyDataLoadJob(), new GracefulCancellationToken()));
            }
            finally
            {
                try
                {
                    testDir.Delete(true);
                }
                catch (IOException e)
                {
                    Console.WriteLine(e);
                }
            }
        }