예제 #1
0
        public void XMLV3ReadWriteTest()
        {
            TVTDatabase initialDatabase = new TVTDatabase();

            initialDatabase.Initialize();

            var advertising = EntityHelper.GetIconicAdvertising();

            initialDatabase.AddAdvertising(advertising);

            var person = EntityHelper.GetIconicPerson("Wurst", "Hans");

            initialDatabase.AddPerson(person);

            //var programme = EntityHelper.GetIconicProgramme();
            //initialDatabase.AddProgramme( programme );

            var persister = new XmlPersisterV3();

            persister.SaveXML(initialDatabase, "UnitTestXMLV2.xml", DatabaseVersion.V3, DataStructure.FakeData);

            TVTDatabase loadDatabase = new TVTDatabase();

            loadDatabase.Initialize();

            persister.LoadXML("UnitTestXMLV2.xml", loadDatabase, DataStructure.FakeData);

            Assert.AreEqual(1, loadDatabase.GetAllAdvertisings().Count());
            var loadAdvertising = loadDatabase.GetAllAdvertisings().First();

            AssertAdvertisings(advertising, loadAdvertising, TestMode.XMLV3);

            Assert.AreEqual(1, loadDatabase.GetAllPeople().Count());
            var loadPerson = loadDatabase.GetAllPeople().First();

            AssertPeople(person, loadPerson, TestMode.XMLV3, true);

            //Assert.AreEqual( 1, loadDatabase.GetAllProgrammes().Count() );
            //var loadProgrammes = loadDatabase.GetAllProgrammes().First();
            //AssertProgrammes( programme, loadProgrammes, TestMode.XMLV3 );
        }
예제 #2
0
        public void B_ReadXMLV2AndMerge()
        {
            System.Diagnostics.Trace.WriteLine(Directory.GetCurrentDirectory());
            Assert.IsTrue(File.Exists("database.xml"));

            var databaseV2 = new TVTDatabase();

            databaseV2.Initialize();

            var persister = new XmlPersisterV2();

            persister.LoadXML("database.xml", databaseV2, TVTDataRoot.V2InUse);

            var sqlDB = new TVTDatabase();

            sqlDB.Initialize();
            sqlDB.Clear();
            using (var connection = TVTSQLSession.GetSessionNewDB())
            {
                string myConnectionString = "SERVER=localhost;" +
                                            "DATABASE=tvtower_new;" +
                                            "UID=TVTowerUser;" +
                                            "PASSWORD=123;";

                var mvSQLDatabase = new TVTSQLDatabase(myConnectionString);
                mvSQLDatabase.FillTVTDatabase(sqlDB);
            }

            var merging = new DatabaseMerging(sqlDB);

            {
                foreach (var currMovie in databaseV2.GetAllProgrammes(true, true))
                {
                    var found = merging.FindProgrammeMatch(currMovie);
                    if (found != null)
                    {
                        merging.MergeProgrammeData(found, currMovie, true);
                        found.DataRoot  = TVTDataRoot.V2InUse;
                        found.IsChanged = true;
                        foreach (var member in found.Staff)
                        {
                            if (member.Person != null)
                            {
                                member.Person.DataRoot  = TVTDataRoot.V2InUse;
                                member.Person.IsChanged = true;
                            }
                        }
                    }
                    else
                    {
                        var newProgramme = new TVTProgramme();
                        newProgramme.GenerateGuid();
                        merging.MergeProgrammeData(newProgramme, currMovie);
                        newProgramme.DataRoot  = TVTDataRoot.V2InUse;
                        newProgramme.IsNew     = true;
                        newProgramme.IsChanged = true;
                        foreach (var member in newProgramme.Staff)
                        {
                            member.Person.DataRoot  = TVTDataRoot.V2InUse;
                            member.Person.IsChanged = true;
                        }
                        sqlDB.AddProgramme(newProgramme);
                    }
                }
            }

            {
                foreach (var currNews in databaseV2.GetAllNews())
                {
                    var found = merging.FindNewsMatchWithV2(currNews);
                    if (found != null)
                    {
                        merging.MergeNewsData(found, currNews, true);
                        found.DataRoot  = TVTDataRoot.V2InUse;
                        found.IsChanged = true;
                    }
                    else
                    {
                        var newNews = new TVTNews();
                        newNews.GenerateGuid();
                        merging.CopyPropertyValues <TVTNews>(newNews, currNews);
                        newNews.DataRoot  = TVTDataRoot.V2InUse;
                        newNews.IsNew     = true;
                        newNews.IsChanged = true;
                        sqlDB.AddNews(newNews);
                    }
                }
            }

            {
                foreach (var currAd in databaseV2.GetAllAdvertisings())
                {
                    var found = merging.FindAdMatchWithV2(currAd);
                    if (found != null)
                    {
                        merging.CopyPropertyValues <TVTAdvertising>(found, currAd);
                        found.DataRoot  = TVTDataRoot.V2InUse;
                        found.IsChanged = true;
                    }
                    else
                    {
                        var newAd = new TVTAdvertising();
                        newAd.GenerateGuid();
                        merging.CopyPropertyValues <TVTAdvertising>(newAd, currAd);
                        newAd.DataRoot  = TVTDataRoot.V2InUse;
                        newAd.IsNew     = true;
                        newAd.IsChanged = true;
                        sqlDB.AddAdvertising(newAd);
                    }
                }
            }

            using (var connection = TVTSQLSession.GetSessionNewDB())
            {
                string myConnectionString = "SERVER=localhost;" +
                                            "DATABASE=tvtower_new;" +
                                            "UID=TVTowerUser;" +
                                            "PASSWORD=123;";

                var mvSQLDatabase = new TVTSQLDatabase(myConnectionString);
                mvSQLDatabase.WriteChangesToDatabase(sqlDB);
            }
        }
예제 #3
0
        public void C_ReadXMLV2AndMergeAdChanges()
        {
            System.Diagnostics.Trace.WriteLine(Directory.GetCurrentDirectory());
            Assert.IsTrue(File.Exists("ads-changes.xml"));

            var databaseV3 = new TVTDatabase();

            databaseV3.Initialize();

            var persister = new XmlPersisterV3();

            persister.LoadXMLV3Beta("ads-changes.xml", databaseV3);

            var sqlDB = new TVTDatabase();

            sqlDB.Initialize();
            sqlDB.Clear();
            using (var connection = TVTSQLSession.GetSessionNewDB())
            {
                string myConnectionString = "SERVER=localhost;" +
                                            "DATABASE=tvtower_new;" +
                                            "UID=TVTowerUser;" +
                                            "PASSWORD=123;";

                var mvSQLDatabase = new TVTSQLDatabase(myConnectionString);
                mvSQLDatabase.FillTVTDatabase(sqlDB);
            }

            var merging = new DatabaseMerging(sqlDB);

            {
                foreach (var currAd in databaseV3.GetAllAdvertisings())
                {
                    var found = merging.FindAdMatchWithV2(currAd);
                    if (found != null)
                    {
                        merging.CopyPropertyValues <TVTAdvertising>(found, currAd);
                        found.DataRoot  = TVTDataRoot.V2InUse;
                        found.IsChanged = true;
                    }
                    else
                    {
                        var newAd = new TVTAdvertising();
                        newAd.GenerateGuid();
                        merging.CopyPropertyValues <TVTAdvertising>(newAd, currAd);
                        newAd.DataRoot  = TVTDataRoot.V2InUse;
                        newAd.IsNew     = true;
                        newAd.IsChanged = true;
                        sqlDB.AddAdvertising(newAd);
                    }
                }
            }

            using (var connection = TVTSQLSession.GetSessionNewDB())
            {
                string myConnectionString = "SERVER=localhost;" +
                                            "DATABASE=tvtower_new;" +
                                            "UID=TVTowerUser;" +
                                            "PASSWORD=123;";

                var mvSQLDatabase = new TVTSQLDatabase(myConnectionString);
                mvSQLDatabase.WriteChangesToDatabase(sqlDB);
            }
        }
예제 #4
0
        //[TestMethod]
        public void A_ConvertOldToNewData()
        {
            var database = new TVTDatabase();

            database.Initialize();

            using (var connection = TVTSQLSession.GetSession())
            {
                var movies = TVTCommandsV2.LoadMoviesOldV2(connection);

                OldV2Converter.Convert(movies, database, TVTDataRoot.V2InStorage);

                TVTCommandsV2.LoadFakesForPeople(connection, database.GetAllPeople());

                OldV2Converter.RefreshMovieDescriptions(database);
                OldV2Converter.FakePersonNames(database);

                var ads = TVTCommandsV2.LoadAdsOldV2(connection);
                OldV2Converter.Convert(ads, database, TVTDataRoot.V2InStorage);

                var news = TVTCommandsV2.LoadNewsOldV2(connection);
                var tt   = news.FirstOrDefault(x => x.title.StartsWith("Programmierer"));
                OldV2Converter.Convert(news, database, TVTDataRoot.V2InStorage);

                database.RefreshPersonProgrammeCount();
                database.RefreshReferences();
                database.RefreshStatus();
            }

            using (var connection = TVTSQLSession.GetSessionNewDB())
            {
                TVTCommandsV3.Insert <TVTPerson>(connection, TVTCommandsV3.GetPersonSQLDefinition(), database.GetAllPeople());
                TVTCommandsV3.Insert <TVTProgramme>(connection, TVTCommandsV3.GetProgrammeSQLDefinition(), database.GetAllProgrammes(true, true));
                //TVTCommandsV3.Insert<TVTEpisode>( connection, TVTCommandsV3.GetEpisodeSQLDefinition(), database.GetAllEpisodes() );
                TVTCommandsV3.Insert <TVTAdvertising>(connection, TVTCommandsV3.GetAdvertisingSQLDefinition(), database.GetAllAdvertisings());
                TVTCommandsV3.Insert <TVTNews>(connection, TVTCommandsV3.GetNewsSQLDefinition(), database.GetAllNews());
            }
        }