Exemplo n.º 1
0
        public void Execute_ShouldReturnError_WhenLoadFails()
        {
            var        console = Container.Resolve <IConsole>();
            var        factory = Container.Resolve <IGitDependFileFactory>();
            string     dir;
            ReturnCode loadCode = ReturnCode.GitRepositoryNotFound;

            factory.Arrange(f => f.LoadFromDirectory(Arg.AnyString, out dir, out loadCode))
            .Returns(null as GitDependFile);

            StringBuilder output = new StringBuilder();

            console.Arrange(c => c.WriteLine(Arg.AnyObject))
            .DoInstead((object obj) =>
            {
                output.AppendLine(obj.ToString());
            });

            var options  = new ConfigSubOptions();
            var instance = new ConfigCommand(options);

            var code = instance.Execute();

            Assert.AreEqual(ReturnCode.GitRepositoryNotFound, code, "Invalid Return Code");
            Assert.AreEqual(string.Empty, output.ToString());
        }
Exemplo n.º 2
0
        public void Execute_ShouldPrintExistingConfig_WhenConfigExistsInGitRepo()
        {
            var        console = Container.Resolve <IConsole>();
            var        factory = Container.Resolve <IGitDependFileFactory>();
            string     dir;
            ReturnCode loadCode = ReturnCode.Success;

            factory.Arrange(f => f.LoadFromDirectory(Arg.AnyString, out dir, out loadCode))
            .Returns(Lib2Config);

            StringBuilder output = new StringBuilder();

            console.Arrange(c => c.WriteLine(Arg.AnyObject))
            .DoInstead((object obj) =>
            {
                output.AppendLine(obj.ToString());
            });

            var options  = new ConfigSubOptions();
            var instance = new ConfigCommand(options);

            var code = instance.Execute();

            Assert.AreEqual(ReturnCode.Success, code, "Invalid Return Code");
            Assert.AreEqual(Lib2Config.ToString() + Environment.NewLine, output.ToString());
        }
Exemplo n.º 3
0
        public override void Run(InitSubOptions options)
        {
            if (this.WriteHelp(options))
            {
                return;
            }

            if (this.SessionContext.IsInitialized)
            {
                throw new SessionAlreadyInitedException(this.SessionContext);
            }

            if (options.Inputs <= 0)
            {
                this.SessionContext.Output.WriteLine("Input length must be at least 1.");
                return;
            }

            if (options.HiddenInputs <= 0)
            {
                this.SessionContext.Output.WriteLine("Hidden neruon no must be at least 1.");
                return;
            }

            try
            {
                var dirInfo = Directory.CreateDirectory(this.SessionContext.ContextDirectory);
                dirInfo.Attributes = FileAttributes.Directory | FileAttributes.Hidden;
            }
            catch (IOException e)
            {
                throw new FileAccessException(this.SessionContext, e, this.SessionContext.ContextDirectory);
            }

            this.SessionContext.NeuronNetwork = new NeuronNetwork(options.Inputs, options.HiddenInputs, context: null);

            try
            {
                this.SessionContext.NeuronContextConfigPath.SerializeToPath(ConfigSubOptions.Default());
            }
            catch (Exception ex)
            {
                throw new ConfigWriteException(this.SessionContext, ex);
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// Creates a new <see cref="ShowConfigCommand"/>
 /// </summary>
 /// <param name="options">The <see cref="ConfigSubOptions"/> that configures the command.</param>
 public ShowConfigCommand(ConfigSubOptions options)
 {
     _options = options;
     _console = DependencyInjection.Resolve <IConsole>();
     _factory = DependencyInjection.Resolve <IGitDependFileFactory>();
 }