public void when_deserializing()
        {
            // Given
            JsonConvert.DefaultSettings = JsonNetSerializerFixture.GetJsonSerializerSettings;

            var    guid   = Guid.NewGuid();
            string source = string.Format("{{\"someString\":\"some string value\",\"someGuid\":\"{0}\"}}", guid);

            var context = new BindingContext
            {
                DestinationType          = typeof(TestData),
                ValidModelBindingMembers = typeof(TestData).GetProperties(BindingFlags.Public | BindingFlags.Instance).Select(p => new BindingMemberInfo(p)),
            };

            // When
            object actual;

            using (var bodyStream = new MemoryStream(Encoding.UTF8.GetBytes(source)))
            {
                IBodyDeserializer sut = new JsonNetBodyDeserializer();
                actual = sut.Deserialize("application/json", bodyStream, context);
            }

            // Then
            var actualData = Assert.IsType <TestData>(actual);

            Assert.Equal("some string value", actualData.SomeString);
            Assert.Equal(guid, actualData.SomeGuid);
        }
        public void when_deserializing()
        {
            // Given
            JsonConvert.DefaultSettings = JsonNetSerializerFixture.GetJsonSerializerSettings;

            var guid = Guid.NewGuid();
            string source = string.Format("{{\"someString\":\"some string value\",\"someGuid\":\"{0}\"}}", guid);

            var context = new BindingContext
            {
                DestinationType = typeof (TestData),
                ValidModelBindingMembers = typeof (TestData).GetProperties(BindingFlags.Public | BindingFlags.Instance).Select(p => new BindingMemberInfo(p)),
            };

            // When
            object actual;
            using (var bodyStream = new MemoryStream(Encoding.UTF8.GetBytes(source)))
            {
                IBodyDeserializer sut = new JsonNetBodyDeserializer();
                actual = sut.Deserialize("application/json", bodyStream, context);
            }

            // Then
            var actualData = Assert.IsType<TestData>(actual);
            Assert.Equal("some string value", actualData.SomeString);
            Assert.Equal(guid, actualData.SomeGuid);
        }
Example #3
0
        protected FeatureTestBase()
        {
            Bundler.Enable(false);
            BundleTable.Bundles.Clear();

            _configuration = new Dictionary<string, object>();
            Configure(_configuration);

            Config.GetValueFunc = key =>
            {
                object value = null;
                if (!_configuration.TryGetValue(key, out value))
                {
                    throw new InvalidOperationException(
                        string.Format("Test is missing configuration value for key {0}", key));
                }

                return value;
            };

            FormsConfig = new FormsAuthenticationConfiguration
            {
                RedirectUrl = "~/admin/login",
                UserMapper = new FormsAuthenticationUserMapper(Store.OpenSession)
            };

            Serializer = new JsonNetSerializer();
            Deserializer = new JsonNetBodyDeserializer();

            _browser = CreateBrowser();
            Admin = Install("admin");
        }