示例#1
0
        public void PropertyContract_ShouldReturnUnchangedIfZeroProperties()
        {
            var idPropInfo = new PropertyValueInfo(typeof(MemberContractTestsClass).GetProperty(nameof(MemberContractTestsClass.Id)));
            var obj        = new MemberContractTestsClass()
            {
                Id = 2001
            };
            var contract = new MemberContract("self", "http://baba.com/props/sven/{ds}", new KeyValuePair <string, IValueInfo> [0]);

            var token = contract.GetToken(obj);

            Assert.NotNull(token);
            Assert.True(token.Type.Equals(JTokenType.Property));
            Assert.Equal("\"self\": \"http://baba.com/props/sven/{ds}\"", token.ToString());
        }
示例#2
0
        public void PropertyContract_ShouldParseProperty()
        {
            var obj = new MemberContractTestsClass()
            {
                Id = 2001
            };
            var contract = new MemberContract("self", "http://baba.com/props/{prp}", new []
            {
                new KeyValuePair <string, IValueInfo>("prp", new PropertyValueInfo(typeof(MemberContractTestsClass).GetProperty(nameof(MemberContractTestsClass.Id)))),
            });

            var token = contract.GetToken(obj);

            Assert.NotNull(token);
            Assert.True(token.Type.Equals(JTokenType.Property));
            Assert.Equal("\"self\": \"http://baba.com/props/2001\"", token.ToString());
        }
示例#3
0
        public void PropertyContract_ShouldParseProperties()
        {
            var obj = new MemberContractTestsClass()
            {
                Id = 2001, Baba = "obob", Bolle = true
            };
            var contract = new MemberContract("self", "http://baba.com/props/{prp}/granlund/{baba}/gg/{olof}/", new[]
            {
                new KeyValuePair <string, IValueInfo>("prp", new PropertyValueInfo(typeof(MemberContractTestsClass).GetProperty(nameof(MemberContractTestsClass.Id)))),
                new KeyValuePair <string, IValueInfo>("olof", new PropertyValueInfo(typeof(MemberContractTestsClass).GetProperty(nameof(MemberContractTestsClass.Bolle)))),
                new KeyValuePair <string, IValueInfo>("baba", new PropertyValueInfo(typeof(MemberContractTestsClass).GetProperty(nameof(MemberContractTestsClass.Baba))))
            });

            var token = contract.GetToken(obj);

            Assert.NotNull(token);
            Assert.True(token.Type.Equals(JTokenType.Property));
            Assert.Equal("\"self\": \"http://baba.com/props/2001/granlund/obob/gg/True/\"", token.ToString());
        }