Esempio n. 1
0
        public void ToString_WithPathAndParameters_ReturnsRequest()
        {
            var api        = "testApi";
            var resource   = "test/csproj.csproj";
            var parameter1 = new RequestParameter("key1", "value1");
            var parameter2 = new RequestParameter("key2", "value2");
            var testee     = new RequestUrl(api, resource, new[] { parameter1, parameter2 });

            var result = testee.ToString();

            Assert.AreEqual("http://testApi/test/csproj.csproj?key1=value1&key2=value2", result);
        }
Esempio n. 2
0
        public void ProcessRequest_FileSystemThrowsException_ReturnsFolderJson()
        {
            var setup      = new TestSetup();
            var requestUrl = new RequestUrl("FileApi", "files.json", new RequestParameter[] { new RequestParameter("Directory", @"C:\temp") });

            setup.FileSystem
            .Setup(x => x.GetFiles(It.IsAny <string>()))
            .Throws(new System.IO.IOException("Could not load folder"));
            var testee = setup.CreateTestee();

            var result = Encoding.UTF8.GetString(
                testee.ProcessRequest(RequestUrl.FromString(requestUrl.ToString())));

            Assert.AreEqual("{\"files\":null,\"errorMessage\":\"Could not load folder\"}", result);
        }
Esempio n. 3
0
        public void ProcessRequest_FileSystemReturnsFiles_ReturnsFolderJson()
        {
            var setup      = new TestSetup();
            var requestUrl = new RequestUrl("FileApi", "files.json", new RequestParameter[] { new RequestParameter("Directory", @"C:\temp") });

            setup.FileSystem
            .Setup(x => x.GetFiles(It.Is <string>(y => y == @"C:\temp")))
            .Returns(new[] { new File {
                                 Kind = FileKind.File, Path = "TestFile"
                             } });
            var testee = setup.CreateTestee();

            var result = Encoding.UTF8.GetString(
                testee.ProcessRequest(RequestUrl.FromString(requestUrl.ToString())));

            Assert.AreEqual("{\"files\":[{\"kind\":0,\"path\":\"TestFile\"}],\"errorMessage\":null}", result);
        }
Esempio n. 4
0
        /// <summary>
        /// Gets response in json/xml/vdf format.
        /// </summary>
        /// <param name="format"></param>
        /// <returns></returns>
        public virtual string GetRawResponse(Format format)
        {
            if (Socket == null)
            {
                Socket = new SteamSocket();
            }
            string response = string.Empty;

            if (format == ReceivedFormat)
            {
                response = ReceivedResponse;
            }
            else
            {
                RequestUrl.Format = format;
                response          = Socket.GetResponse(RequestUrl.ToString());
            }
            return(response);
        }