コード例 #1
0
        /// <summary>
        /// Create the command object that will be used to act on the repository.
        /// </summary>
        /// <returns>The command object that will be used to act on the
        ///     repository.</returns>
        /// <exception cref="Exception">TODO: Make a more specific exception</exception>
        /// <exception cref="NotImplementedException">If the command argument
        ///     is not implemented currently.  TODO: Implement the argument.</exception>
        public override ICommand CreateCommand()
        {
            ICSharpCode.SharpCvsLib.Commands.ImportModuleCommand importCommand;
            try {
                this.ParseOptions(this.unparsedOptions);
                CurrentWorkingDirectory = new WorkingDirectory(this.cvsRoot,
                                                               Environment.CurrentDirectory, this.repository);
                Manager manager = new Manager(Environment.CurrentDirectory);

                DirectoryInfo importDir = new DirectoryInfo(Environment.CurrentDirectory);

                if (!importDir.Exists)
                {
                    ConsoleMain.ExitProgram("Import directory does not exist.");
                }

                CurrentWorkingDirectory.Folders =
                    manager.FetchFilesToAdd(importDir.FullName);
                importCommand =
                    new ICSharpCode.SharpCvsLib.Commands.ImportModuleCommand(
                        CurrentWorkingDirectory, this.message);

                importCommand.VendorString  = this.vendor;
                importCommand.ReleaseString = this.release;
                importCommand.LogMessage    = this.message;
//                importCommand.Repository = this.repository;
            }
            catch (Exception e) {
                LOGGER.Error(e);
                throw e;
            }
            return(importCommand);
        }
コード例 #2
0
        /// <summary>
        /// Process the login command with cvs library API calls.
        /// </summary>
        public void Execute()
        {
            if (null != this.CvsRoot && this.CvsRoot.TransportProtocol !=
                ICSharpCode.SharpCvsLib.Misc.CvsRoot.ProtocolType.pserver)
            {
                LOGGER.Debug(string.Format("cvs [login aborted]: The :{0}: protocol does not support the login command",
                                           this.CvsRoot.Protocol));
                return;
            }

            CVSServerConnection serverConn =
                new CVSServerConnection(CurrentWorkingDirectory);

            try {
                serverConn.Connect(CurrentWorkingDirectory, password);
            } catch (ICSharpCode.SharpCvsLib.Exceptions.AuthenticationException) {
                try {
                    this.password =
                        PServerProtocol.PromptForPassword(this.CvsRoot.ToString());
                    if (this.password == null)
                    {
                        this.password = string.Empty;
                    }
                    Manager manager = new Manager(this.workingDirectory.LocalDirectory);
                    manager.UpdatePassFile(this.password, this.CvsRoot);

                    serverConn.Connect(CurrentWorkingDirectory, password);
                } catch (ICSharpCode.SharpCvsLib.Exceptions.AuthenticationException e) {
                    ConsoleMain.ExitProgram(e.Message);
                }
            }
        }
コード例 #3
0
ファイル: ConsoleUnitTests.cs プロジェクト: kjhf/SplatTag
        public void ConsoleNoArguments()
        {
            using StringWriter sw = new StringWriter();
            Console.SetOut(sw);
            Console.SetError(sw);
            string expected = CHOOSE_A_FUNCTION;

            var timeoutTask     = Task.Delay(MAX_WAIT_TIME);
            var mainTask        = Task.Run(() => ConsoleMain.Main(Array.Empty <string>()));
            var successfulCheck = Task.Run(() =>
            {
                for (; ;)
                {
                    string actual = sw.ToString().Base64DecodeByLines();
                    if (actual.Contains(expected))
                    {
                        break;
                    }
                    Thread.Sleep(250);
                }
            });

            Task.WaitAny(timeoutTask, mainTask, successfulCheck);
            Console.SetOut(consoleOut);
            Console.SetError(consoleError);
            string actual = sw.ToString();

            Console.WriteLine("==================================================");
            Console.WriteLine(actual);
            Console.WriteLine("==================================================");
            Console.WriteLine(actual = actual.Base64DecodeByLines());
            Console.WriteLine("==================================================");
            Assert.IsTrue(actual.Contains(expected));
        }
コード例 #4
0
        protected void Dispose(bool disposing)
        {
            if (_debug > 0)
            {
                Console.WriteLine("TelnetSSH-Dispose-End");
            }

            if (!this.disposed)
            {
                if (disposing)
                {
                    _isRunning = false;
                    this.close();
                    if (_Console != null)
                    {
                        _Console = null;
                    }
                    if (_terminalOptions != null)
                    {
                        _terminalOptions = null;
                    }
                    if (_terminalSettings != null)
                    {
                        _terminalSettings = null;
                    }
                }

                //free unmanaged objects
                //AdditionalCleanup();

                this.disposed = true;
            }
        }
コード例 #5
0
ファイル: ConsoleUnitTests.cs プロジェクト: kjhf/SplatTag
        public void ConsoleSingleQuery()
        {
            using StringWriter sw = new StringWriter();
            Console.SetOut(sw);
            Console.SetError(sw);

            var timeoutTask = Task.Delay(MAX_WAIT_TIME);
            // This task will end once Slapp completes as --keepOpen is not specified
            var mainTask = Task.Run(async() =>
            {
                await ConsoleMain.Main("--query Slate".Split(" ")).ConfigureAwait(false);
                await Task.Delay(500).ConfigureAwait(false); // Let any logging finish.
            });

            Task.WaitAny(timeoutTask, mainTask);
            Console.SetOut(consoleOut);
            Console.SetError(consoleError);
            string actual = sw.ToString();

            Console.WriteLine("==================================================");
            Console.WriteLine(actual);
            Console.WriteLine("==================================================");
            Console.WriteLine(actual = actual.Base64DecodeByLines());
            Console.WriteLine("==================================================");

            Assert.IsTrue(actual.Contains(MESSAGE_OK));
            Assert.IsTrue(actual.Contains("kjhf1273"));
            Assert.IsTrue(actual.Contains("Inkology"));
            Assert.IsTrue(actual.Contains("Revitalize"));
            Assert.IsTrue(actual.Contains("2019-03-25-LUTI-S8")); // Check sources populated
            Assert.IsTrue(actual.Count("UNLINKED") == 1);         // Check no unlinked teams (except the one specified in Additional Sources)
            Assert.IsTrue(actual.Count("Built-in") >= 1);         // Check for built-in sources (one specified in Additional Sources)
        }
コード例 #6
0
        public void MakeAddCommandTest()
        {
            String fullPath = null;

            Directory.CreateDirectory(settings.Config.LocalPath);
            Environment.CurrentDirectory = settings.Config.LocalPath;
            // add file TargetFile
            // commit file TargetFile
            // remove file TargetFile
            // commit remove TargetFile
            String[] files = Directory.GetFiles(Path.Combine(Environment.CurrentDirectory,
                                                             settings.Config.Module), settings.Config.TargetFile);
            Assert.IsTrue(files.Length > 0);

            foreach (String file in files)
            {
                LOGGER.Debug("file=[" + file + "]");
                // Remove the .txt when everything works, giving me bugs...
                String newFileName = Guid.NewGuid().ToString() + ".txt";
                fullPath = Path.Combine(Path.Combine(Environment.CurrentDirectory, settings.Config.Module), newFileName);
                File.Copy(file, fullPath);
            }
            String commandLine = "-d" + settings.Config.Cvsroot + " add " + fullPath;

            String [] commandLineArgs = commandLine.Split(' ');
            // Create consoleMain object to test the Add command
            ConsoleMain consoleMain = new ConsoleMain();

            Assert.IsNotNull(consoleMain);

            consoleMain.Execute(commandLineArgs);
            Assert.IsTrue(File.Exists(fullPath));
        }
コード例 #7
0
 public TelnetSSHLogin()
 {
     _instance         = this;
     _isRunning        = true;
     _Console          = new ConsoleMain();
     _terminalOptions  = new TerminalOptions("");
     _terminalSettings = new TerminalSettings();
     _timeout          = _Console.ProtocolOptions.SocketConnectTimeout / 1000;
 }
コード例 #8
0
        public void MakeMainTest()
        {
            // Test Creating a ConsoleMain object
            ConsoleMain newMain = new ConsoleMain();

            String[] args = { "--help" };

            // Execute the Execute method
            newMain.Execute(args);
        }
コード例 #9
0
        public void HelpCommandTest()
        {
            // Test Creating a ConsoleMain object
            ConsoleMain newMain = new ConsoleMain();

            String[] args = { "--help-commands" };

            // Execute the Execute method
            newMain.Execute(args);
        }
コード例 #10
0
        public void MinusdOptionCheckoutFileIntoDir()
        {
            String commandLine = "-d" + settings.Config.Cvsroot + " co -d newlocation " + settings.Config.Module;

            String [] commandLineArgs = commandLine.Split(' ');
            // Test Creating a ConsoleMain object
            ConsoleMain consoleMain = new ConsoleMain();

            Assert.IsNotNull(consoleMain);
            consoleMain.Execute(commandLineArgs);
            Assert.IsTrue(Directory.Exists(Path.Combine(settings.Config.LocalPath, "newlocation")));
        }
コード例 #11
0
        public void MakeInitCommandTest()
        {
            Directory.CreateDirectory(settings.Config.LocalPath);
            Environment.CurrentDirectory = settings.Config.LocalPath;
            String commandLine = "-d" + settings.Config.Cvsroot + " init";

            String [] commandLineArgs = commandLine.Split(' ');
            // Create a consoleMain to test the InitCommand
            ConsoleMain consoleMain = new ConsoleMain();

            Assert.IsNotNull(consoleMain);
            consoleMain.Execute(commandLineArgs);
        }
コード例 #12
0
        public void MinusrOptionCheckoutFilesBasedOnRevision()
        {
            String commandLine = "-d" + settings.Config.Cvsroot + " co -r " + settings.Config.Tag1 +
                                 " " + settings.Config.Module;

            String [] commandLineArgs = commandLine.Split(' ');
            // Test Creating a ConsoleMain object
            ConsoleMain consoleMain = new ConsoleMain();

            consoleMain.Execute(commandLineArgs);
            // check for directory
            Assert.IsTrue(Directory.Exists(Path.Combine(settings.Config.LocalPath, settings.Config.Module)));
            // check for files with specified revision
        }
コード例 #13
0
        public void MinusrOptionCommitFilesBasedOnRevision()
        {
            Directory.CreateDirectory(settings.Config.LocalPath);
            Environment.CurrentDirectory = settings.Config.LocalPath;

            String commandLine =
                "-d" + settings.Config.Cvsroot + " ci -r " + settings.Config.Tag1 +
                " " + Path.Combine(settings.Config.LocalPath, settings.Config.TargetFile);

            String [] commandLineArgs = commandLine.Split(' ');
            // Test Creating a CommitCommand object
            ConsoleMain consoleMain = new ConsoleMain();

            consoleMain.Execute(commandLineArgs);
        }
コード例 #14
0
        public void MinusrOptionRTagFilesBasedOnRevision()
        {
            Directory.CreateDirectory(settings.Config.LocalPath);
            Environment.CurrentDirectory = settings.Config.LocalPath;

            String commandLine = "-d" + settings.Config.Cvsroot + " rt -r " +
                                 settings.Config.Tag1 + " " + settings.Config.Module;

            String [] commandLineArgs = commandLine.Split(' ');
            // Test Create the consoleMain to test the console RTagCommand
            ConsoleMain consoleMain = new ConsoleMain();

            consoleMain.Execute(commandLineArgs);
            Assert.IsNotNull(consoleMain);
        }
コード例 #15
0
        public void MakeUpdateCommandTest()
        {
            Directory.CreateDirectory(settings.Config.LocalPath);
            Environment.CurrentDirectory = settings.Config.LocalPath;

            String commandLine = "-d" + settings.Config.Cvsroot + " up " +
                                 Path.Combine(settings.Config.LocalPath, settings.Config.TargetFile);

            String [] commandLineArgs = commandLine.Split(' ');
            // Test Creating a consoleMain object to test the UpdateCommand object
            ConsoleMain consoleMain = new ConsoleMain();

            consoleMain.Execute(commandLineArgs);
            Assert.IsNotNull(consoleMain);
        }
コード例 #16
0
        public void MakeCheckoutCommandTest()
        {
            Directory.CreateDirectory(settings.Config.LocalPath);
            Environment.CurrentDirectory = settings.Config.LocalPath;

            String commandLine =
                "-d" + settings.Config.Cvsroot + " co " + settings.Config.Module;

            String [] commandLineArgs = commandLine.Split(' ');
            // Test Creating a ConsoleMain object
            ConsoleMain consoleMain = new ConsoleMain();

            consoleMain.Execute(commandLineArgs);
            Assert.IsTrue(Directory.Exists(Path.Combine(settings.Config.LocalPath, settings.Config.Module)));
        }
コード例 #17
0
        public void MinusdOptionUpdateFileIntoDir()
        {
            Directory.CreateDirectory(settings.Config.LocalPath);
            Environment.CurrentDirectory = settings.Config.LocalPath;
            String commandLine = "-d" + settings.Config.Cvsroot + " up -d newlocation " +
                                 Path.Combine(settings.Config.LocalPath, settings.Config.TargetFile);

            String [] commandLineArgs = commandLine.Split(' ');
            // Test Creating a ConsoleMain object to test the UpdateCommand object
            ConsoleMain consoleMain = new ConsoleMain();

            Assert.IsNotNull(consoleMain);
            consoleMain.Execute(commandLineArgs);
            Assert.IsTrue(Directory.Exists(Path.Combine(settings.Config.LocalPath, "newlocation")));
        }
コード例 #18
0
        public void MinusDOptionRTagByCertainDate()
        {
            Directory.CreateDirectory(settings.Config.LocalPath);
            Environment.CurrentDirectory = settings.Config.LocalPath;

            String commandLine = "-d" + settings.Config.Cvsroot + " rt -D " +
                                 Path.Combine(settings.Config.LocalPath, settings.Config.TargetFile) +
                                 " " + settings.Config.Module;

            String [] commandLineArgs = commandLine.Split(' ');
            // Test Create the consoleMain to test the console RTagCommand
            ConsoleMain consoleMain = new ConsoleMain();

            consoleMain.Execute(commandLineArgs);
            Assert.IsNotNull(consoleMain);
        }
コード例 #19
0
        public void MakeCommitCommandTest()
        {
            Directory.CreateDirectory(settings.Config.LocalPath);
            Environment.CurrentDirectory = settings.Config.LocalPath;

            String commandLine =
                "-d" + settings.Config.Cvsroot + " ci " +
                Path.Combine(settings.Config.LocalPath, settings.Config.TargetFile);

            String [] commandLineArgs = commandLine.Split(' ');
            // Test Creating a CommitCommand object
            ConsoleMain consoleMain = new ConsoleMain();

            consoleMain.Execute(commandLineArgs);
            //Assertion.Assert (Directory.Exists(Path.Combine(settings.Config.LocalPath, settings.Config.TargetFile)));
        }
コード例 #20
0
        public void MinusDOptionCommitFilesWithMsg()
        {
            Directory.CreateDirectory(settings.Config.LocalPath);
            Environment.CurrentDirectory = settings.Config.LocalPath;

            String commandLine =
                "-d" + settings.Config.Cvsroot + " ci -m thismessage " +
                Path.Combine(settings.Config.LocalPath, settings.Config.TargetFile);

            String [] commandLineArgs = commandLine.Split(' ');
            // Test Creating a CommitCommand object
            ConsoleMain consoleMain = new ConsoleMain();

            consoleMain.Execute(commandLineArgs);
            // Verify file with new message text
            //Assertion.Assert ("Should have found the check file.  file=[" +
            //    checkFile + "]", File.Exists (checkFile));
        }
コード例 #21
0
        public void MinusDOptionCheckoutByCertainDate()
        {
            String commandLine = "-d" + settings.Config.Cvsroot + " co -D 09.13.03 " + settings.Config.Module;

            String [] commandLineArgs = commandLine.Split(' ');
            // Test Creating a ConsoleMain object
            ConsoleMain consoleMain = new ConsoleMain();

            Assert.IsNotNull(consoleMain);
            consoleMain.Execute(commandLineArgs);
            Assert.IsTrue(Directory.Exists(Path.Combine(settings.Config.LocalPath, settings.Config.Module)));
            // Find a file that should exist
            //Assertion.Assert ("Should have found the check file.  file=[" +
            //    checkFile + "]", File.Exists (checkFile));

            // Find a file that should not exist
            //Assertion.Assert ("Should have found the check file.  file=[" +
            //    checkFile + "]", File.Exists (checkFile));
        }
コード例 #22
0
        public void MakeRemoveCommandTest()
        {
            Directory.CreateDirectory(settings.Config.LocalPath);
            Environment.CurrentDirectory = settings.Config.LocalPath;
            // add file TargetFile
            // commit file TargetFile
            // remove file TargetFile
            // commit remove TargetFile
            String commandLine = "-d" + settings.Config.Cvsroot + " rm " +
                                 Path.Combine(settings.Config.LocalPath, settings.Config.TargetFile);

            String [] commandLineArgs = commandLine.Split(' ');
            // Test Creating a RemoveCommand object
            ConsoleMain consoleMain = new ConsoleMain();

            Assert.IsNotNull(consoleMain);

            consoleMain.Execute(commandLineArgs);
            Assert.IsTrue(!File.Exists(Path.Combine(settings.Config.LocalPath, settings.Config.TargetFile)));
        }
コード例 #23
0
        private void Run()
        {
            ConsoleMain.InvokeMember("Main", BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.Static, null, null, new object[] { new string[] { "//r", this._settingsFile } });

            this.RestorConsoleOutput();

            lock (SyncLock)
            {
                Signal = true;
            }

            if (File.Exists(this._settingsFile))
            {
                this.Log(Level.Verbose, "Deleting settings file: " + this._settingsFile);
                File.Delete(this._settingsFile);
            }
            if (this._registerProfiler)
            {
                NCoverUtilities.UnregisterNCover();
            }
        }
コード例 #24
0
        public void TestBug884798_OneSpace()
        {
            Environment.CurrentDirectory = this.GetTempPath();
            String commandLine =
                "-d:pserver:[email protected]:/home/cvs/src co -d sharpcvslib-new -r HEAD sharpcvslib-test-repository";
            // Create new process

            ConsoleMain main = new ConsoleMain();

            try {
                main.Execute(commandLine.Split(' '));
            } catch (Exception e) {
                LOGGER.Error(e);
                Assert.Fail(e.ToString());
            }
            Manager manager = new Manager(this.GetTempPath());
            String  modDir  = Path.Combine(this.GetTempPath(), this.settings.Config.Module);
            Tag     tag     = manager.FetchTag(Path.Combine(modDir, "src"));

            Assert.IsNotNull(tag);
            Assert.AreEqual("NHEAD", tag.FileContents);
        }
コード例 #25
0
        public void MinusDOptionUpdateByCertainDate()
        {
            Directory.CreateDirectory(settings.Config.LocalPath);
            Environment.CurrentDirectory = settings.Config.LocalPath;
            String commandLine = "-d" + settings.Config.Cvsroot + " up -D 01.28.03 " +
                                 Path.Combine(settings.Config.LocalPath, settings.Config.TargetFile);

            String [] commandLineArgs = commandLine.Split(' ');

            // Test Creating a ConsoleMain object to test the UpdateCommand object
            ConsoleMain consoleMain = new ConsoleMain();

            Assert.IsNotNull(consoleMain);
            consoleMain.Execute(commandLineArgs);
            // Find a file that should exist
            //Assertion.Assert ("Should have found the update file.  file=[" +
            //    checkFile + "]", File.Exists (checkFile));

            // Find a file that should not exist
            //Assertion.Assert ("Should have found the update file.  file=[" +
            //    checkFile + "]", File.Exists (checkFile));
        }
コード例 #26
0
        /// <summary>
        /// Create the command object that will be used to act on the repository.
        /// </summary>
        /// <returns>The command object that will be used to act on the
        ///     repository.</returns>
        /// <exception cref="Exception">TODO: Make a more specific exception</exception>
        /// <exception cref="NotImplementedException">If the command argument
        ///     is not implemented currently.  TODO: Implement the argument.</exception>
        public override ICommand CreateCommand()
        {
            ICSharpCode.SharpCvsLib.Commands.LogCommand logCommand;
            DirectoryInfo dir = new DirectoryInfo(Directory.GetCurrentDirectory());

            this.ParseOptions(this.unparsedOptions);
            try {
                Repository repository = Repository.Load(dir);
                if (null == repository || null == repository.FileContents)
                {
                    throw new CvsFileNotFoundException(
                              string.Format("Valid CVS\\Repository file not found in {0}",
                                            dir));
                }
                this.repository = repository.FileContents;
                Root root = Root.Load(dir);
                if (null == root || null == root.FileContents)
                {
                    throw new CvsFileNotFoundException(
                              string.Format("Valid CVS\\Root file not found in {0}",
                                            dir));
                }
                this.cvsRoot = new CvsRoot(root.FileContents);
            } catch (CvsFileNotFoundException e) {
                LOGGER.Error(e);
                ConsoleMain.ExitProgram("Not a CVS repository.", e);
            }

            CurrentWorkingDirectory = new WorkingDirectory(this.cvsRoot,
                                                           dir.FullName, this.repository);


            logCommand =
                new ICSharpCode.SharpCvsLib.Commands.LogCommand(
                    CurrentWorkingDirectory, folders);

            return(logCommand);
        }
コード例 #27
0
ファイル: ConsoleUnitTests.cs プロジェクト: kjhf/SplatTag
        public void ConsoleCaseSensitiveQuery()
        {
            Stopwatch stopwatch = new Stopwatch();

            using StringWriter sw = new StringWriter();
            Console.SetOut(sw);
            Console.SetError(sw);

            stopwatch.Start();
            var timeoutTask = Task.Delay(MAX_WAIT_TIME);
            // This task will end once Slapp completes as --keepOpen is not specified
            var mainTask = Task.Run(async() =>
            {
                await ConsoleMain.Main("--query slAte --exactCase".Split(" ")).ConfigureAwait(false);
                await Task.Delay(500).ConfigureAwait(false); // Let any logging finish.
            });

            Task.WaitAny(timeoutTask, mainTask);
            stopwatch.Stop();
            Console.SetOut(consoleOut);
            Console.SetError(consoleError);
            string actual = sw.ToString();

            Console.WriteLine("==================================================");
            Console.WriteLine(actual);
            Console.WriteLine("==================================================");
            Console.WriteLine(actual = actual.Base64DecodeByLines());
            Console.WriteLine("==================================================");

            // Should NOT contain the result because the name is "Slate"
            Assert.IsFalse(actual.Contains("kjhf1273"));
            Assert.IsTrue(actual.Contains(MESSAGE_OK));

            if (stopwatch.ElapsedMilliseconds > 3000)
            {
                Assert.Inconclusive($"Test passed but it took {stopwatch.ElapsedMilliseconds}ms which is unacceptable for a Console query. Aim for < 3 seconds.");
            }
        }
コード例 #28
0
ファイル: EndToEndUnitTests.cs プロジェクト: kjhf/SplatTag
        public void EndToEndPatch()
        {
            // First run the Rebuild function.
            EndToEndBuild();

            // Now we can patch
            using StringWriter sw = new StringWriter();
            Console.SetOut(sw);
            Console.SetError(sw);

            var mainTask = Task.Run(async() =>
            {
                await ConsoleMain.Main($"--verbose --patch {patchPath}".Split(" ")).ConfigureAwait(false);
                await Task.Delay(500).ConfigureAwait(false); // Let any logging finish.
            });

            Task.WaitAny(mainTask);

            Console.SetOut(consoleOut);
            Console.SetError(consoleError);
            string actual = sw.ToString();

            Console.WriteLine("==================================================");
            Console.WriteLine(actual = actual.Base64DecodeByLines());
            Console.WriteLine("==================================================");

            Assert.IsTrue(actual.Contains(MESSAGE_PATCHED), "Database patched message not found.");

            SplatTagJsonSnapshotDatabase splatTagJsonSnapshotDatabase = new SplatTagJsonSnapshotDatabase(current);

            (var players, var teams, var sources) = splatTagJsonSnapshotDatabase.LoadInline();

            var slates = players.Where(p => p.AllKnownNames.NamesMatch(new[] { new Name("Slate", Builtins.ManualSource) }));

            // Assertions.
            StringBuilder slateFailMessage = new StringBuilder()
                                             .AppendJoin("\n - ",
                                                         slates
                                                         .Select(p => new StringBuilder()
                                                                 .Append('[')
                                                                 .AppendJoin(", ", p.AllKnownNames)
                                                                 .Append(']')
                                                                 .Append(" -- Sourced from [")
                                                                 .AppendJoin(", ", p.Sources)
                                                                 .Append("] and teams [")
                                                                 .AppendJoin(", ", p.TeamInformation.GetAllTeamsUnordered())
                                                                 .Append("] and Battlefy Slugs [")
                                                                 .AppendJoin(", ", p.Battlefy.Slugs ?? Array.Empty <BattlefyUserSocial>())
                                                                 .Append("] top500=")
                                                                 .Append(p.Top500)
                                                                 .AppendLine(".")
                                                                 )
                                                         );

            Assert.AreEqual(3, slates.Count(), "Incorrect number of Slates:\n - " + slateFailMessage.ToString());

            var splatarians = teams.Where(p => p.Name.Value == "Splatarians");

            if (splatarians.Count() != 1)
            {
                StringBuilder failMessage = new StringBuilder();
                failMessage.Append("Incorrect number of Splatarians (").Append(splatarians.Count()).Append("):\n - ").AppendJoin("\n - ", splatarians).AppendLine();
                failMessage.Append("Sources (").Append(sources.Count).Append("):\n - ").AppendJoin("\n - ", sources).AppendLine();
                failMessage.Append("From:\n - ").AppendJoin("\n - ", splatarians.Select(t => string.Join(", ", t.Sources))).AppendLine();
                Assert.Fail(failMessage.ToString());
            }
            Assert.AreEqual("SX", splatarians.First().CurrentDiv.Season);
            Assert.IsTrue(splatarians.First().DivisionInformation.GetDivisionsUnordered().Any(d => d.Season == "S9"));

            // Check that the patching has happened
            Assert.AreEqual(5, sources.Count, "Unexpected number of sources loaded.");
            Assert.IsTrue(slates.Any(p => p.Top500), "Expected the patching to Slate to set top 500 flag -- " + slateFailMessage.ToString());
        }
コード例 #29
0
ファイル: EndToEndUnitTests.cs プロジェクト: kjhf/SplatTag
        public void EndToEndBuild()
        {
            using StringWriter sw = new StringWriter();
            Console.SetOut(sw);
            Console.SetError(sw);

            var mainTask = Task.Run(async() =>
            {
                await ConsoleMain.Main($"--verbose --rebuild {sourcesPath}".Split(" ")).ConfigureAwait(false);
                await Task.Delay(500).ConfigureAwait(false); // Let any logging finish.
            });

            Task.WaitAny(mainTask);

            Console.SetOut(consoleOut);
            Console.SetError(consoleError);
            string actual = sw.ToString();

            Console.WriteLine("==================================================");
            Console.WriteLine(actual = actual.Base64DecodeByLines());
            Console.WriteLine("==================================================");

            Assert.IsTrue(actual.Contains(MESSAGE_REBUILT), "Database rebuilt message not found.");

            // Contains the snapshots?
            Assert.AreEqual(3, SplatTagJsonSnapshotDatabase.GetSnapshots(current).Count());

            // Load.
            SplatTagJsonSnapshotDatabase splatTagJsonSnapshotDatabase = new SplatTagJsonSnapshotDatabase(current);

            (var players, var teams, var sources) = splatTagJsonSnapshotDatabase.LoadInline();
            Assert.IsNotNull(players, "Not expecting null return for players");
            Assert.IsNotNull(teams, "Not expecting null return for teams");
            Assert.IsNotNull(sources, "Not expecting null return for sources");

            // Assertions.
            Assert.AreEqual(2, players.Count(p => p.Name.Value.Contains("Slate")), "Incorrect number of Slates:\n - " +
                            new StringBuilder()
                            .AppendJoin("\n - ",
                                        players
                                        .Where(p => p.Name.Value.Contains("Slate"))
                                        .Select(p => new StringBuilder()
                                                .Append('[')
                                                .AppendJoin(", ", p.NamesInformation)
                                                .Append(']')
                                                .Append(" -- Sourced from [")
                                                .AppendJoin(", ", p.Sources)
                                                .Append("] and teams [")
                                                .AppendJoin(", ", p.TeamInformation.GetAllTeamsUnordered())
                                                .Append("] and Battlefy Slugs [")
                                                .AppendJoin(", ", p.Battlefy.Slugs ?? Array.Empty <BattlefyUserSocial>())
                                                .Append("] top500=")
                                                .Append(p.Top500)
                                                .AppendLine(".")
                                                )
                                        ));
            var splatarians = teams.Where(p => p.Name.Value == "Splatarians");

            Assert.AreEqual(1, splatarians.Count(), $"Incorrect number of Splatarians:\n - { string.Join("\n - ", splatarians)}");
            Assert.AreEqual("SX", splatarians.First().CurrentDiv.Season);
            Assert.IsTrue(splatarians.First().DivisionInformation.GetDivisionsUnordered().Any(d => d.Season == "S9"));
            Assert.AreEqual(4, sources.Count, "Unexpected number of sources loaded.");
            Assert.IsTrue(players.Where(p => p.Name.Value.Contains("Slate")).All(p => !p.Top500), "Expected Slate top 500 flag to be false.");
        }
コード例 #30
0
ファイル: ConsoleUnitTests.cs プロジェクト: kjhf/SplatTag
        public void ConsolePerist()
        {
            using (StringWriter sw = new StringWriter())
            {
                Console.SetOut(sw);
                Console.SetError(sw);
                Console.SetIn(new StringReader(string.Empty));

                using StringReader tr  = new StringReader("--b64 " + "ig manny".Base64Encode() + "\r\n--b64 " + "Slate".Base64Encode() + "\r\n"); // a TextReader -- also tests spaces.
                using StringReader tr2 = new StringReader("--b64 " + "thatsrb2dude".Base64Encode() + "\r\n");
                var timeoutTask = Task.Delay(MAX_WAIT_TIME);
                var mainTask    = Task.Run(async() =>
                {
                    Console.WriteLine($"[{DateTime.Now:HH:mm:ss.ff}] mainTask: Beginning.");
                    await ConsoleMain.Main("--keepOpen".Split(" ")).ConfigureAwait(false);
                    Console.WriteLine($"[{DateTime.Now:HH:mm:ss.ff}] mainTask: Finishing.");
                    await Task.Delay(500).ConfigureAwait(false); // Let any logging finish.
                });
                var externalInputTask = Task.Run(async() =>
                {
                    Console.WriteLine($"[{DateTime.Now:HH:mm:ss.ff}] externalInputTask: Waiting 3 seconds.");
                    await Task.Delay(3000).ConfigureAwait(false);
                    Console.WriteLine($"[{DateTime.Now:HH:mm:ss.ff}] externalInputTask: Setting first input.");
                    Console.SetIn(tr);

                    // Only move on when the input stream has been consumed.
                    while (tr.Peek() != -1)
                    {
                        await Task.Delay(250).ConfigureAwait(false);
                    }

                    Console.WriteLine($"[{DateTime.Now:HH:mm:ss.ff}] externalInputTask: Setting second input in 2 seconds.");
                    await Task.Delay(2000).ConfigureAwait(false);
                    Console.SetIn(tr2);
                    Console.WriteLine($"[{DateTime.Now:HH:mm:ss.ff}] externalInputTask: Input set, finishing.");
                });

                var successfulCheck = Task.Run(async() =>
                {
                    for (; ;)
                    {
                        string actual = sw.ToString().Base64DecodeByLines();
                        if (actual.Contains("Slate") && actual.Contains("ig manny") && actual.Contains("thatsrb2dude"))
                        {
                            Console.WriteLine($"[{DateTime.Now:HH:mm:ss.ff}] successfulCheck: Passed.");
                            break;
                        }
                        await Task.Delay(250).ConfigureAwait(false);
                    }

                    Console.WriteLine($"[{DateTime.Now:HH:mm:ss.ff}] successfulCheck: Finishing.");
                });

                bool timedOut = Task.WaitAny(timeoutTask, externalInputTask, mainTask) == 0;
                Console.WriteLine($"[{DateTime.Now:HH:mm:ss.ff}] timedOut={timedOut}");
                bool wasSuccessfulCheck = Task.WaitAny(timeoutTask, mainTask, successfulCheck) == 2;
                Console.WriteLine($"[{DateTime.Now:HH:mm:ss.ff}] wasSuccessfulCheck={wasSuccessfulCheck}");
                Console.WriteLine($"mainTask.IsCompleted={mainTask.IsCompleted}");
                Console.WriteLine($"externalInputTask.IsCompleted={externalInputTask.IsCompleted}");

                Console.SetOut(consoleOut);
                Console.SetError(consoleError);
                string actual = sw.ToString();
                Console.WriteLine("==================================================");
                Console.WriteLine(actual);
                Console.WriteLine("==================================================");
                Console.WriteLine(actual = actual.Base64DecodeByLines());
                Console.WriteLine("==================================================");

                Assert.IsTrue(actual.Contains(MESSAGE_OK), "Unexpected message result");
                if (actual.Contains(EMPTY_PLAYERS) && !actual.Contains(POPULATED_PLAYERS))
                {
                    Assert.Inconclusive("The test returned an empty players list. This may be because the database has not been populated. Do so and re-run the test.");
                }
                else
                {
                    Assert.IsTrue(actual.Contains(POPULATED_PLAYERS), "Doesn't contain matched players");
                    Assert.IsTrue(actual.Contains(SLATE), "Doesn't contain Slate");
                    Assert.IsTrue(actual.Contains("ig manny"), "Doesn't contain ig manny query");
                    Assert.IsTrue(actual.Contains("thatsrb2dude"), "Doesn't contain thatsrb2dude query");

                    Assert.IsTrue(actual.Contains("kjhf1273"), "Doesn't contain kjhf1273");
                    Assert.IsTrue(actual.Contains("Inkology"), "Doesn't contain Inkology");
                    Assert.IsTrue(actual.Contains("Revitalize"), "Doesn't contain Revitalize");
                    Assert.IsFalse(mainTask.IsCompleted, "The main task should not have completed because keepOpen is specified."); // Test last
                }
            }
        }