public override string ToString()
        {
            var sb = new StringBuilder();

            sb.AppendLine("{");

            if (Args?.Any() ?? false)
            {
                sb
                .AppendLine("Args: {")
                .AppendLine(DictToString(Args))
                .AppendLine("}");
            }

            if (Headers?.Any() ?? false)
            {
                sb
                .AppendLine("Headers: {")
                .AppendLine(DictToString(Headers))
                .AppendLine("}");
            }

            if (Url != null)
            {
                sb.AppendLine($"\tUrl: {Url}");
            }

            sb.AppendLine("}");

            return(sb.ToString());
        }
Beispiel #2
0
        public static async Task <DeleteResult> Delete <T>(bool DryRun, T APIObject, params string[] Args)
        {
            string Url = ServiceURI + "/" + typeof(T).GetApiEndPoint().Delete;

            if (Args.Any())
            {
                Url = string.Format(Url, Args);
            }

            Ext.GetLogger <CFHostOperator>().LogInformation((DryRun ? "Delete(DryRun): " : "Delete: ") + APIObject.ToString());

            if (DryRun)
            {
                return(new DeleteResult());
            }

            WebRequest Request = WebRequest.Create(Url);

            Request.Headers.Add(HttpRequestHeader.Authorization, $"Bearer {APIToken}");
            Request.Headers.Add(HttpRequestHeader.Accept, "application/json");
            Request.Method      = "DELETE";
            Request.ContentType = "application/json";

            WebResponse Response = await Request.GetResponseAsync();

            using var RespStream = Response.GetResponseStream();
            return(await JsonSerializer.DeserializeAsync <DeleteResult>(RespStream));
        }
Beispiel #3
0
 public string ArgsOutput()
 {
     if (!Args.Any())
     {
         return("");
     }
     return(string.Join(", ", Args.Select(a => $"{a.DotNetType} {a.Name}")));
 }
Beispiel #4
0
        private ICommand GetTargetCommand()
        {
            var globalProperties = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase)
            {
                // This property disables default item globbing to improve performance
                // This should be safe because we are not evaluating items, only properties
                { Constants.EnableDefaultItems, "false" },
                { Constants.MSBuildExtensionsPath, AppContext.BaseDirectory }
            };

            if (!string.IsNullOrWhiteSpace(Configuration))
            {
                globalProperties.Add("Configuration", Configuration);
            }

            if (!string.IsNullOrWhiteSpace(Framework))
            {
                globalProperties.Add("TargetFramework", Framework);
            }

            if (!string.IsNullOrWhiteSpace(Runtime))
            {
                globalProperties.Add("RuntimeIdentifier", Runtime);
            }

            var project = new ProjectInstance(Project, globalProperties, null);

            string runProgram = project.GetPropertyValue("RunCommand");

            if (string.IsNullOrEmpty(runProgram))
            {
                ThrowUnableToRunError(project);
            }

            string runArguments        = project.GetPropertyValue("RunArguments");
            string runWorkingDirectory = project.GetPropertyValue("RunWorkingDirectory");

            if (Args.Any())
            {
                runArguments += " " + ArgumentEscaper.EscapeAndConcatenateArgArrayForProcessStart(Args);
            }

            CommandSpec commandSpec = new CommandSpec(runProgram, runArguments);

            var command = CommandFactoryUsingResolver.Create(commandSpec)
                          .WorkingDirectory(runWorkingDirectory);

            var rootVariableName = Environment.Is64BitProcess ? "DOTNET_ROOT" : "DOTNET_ROOT(x86)";

            if (Environment.GetEnvironmentVariable(rootVariableName) == null)
            {
                command.EnvironmentVariable(rootVariableName, Path.GetDirectoryName(new Muxer().MuxerPath));
            }

            return(command);
        }
Beispiel #5
0
		public override string ToString() {
			string s = string.Format("Game {0:x8}: {1} ({2}) -> {3}", Game.FuzzyGameHash, Source.Card.Name, Source.Id, Action);
			if (Args != null && Args.Any()) {
				s += "(";
				foreach (var a in Args)
					s += a + ", ";
				s = s.Substring(0, s.Length - 2) + ")";
			}
			return s;
		}
        public string ArgsOutput()
        {
            if (!Args.Any())
            {
                return("");
            }
            var result = string.Join(", ", Args.Select(a => $"{(a.Required ? a.DotNetType.Trim('?') : a.DotNetType)} {a.Name}"));

            return(result);
        }
Beispiel #7
0
        private void ProcessArgs()
        {
            if (Args != null &&
                Args.Any(a => !string.IsNullOrEmpty(a) && a.ToLower() == "version"))
            {
                var fileVersionAttribute = GetAssemblyFileVersion(GetType().Assembly);

                Console.WriteLine(fileVersionAttribute.ToString());
                Environment.Exit(0);
            }
        }
 public async Task CanRouteWithParameterForParameterExpression()
 {
     await RouteAssert.ForAsync(
         _server,
         request => request.WithPathAndQuery("/parameter/query-string-parameter?parameter=value"),
         routeAssert => routeAssert
         .MapsTo <ParameterController>(a => a.QueryStringParameter(Args.Any <string>()))
         .ForParameter <string>("parameter", p =>
     {
         Assert.True(p == "value");
     }));
 }
 // This looks VERY similar to the first test but
 // because the assert is different we need to write a different
 // test.  Each test should only really assert the name of the test
 // as it makes it easier to debug and fix it when it only tests
 // one thing.
 public void TryDeleteAllFiles2_WithEmptyPath_CallsFileManagerGetFiles()
 {
   /// ** ASSIGN **
   var fileManager = Substitute.For<IFileManager>();
   fileManager
     .GetFiles(Args.Any<string>())
     .Returns(new List<IFile>());
   var mySpaceManager = new MySpaceManager(fileManager);
   // ** ACT **
   mySpaceManager.TryDeleteAllFiles2(string.Empty)
   // ** ASSERT **
   Assert.DoesNotThrow(fileManager.Received().GetFiles());
 }
Beispiel #10
0
        public static async Task <Result <T> > Create <T>(T APIObject, bool DryRun, params string[] Args)
        {
            string Url = ServiceURI + "/" + typeof(T).GetApiEndPoint().Create;

            if (Args.Any())
            {
                Url = string.Format(Url, Args);
            }

            Ext.GetLogger <CFHostOperator>().LogInformation((DryRun ? "Create(DryRun): " : "Create: ") + APIObject.ToString());

            if (DryRun)
            {
                return new Result <T>()
                       {
                           Item = APIObject
                       }
            }
            ;

            WebRequest Request = WebRequest.Create(Url);

            Request.Headers.Add(HttpRequestHeader.Authorization, $"Bearer {APIToken}");
            Request.Headers.Add(HttpRequestHeader.Accept, "application/json");
            Request.Method      = WebRequestMethods.Http.Post;
            Request.ContentType = "application/json";

            JsonConverter Converter = typeof(T).GetApiPostConverter()?.Create;

            using var ReqStream = Request.GetRequestStream();
            if (Converter != null)
            {
                JsonSerializerOptions Options = new JsonSerializerOptions();

                Options.Converters.Add(Converter);
                string A = JsonSerializer.Serialize(APIObject, Options);
                await JsonSerializer.SerializeAsync(ReqStream, APIObject, Options);
            }
            else
            {
                await JsonSerializer.SerializeAsync(ReqStream, APIObject);
            }

            WebResponse Response = await Request.GetResponseAsync();

            using var RespStream = Response.GetResponseStream();
            return(await JsonSerializer.DeserializeAsync <Result <T> >(RespStream));
        }
Beispiel #11
0
        public static async Task <ListResult <T> > List <T>(params string[] Args)
        {
            string Url = ServiceURI + "/" + typeof(T).GetApiEndPoint().List;

            if (Args.Any())
            {
                Url = string.Format(Url, Args);
            }

            WebRequest Request = WebRequest.Create(Url);

            Request.Headers.Add(HttpRequestHeader.Authorization, $"Bearer {APIToken}");
            using var Response = await Request.GetResponseAsync();

            return(await JsonSerializer.DeserializeAsync <ListResult <T> >(Response.GetResponseStream()));
        }
Beispiel #12
0
        private ICommand GetTargetCommand()
        {
            var globalProperties = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase)
            {
                // This property disables default item globbing to improve performance
                // This should be safe because we are not evaluating items, only properties
                { Constants.EnableDefaultItems, "false" },
                { Constants.MSBuildExtensionsPath, AppContext.BaseDirectory }
            };

            if (!string.IsNullOrWhiteSpace(Configuration))
            {
                globalProperties.Add("Configuration", Configuration);
            }

            if (!string.IsNullOrWhiteSpace(Framework))
            {
                globalProperties.Add("TargetFramework", Framework);
            }

            if (!string.IsNullOrWhiteSpace(Runtime))
            {
                globalProperties.Add("RuntimeIdentifier", Runtime);
            }

            var project = new ProjectInstance(Project, globalProperties, null);

            string runProgram = project.GetPropertyValue("RunCommand");

            if (string.IsNullOrEmpty(runProgram))
            {
                ThrowUnableToRunError(project);
            }

            string runArguments        = project.GetPropertyValue("RunArguments");
            string runWorkingDirectory = project.GetPropertyValue("RunWorkingDirectory");

            if (Args.Any())
            {
                runArguments += " " + ArgumentEscaper.EscapeAndConcatenateArgArrayForProcessStart(Args);
            }

            CommandSpec commandSpec = new CommandSpec(runProgram, runArguments, CommandResolutionStrategy.None);

            return(Command.Create(commandSpec)
                   .WorkingDirectory(runWorkingDirectory));
        }
 // First simple, best good path for code
 public void TryDeleteAllFiles2_WithEmptyPath_ThrowsNoException()
 {
   /// ** ASSIGN **
   // I'm using NSubstitute here just for an example
   // could use Moq or RhinoMocks, whatever doesn't  
   // really matter in this instance
   // the important part is that we do NOT test dependencies
   // the class relies on.
   var fileManager = Substitute.For<IFileManager>();
   fileManager
     .GetFiles(Args.Any<string>())
     .Returns(new List<IFile>());
   var mySpaceManager = new MySpaceManager(fileManager);
   // ** ACT && ASSERT**
   // we know that the argument doesn't matter so we don't need it to be
   // anything at all, we just want to make sure that it runs to completion
   Asser.DoesNotThrow(() => mySpaceManager.TryDeleteAllFiles2(string.Empty);
 }
 public async Task CanPostPerson()
 {
     await RouteAssert.ForAsync(
         _server,
         request => request
         .WithPathAndQuery("/post-with-person")
         .WithMethod(HttpMethod.Post)
         .WithFormData(new Dictionary <string, string>
     {
         { "FirstName", "Niklas" },
         { "LastName", "Wendel" }
     }),
         routeAssert => routeAssert
         .MapsTo <PostController>(a => a.WithPerson(Args.Any <Person>()))
         .ForParameter <Person>("person", p =>
     {
         Assert.Equal("Niklas", p.FirstName);
         Assert.Equal("Wendel", p.LastName);
     }));
 }
 public async Task CanPostJsonPerson()
 {
     await RouteAssert.ForAsync(
         _server,
         request => request
         .WithPathAndQuery("/post-with-json-person")
         .WithMethod(HttpMethod.Post)
         .WithJsonData(new Person
     {
         FirstName = "Niklas",
         LastName  = "Wendel"
     }),
         routeAssert => routeAssert
         .MapsTo <PostController>(a => a.WithJsonPerson(Args.Any <Person>()))
         .ForParameter <Person>("person", p =>
     {
         Assert.Equal("Niklas", p.FirstName);
         Assert.Equal("Wendel", p.LastName);
     }));
 }
 public async Task CanRouteWithParameterMatchingAny()
 {
     await RouteAssert.ForAsync(
         _server,
         request => request.WithPathAndQuery("/parameter/query-string-parameter?parameter=value"),
         routeAssert => routeAssert.MapsTo <ParameterController>(a => a.QueryStringParameter(Args.Any <string>())));
 }
 public async Task ThrowsOnRouteWithParameterForParameterWrongParameterName()
 {
     await Assert.ThrowsAsync <ArgumentException>("parameterName", () =>
                                                  RouteAssert.ForAsync(
                                                      _server,
                                                      request => request.WithPathAndQuery("/parameter/query-string-parameter?parameter=wrong-value"),
                                                      routeAssert => routeAssert
                                                      .MapsTo <ParameterController>(a => a.QueryStringParameter(Args.Any <string>()))
                                                      .ForParameter <string>("wrong-parameter", p =>
     {
         Assert.Equal("value", p);
     })));
 }
Beispiel #18
0
 protected virtual bool HasArgsKey(string key)
 {
     return(Args.Any(s => !string.IsNullOrEmpty(s) &&
                     s.ToLower() == "--" + key || s.ToLower() == key));
 }
Beispiel #19
0
        public bool HasArgument(string ArgName)
        {
            string LongName = "-" + ArgName;

            return(Args.Any(arg => arg == LongName));
        }