Example #1
0
        public void CopyToBasicTest()
        {
            //Perform Test only if we use a db connection otherwise test case makes no sense
            if (TestInfrastructure.IsActive(TestContext) && TestInfrastructure.ConnectionType(TestContext) != "File")
            {
                IUser sourceUser = null;
                IUser targetUser = null;
                try
                {
                    string repositoryNameFinal = "finalTargetForCopyTest" + System.Environment.MachineName.ToLower();

                    //Do we have a target to copy from
                    Assert.IsTrue(File.Exists(TestDic), "Test Learning Module file cannot be found.");
                    ConnectionStringStruct sourceConnection = new ConnectionStringStruct(DatabaseType.Xml, CopyToTest.TestDic, false);
                    sourceUser = UserFactory.Create((GetLoginInformation) delegate(UserStruct u, ConnectionStringStruct c) { return(u); },
                                                    sourceConnection, (DataAccessErrorDelegate) delegate { return; }, this);
                    if (!authenticationUsers.ContainsKey(sourceConnection.ConnectionString))
                    {
                        authenticationUsers.Add(sourceConnection.ConnectionString, sourceUser.AuthenticationStruct);
                    }

                    //Copy the reference LM to the new persistent LM
                    ConnectionStringStruct dbConnection;
                    using (Dictionary dbTarget = TestInfrastructure.GetConnection(TestContext))
                    {
                        IUser dbUser = dbTarget.DictionaryDAL.Parent.CurrentUser;
                        dbConnection = dbUser.ConnectionString;
                        if (!authenticationUsers.ContainsKey(dbConnection.ConnectionString))
                        {
                            authenticationUsers.Add(dbConnection.ConnectionString, dbUser.AuthenticationStruct);
                        }
                        dbTarget.Dispose();

                        finished = false;
                        LearnLogic.CopyToFinished += new EventHandler(LearnLogic_CopyToFinished);
                        LearnLogic.CopyLearningModule(sourceConnection, dbConnection,
                                                      GetUser, (MLifter.DAL.Tools.CopyToProgress) delegate(string m, double p) { return; }, (DataAccessErrorDelegate) delegate { return; }, null);
                        while (!finished)
                        {
                            System.Threading.Thread.Sleep(100);
                        }
                        ;
                        LearnLogic.CopyToFinished -= new EventHandler(LearnLogic_CopyToFinished);
                    }


                    //copy to another persistent LM where we use Save to store as odx again
                    ConnectionStringStruct targetConnection;
                    using (Dictionary target = TestInfrastructure.GetPersistentLMConnection(TestContext, "sqlce"))
                    {
                        targetUser       = target.DictionaryDAL.Parent.CurrentUser;
                        targetConnection = targetUser.ConnectionString;
                        if (!authenticationUsers.ContainsKey(targetConnection.ConnectionString))
                        {
                            authenticationUsers.Add(targetConnection.ConnectionString, targetUser.AuthenticationStruct);
                        }
                        target.Dispose();

                        finished = false;
                        LearnLogic.CopyToFinished += new EventHandler(LearnLogic_CopyToFinished);
                        LearnLogic.CopyLearningModule(dbConnection, targetConnection,
                                                      GetUser, (MLifter.DAL.Tools.CopyToProgress) delegate(string m, double p) { return; }, (DataAccessErrorDelegate) delegate { return; }, null);
                        while (!finished)
                        {
                            System.Threading.Thread.Sleep(100);
                        }
                        ;
                        LearnLogic.CopyToFinished -= new EventHandler(LearnLogic_CopyToFinished);
                    }


                    using (Dictionary source = new Dictionary(sourceUser.Open(), null))
                        using (Dictionary target = new Dictionary(targetUser.Open(), null))
                        {
                            CompareChapters(source.Chapters.Chapters, target.Chapters.Chapters);

                            //Verification Code compare finalTarget with the reference target
                            CompareCards(source.Cards.Cards, target.Cards.Cards, source, target);

                            //Compare Settings
                            CompareSettings(source.Settings, target.Settings);
                            if ((source.Settings != null) && (target.Settings != null))
                            {
                                //Compare Styles
                                CompareStyles(source.Settings.Style, target.Settings.Style);
                            }
                        }
                }
                finally
                {
                    if (sourceUser != null)
                    {
                        sourceUser.Logout();
                    }
                    if (targetUser != null)
                    {
                        targetUser.Logout();
                    }
                }
            }
        }