Esempio n. 1
0
        public async Task LoginWithNonJsonBody(string credentials)
        {
            // SETUP
            var credentialObject = new JObject();
            ByteArrayContent content;

            try
            {
                credentialObject = JObject.Parse(credentials);
                content          = HttpBody.GetBodyFromJSON(credentialObject);
            }
            catch (Newtonsoft.Json.JsonReaderException e)
            {
                content = HttpBody.GetBodyFromString("");
            }

            // ACT
            var response = await _testFixture.Client.PostAsync(LOGIN_ROUTE, content);

            // ASSERT
            response.StatusCode.Should().Be(HttpStatusCode.BadRequest);

            var jsonString = await response.Content.ReadAsStringAsync();

            var jsonObject = JObject.Parse(jsonString);

            jsonObject.Should().HaveElement("");
        }
Esempio n. 2
0
        async public Task <AccessModel> Login(LoginModel model)
        {
            try
            {
                if (model == null)
                {
                    throw new ArgumentNullException(nameof(model));
                }

                var body     = new HttpBody <LoginModel>();
                var response = await RestService.Post <AccessModel, LoginModel>("Login", body);

                var result = response.Content;

                Context.Credentials = result;

                return(result);
            }
            catch (HttpException ex)
            {
                if (ex.StatusCode == HttpStatusCode.NotFound)
                {
                    return(null);
                }

                ex.CheckRule();
                throw;
            }
        }
Esempio n. 3
0
        public async Task LoginWithIncompleteCredentials(string credentials)
        {
            // SETUP
            JObject          credentialObject = JObject.Parse(credentials);
            ByteArrayContent content          = HttpBody.GetBodyFromJSON(credentialObject);

            // ACT
            var response = await _testFixture.Client.PostAsync(LOGIN_ROUTE, content);

            // ASSERT
            response.StatusCode.Should().Be(HttpStatusCode.BadRequest);

            var jsonString = await response.Content.ReadAsStringAsync();

            var jsonObject = JObject.Parse(jsonString);

            if (!credentialObject.ContainsKey("username"))
            {
                jsonObject.Should().HaveElement("Username");
            }

            if (!credentialObject.ContainsKey("password"))
            {
                jsonObject.Should().HaveElement("Password");
            }
        }
Esempio n. 4
0
        unsafe internal static Byte[] marshall(HttpResp response, Object val,
                                               MediaType produces)
        {
            if (response.StatusCode == 0)
            {
                //which indicates that the user did not set this
                response.StatusCode = 200;
            }

            //return values can be Object, any built in Type, a file or nothing.
            //Process depending on return format specified by the user

            response.StatusDesc  = StatusCodeDesc.GetStatusDesc(response.StatusCode);
            response.ContentType = response.ContentType.Equals("") == true ?
                                   produces : response.ContentType;

            //package the body correctly
            Byte[] BodyContent = GetByte(val, produces);
            response.ContentLength = (UInt64)BodyContent.Length;

            HttpBody Body = response.Body;

            Body.SetLengthOfBody(BodyContent.Length);
            Body.SetBodyContent(BodyContent);
            return(response.Bytes());
        }
Esempio n. 5
0
        public void ThenSetValue_Perform_SetHttpBodyTest()
        {
            string textValue = "value";

            Mock <EventInfo>      mockEventInfo   = new Mock <EventInfo>();
            Mock <HttpMessage>    mockHttpMessage = new Mock <HttpMessage>();
            Mock <HttpBody>       mockHttpBody    = new Mock <HttpBody>();
            Mock <VariableString> mockTextString  = new Mock <VariableString>(It.IsAny <string>(), null);

            EventInfo      eventInfo   = mockEventInfo.Object;
            HttpMessage    httpMessage = mockHttpMessage.Object;
            HttpBody       httpBody    = mockHttpBody.Object;
            VariableString textString  = mockTextString.Object;

            mockTextString.Setup(mock => mock.GetText(It.IsAny <Variables>())).Returns(textValue);
            mockEventInfo.Setup(mock => mock.Message).Returns(httpMessage);
            mockHttpMessage.SetupSet(mock => mock.Body = It.IsAny <HttpBody>()).Callback((HttpBody body) =>
            {
                Assert.AreEqual(textValue, body.Text);
            });

            ThenSetValue then = new ThenSetValue()
            {
                Text = textString,
                DestinationMessageValue = MessageValue.HttpBody
            };

            Assert.AreEqual(ThenResponse.Continue, then.Perform(eventInfo));

            mockHttpMessage.VerifySet(mock => mock.Body = It.IsAny <HttpBody>(), Times.Once);
        }
Esempio n. 6
0
 protected override void OnMessageReceive(PacketRecieveMessagerArgs e)
 {
     base.OnMessageReceive(e);
     if (e.Message is HttpExtend.HttpHeader)
     {
         HttpExtend.HttpHeader header = e.Message as HttpExtend.HttpHeader;
         if (header.Connection != null)
         {
             e.Channel["keep-alive"] = true;
         }
         header                  = new HttpHeader();
         header.Action           = "HTTP/1.1 200 OK";
         header["Cache-Control"] = "private";
         header.ContentType      = "text/html; charset=utf-8";
         header.Server           = "Beetle/HttpExtend";
         header.Connection       = "keep-alive";
         // FileReader reader = new FileReader("h:\\KendeSoft.htm");
         // header.Length = reader.FileInfo.Length;
         HttpBody body = HttpPacket.InstanceBodyData();
         body.Data.Encoding("<p>beetle http extend server!</p><p>Beetle是基于c#编写的高性能稳定的TCP通讯组件,它可以轻易支持成千上万长连接基础上进行密集的通讯交互. 组件提供了出色的性能支持和可靠的稳定性足以保证应用7x24无间断运行。为了更好地利用.Net的网络IO来处理数据,组件提供智能合并消息机制,组件调度器会根据当前负载情况对发向客户的多个消息进行合并处处理,从而减少IO操作达到更高的处理效能;通过测试在大量用户信息广播的情况轻易可以处理上百万的消息转发</p>", Encoding.UTF8);
         body.Eof      = true;
         header.Length = body.Data.Count;
         e.Channel.Send(header);
         e.Channel.Send(body);
         //while (reader.Read())
         //{
         //    HttpBody body = HttpPacket.InstanceBodyData();
         //    reader.ReadTo(body);
         //    e.Channel.Send(body);
         //}
     }
 }
Esempio n. 7
0
        public async Task <bool> Register(RegistrationModel model)
        {
            var settings = new HttpSettings($"{this._url}/registration", null, null, "Registration");

            var body = new HttpBody <RegistrationModel>(model);

            return(await this._httpService.Create <RegistrationModel>(settings, body));
        }
Esempio n. 8
0
        public void Can_serialize_dynamic_instance()
        {
            var dog  = new { Name = "Spot" };
            var json = HttpBody.Serialize(dog);

            Assert.IsNotNull(json);
            Console.WriteLine(json);
        }
Esempio n. 9
0
        public HttpApiResponse(HttpStatusCode statusCode = HttpStatusCode.OK, HttpBody body = null, IEnumerable<HttpHeader> headers = null)
        {
            var headersList = headers?.ToList() ?? new List<HttpHeader>();

            StatusCode = statusCode;
            Headers = headersList;
            Body = body;
        }
Esempio n. 10
0
        public Task <GeneratorSettings> GenerateSimple(GeneratorSettings settings)
        {
            var httpSettings = new HttpSettings($"{this._url}/generate", null, null, "Csomor generating");

            var body = new HttpBody <GeneratorSettings>(settings);

            return(this._http.UpdateWithResult <GeneratorSettings, GeneratorSettings>(httpSettings, body));
        }
Esempio n. 11
0
        public async Task <bool> UpdateReadStatuses(List <BookReadStatusModel> models)
        {
            var settings = new HttpSettings($"{this.Url}/map/status", null, null, "My Book read status updating");

            var body = new HttpBody <List <BookReadStatusModel> >(models);

            return(await this.Http.Update <List <BookReadStatusModel> >(settings, body));
        }
Esempio n. 12
0
        public async Task <bool> UpdateMyMovies(MyMovieModel model)
        {
            var settings = new HttpSettings($"{this.Url}/map", null, null, "My Movies updating");

            var body = new HttpBody <MyMovieModel>(model);

            return(await this.Http.Update <MyMovieModel>(settings, body));
        }
Esempio n. 13
0
        public async Task <bool> DisableUser()
        {
            var settings = new HttpSettings($"{this._url}/disable", null, null, "User disabling");

            var body = new HttpBody <object>(null);

            return(await this._httpService.Update <object>(settings, body));
        }
Esempio n. 14
0
        public async Task <bool> SendMessage(MessageModel model)
        {
            var settings = new HttpSettings($"{this.Url}/send", null, null, "Message sending");

            var body = new HttpBody <MessageModel>(model);

            return(await this.Http.Create <MessageModel>(settings, body));
        }
        public async Task <bool> SetUnReadsToRead(int[] ids)
        {
            var settings = new HttpSettings($"{this._url}", null, null, "Notification refreshing");

            var body = new HttpBody <int[]>(ids);

            return(await this._httpService.Update <int[]>(settings, body));
        }
Esempio n. 16
0
        public async Task <bool> UpdatePassword(PasswordUpdateModel model)
        {
            var settings = new HttpSettings($"{this._url}/password", null, null, "Password updating");

            var body = new HttpBody <PasswordUpdateModel>(model);

            return(await this._httpService.Update <PasswordUpdateModel>(settings, body));
        }
Esempio n. 17
0
        public async Task <bool> UpdateSeenStatus(List <EpisodeSeenStatusModel> models)
        {
            var settings = new HttpSettings($"{this.Url}/map/status", null, null, "My Episode seen status updating");

            var body = new HttpBody <List <EpisodeSeenStatusModel> >(models);

            return(await this.Http.Update <List <EpisodeSeenStatusModel> >(settings, body));
        }
Esempio n. 18
0
        public async Task <bool> UpdateUser(UserModel userUpdate)
        {
            var settings = new HttpSettings($"{this._url}", null, null, "User updating");

            var body = new HttpBody <UserModel>(userUpdate);

            return(await this._httpService.Update <UserModel>(settings, body));
        }
Esempio n. 19
0
        public async Task <bool> UpdateProfileImage(byte[] image)
        {
            var settings = new HttpSettings($"{this._url}/profile-image", null, null, "Image updating");

            var body = new HttpBody <byte[]>(image);

            return(await this._httpService.Update <byte[]>(settings, body));
        }
Esempio n. 20
0
        public async Task <bool> UpdateUsername(UsernameUpdateModel model)
        {
            var settings = new HttpSettings($"{this._url}/username", null, null, "User Name updating");

            var body = new HttpBody <UsernameUpdateModel>(model);

            return(await this._httpService.Update <UsernameUpdateModel>(settings, body));
        }
Esempio n. 21
0
        public Task <int> Create(GeneratorSettingsModel model)
        {
            var settings = new HttpSettings($"{this._url}", null, null, "Generator setting creating");

            var body = new HttpBody <GeneratorSettingsModel>(model);

            return(this._http.CreateInt <GeneratorSettingsModel>(settings, body));
        }
Esempio n. 22
0
        public async Task <bool> UpdateSeenStatus(SeriesSeenStatusModel model)
        {
            var settings = new HttpSettings($"{this.Url}/map/status", null, null, "My Series seen status updating");

            var body = new HttpBody <SeriesSeenStatusModel>(model);

            return(await this.Http.Update <SeriesSeenStatusModel>(settings, body));
        }
Esempio n. 23
0
        public void Can_deserialize_dynamic_instance()
        {
            var dog          = new { Name = "Spot" };
            var json         = HttpBody.Serialize(dog);
            var deserialized = HttpBody.Deserialize(json);

            Assert.IsNotNull(deserialized);
            Assert.AreEqual(dog.Name, deserialized.Name);
        }
Esempio n. 24
0
        public void Can_deserialize_dynamic_instance_into_concrete_instance()
        {
            var dog          = new { Name = "Spot" };
            var json         = HttpBody.Serialize(dog);
            var deserialized = HttpBody.Deserialize(json);
            Dog concrete     = HttpBody.Deserialize <Dog>(deserialized);

            Assert.IsNotNull(concrete);
            Assert.AreEqual("Spot", concrete.Name);
        }
Esempio n. 25
0
        public async Task <bool> SendFriendRequestResponse(FriendRequestResponseModel model)
        {
            var toaster = new ToasterSettings("Friend request answering");

            var settings = new HttpSettings($"{this._url}/request", null, null, toaster);

            var body = new HttpBody <FriendRequestResponseModel>(model);

            return(await this._httpService.Update <FriendRequestResponseModel>(settings, body));
        }
Esempio n. 26
0
        public async Task <bool> AddMovieToMyMovies(int id)
        {
            var pathParams = new HttpPathParameters();

            pathParams.Add <int>(id, -1);
            var settings = new HttpSettings($"{this.Url}/map", null, pathParams, "Adding movie to My Movies");

            var body = new HttpBody <object>(null);

            return(await this.Http.Create <object>(settings, body));
        }
Esempio n. 27
0
        public async Task LoginWithBadCredentials(string credentials)
        {
            // SETUP
            ByteArrayContent content = HttpBody.GetBodyFromJSONString(credentials);

            // ACT
            var response = await _testFixture.Client.PostAsync(LOGIN_ROUTE, content);

            // ASSERT
            response.StatusCode.Should().Be(HttpStatusCode.Unauthorized);
        }
Esempio n. 28
0
        public async Task <bool> AddIncremented(int seasonId)
        {
            var pathParams = new HttpPathParameters();

            pathParams.Add <int>(seasonId, -1);

            var settings = new HttpSettings($"{this.Url}", null, pathParams, "Episode adding");

            var body = new HttpBody <object>(null);

            return(await this.Http.Create <object>(settings, body));
        }
Esempio n. 29
0
        public async Task <bool> UpdateRate(int id, MovieRateModel model)
        {
            var pathParams = new HttpPathParameters();

            pathParams.Add <int>(id, -1);

            var settings = new HttpSettings($"{this.Url}/rate", null, pathParams, "Movie rating");

            var body = new HttpBody <MovieRateModel>(model);

            return(await this.Http.Update <MovieRateModel>(settings, body));
        }
Esempio n. 30
0
        /// <summary>
        /// Set current Period
        /// </summary>
        /// <param name="id">New Period</param>
        /// <returns>Async result</returns>
        public async Task <bool> SetCurrent(int id)
        {
            var pathParams = new HttpPathParameters();

            pathParams.Add("current", -1);

            var settings = new HttpSettings(Url + "/" + this.Entity, null, pathParams, "Set current period");

            var body = new HttpBody <int>(id);

            return(await HttpService.Update(settings, body));
        }
Esempio n. 31
0
        public async Task <bool> UpdateImage(int id, EpisodeImageModel model)
        {
            var pathParams = new HttpPathParameters();

            pathParams.Add <int>(id, -1);

            var settings = new HttpSettings($"{this.Url}/image", null, pathParams, "Episode image updating");

            var body = new HttpBody <EpisodeImageModel>(model);

            return(await this.Http.Update <EpisodeImageModel>(settings, body));
        }