Ejemplo n.º 1
0
        public IActionResult Post([FromBody] MockRequest request)
        {
            var clientVersion = Request.Headers["user-agent"].ToString();
            var serverVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();

            if (clientVersion != serverVersion)
            {
                return(BadRequest(new IncompalibleVersionsException(serverVersion, clientVersion)));
            }
            var mockResource = new MockResource(ResourceStream(), request);

            RequestToConsole(request);
            using (var stream = mockResource.ToStream())
            {
                if (stream == null)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.Write(string.Format("File is not found: {0}\n\n", mockResource.RequestedResourcePath));
                    return(NotFound(mockResource.RequestedResourcePath));
                }

                Console.ForegroundColor = ConsoleColor.Green;
                Console.Write(string.Format("File: {0}\n\n", mockResource.RequestedResourcePath));

                using (var reader = new StreamReader(stream))
                {
                    var result = reader.ReadToEnd();
                    Console.WriteLine($"Post return {result}");
                    reader.Close();
                    stream.Close();
                    return(Ok(result));
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Return EmbededdedResourceStream for mock mockRequest.
        /// </summary>
        /// <param name="mockRequest">Mock request.</param>
        /// <returns>Task Stream with wanted mock data.</returns>
        protected override async Task <Stream> DataStream(MockRequest mockRequest)
        {
            var mockResource = new MockResource(ResourceStream(), mockRequest);
            var stream       = mockResource.ToStream();

            if (stream == null)
            {
                return(null);
            }

            return(await Task.FromResult(stream));
        }