public async void validJsonContent()
        {
            // Arrange
            MockHttpMessageHandler mockHttp = MockTools.GetNewMockHandler();

            mockHttp.When(HttpMethod.Get, "*/test").Respond(HttpStatusCode.OK, "application/json", "{\"Value\":\"Test\"}");

            HttpClient httpClient = mockHttp.ToHttpClient();

            // Act
            HttpResponseMessage httpResponse = await httpClient.GetAsync("http://test.com/test");

            // Assert
            Assert.NotNull(await JsonWrapper.Deserialize <Hostname>(httpResponse));
        }
Beispiel #2
0
        // Helper method
        private void ReadRoleDataStore()
        {
            lock (_lockObj)
            {
                _usersAndRoles = new Dictionary <string, string[]>(16, StringComparer.InvariantCultureIgnoreCase);
                _rolesAndUsers = new Dictionary <string, string[]>(16, StringComparer.InvariantCultureIgnoreCase);

                var users = JsonWrapper.Deserialize <List <User> >(File.OpenRead(_jsonFileName));

                foreach (var user in users)
                {
                    if (string.IsNullOrEmpty(user.UserName))
                    {
                        throw new ProviderException("Empty UserName element");
                    }

                    if (user.Roles == null || user.Roles.Length == 0)
                    {
                        _usersAndRoles.Add(user.UserName, new string[0]);
                    }
                    else
                    {
                        _usersAndRoles.Add(user.UserName, user.Roles);
                        foreach (var role in user.Roles)
                        {
                            // Add the user name to _RolesAndUsers and
                            // key it by role names
                            string[] users1;
                            if (_rolesAndUsers.TryGetValue(role, out users1))
                            {
                                string[] users2 = new string[users1.Length + 1];
                                users1.CopyTo(users2, 0);
                                users2[users1.Length] = user.UserName;
                                _rolesAndUsers.Remove(role);
                                _rolesAndUsers.Add(role, users2);
                            }
                            else
                            {
                                _rolesAndUsers.Add(role, new[] { user.UserName });
                            }
                        }
                    }
                }
            }
        }
        // Helper method
        private void ReadMembershipDataStore()
        {
            lock (_lockObj)
            {
                try
                {
                    _users = new Dictionary <string, MembershipUser>(16, StringComparer.InvariantCultureIgnoreCase);

                    var users = JsonWrapper.Deserialize <IList <User> >(File.OpenRead(_jsonFileName));

                    foreach (var user in users)
                    {
                        var membershipUser = new MembershipUser(
                            Name,                      // Provider name
                            user.UserName,             // Username
                            null,                      // providerUserKey
                            string.Empty,              // Email
                            string.Empty,              // passwordQuestion
                            user.Password,             // Comment
                            true,                      // isApproved
                            false,                     // isLockedOut
                            DateTime.Now,              // creationDate
                            DateTime.Now,              // lastLoginDate
                            DateTime.Now,              // lastActivityDate
                            DateTime.Now,              // lastPasswordChangedDate
                            new DateTime(1980, 1, 1)   // lastLockoutDate
                            );
                        _users.Add(user.UserName, membershipUser);
                    }
                }
                catch (Exception e)
                {
                    _logger.Error(e, e.Message);
                    throw;
                }
            }
        }
        public async void BadFormattedJsonContent(string jsonString)
        {
            // Arrange
            MockHttpMessageHandler mockHttp = MockTools.GetNewMockHandler();

            mockHttp.When(HttpMethod.Get, "*/test").Respond(HttpStatusCode.OK, "application/failed", jsonString);

            HttpClient httpClient = mockHttp.ToHttpClient();

            // Act
            HttpResponseMessage httpResponse = await httpClient.GetAsync("http://test.com/test");

            // Assert
            BunnyInvalidResponseException exception = await Assert.ThrowsAsync <BunnyInvalidResponseException>(async() => { await JsonWrapper.Deserialize <object>(httpResponse); });
        }
Beispiel #5
0
            /// @param data
            ///     The json data
            ///
            public static void DeserializeString(this ISerializable serializable, string data)
            {
                var jsonData = JsonWrapper.Deserialize(data);

                serializable.Deserialize(jsonData);
            }