コード例 #1
0
        public static FixtureResponse Get(FixtureType type, string name)
        {
            if (name.IsNullOrEmpty())
                throw new ArgumentNullException("name");

            if(!Enum.IsDefined(typeof(FixtureType), type))
                throw new InvalidEnumArgumentException("type", (int)type, typeof(FixtureType));

            var fixturePath = string.Format("fixtures/{0}/{1}.xml", type, name);

            if (!File.Exists(fixturePath))
                throw new FileNotFoundException("Could not locate the fixture response file!", fixturePath);

            var contents = new List<string>();
            using (var reader = new StreamReader(File.OpenRead(fixturePath)))
            {
                string line;
                while ((line = reader.ReadLine()) != null)
                    contents.Add(line);
            }

            var response = new FixtureResponse();
            var count = 0;
            for (; count < contents.Count; ++count)
            {
                var line = contents[count];
                if (line.IsNullOrWhiteSpace()) continue;

                if (line.StartsWith("HTTP"))
                    response.StatusCode = ParseStatusCode(line);
                else if (line.StartsWith("<"))
                    break;
                else
                    response.AddHeader(ParseHeader(line));
            }

            var remainder = contents.Count - count;
            response.Xml = string.Join(Environment.NewLine, contents.ToArray(), count, remainder);

            return response;
        }
コード例 #2
0
        public static FixtureResponse Get(FixtureType type, string name)
        {
            if (name.IsNullOrEmpty())
            {
                throw new ArgumentNullException("name");
            }

            if (!Enum.IsDefined(typeof(FixtureType), type))
            {
                throw new InvalidEnumArgumentException("type", (int)type, typeof(FixtureType));
            }

            var fixturePath = string.Format("fixtures/{0}/{1}.xml", type, name);

            if (!File.Exists(fixturePath))
            {
                throw new FileNotFoundException("Could not locate the fixture response file!", fixturePath);
            }

            var contents = new List <string>();

            using (var reader = new StreamReader(File.OpenRead(fixturePath)))
            {
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    contents.Add(line);
                }
            }

            var response = new FixtureResponse();
            var count    = 0;

            for (; count < contents.Count; ++count)
            {
                var line = contents[count];
                if (line.IsNullOrWhiteSpace())
                {
                    continue;
                }

                if (line.StartsWith("HTTP"))
                {
                    response.StatusCode = ParseStatusCode(line);
                }
                else if (line.StartsWith("<"))
                {
                    break;
                }
                else
                {
                    response.AddHeader(ParseHeader(line));
                }
            }

            var remainder = contents.Count - count;

            response.Xml = string.Join(Environment.NewLine, contents.ToArray(), count, remainder);

            return(response);
        }