Пример #1
0
        public void ShouldSerializePropertyRenamedWithAttributeTest()
        {
            // Arrange
            var obj = new Smile {
                Id = 2, SmileType = "Big grin"
            };

            // Act & Assert
            Assert.IsTrue(ExcludeEmptyEnumerablesContractResolver.Instance.ShouldSerialize(obj, new JsonProperty {
                PropertyName = "Type", UnderlyingName = "SmileType"
            }));
        }
Пример #2
0
        public void GetRelatedEntity_NotGeneric_Test()
        {
            // Arrange
            var odataUser = new OdataObject <User, int>();
            var re1       = new RelatedEntity {
                Id = "7"
            };
            var smile1 = new Smile {
                Id = 7, SmileType = "Wide"
            };
            var json1 = JsonConvert.SerializeObject(smile1);

            re1.Object = new JRaw(json1);

            var re2 = new RelatedEntity {
                Id = "8"
            };
            var smile2 = new Smile {
                Id = 8, SmileType = "Flat"
            };
            var json2 = JsonConvert.SerializeObject(smile2);

            re2.Object = new JRaw(json2);
            var rec = new RelatedEntityCollection {
                re1, re2
            };

            rec.RelatedEntity = "Smile";
            odataUser.RelatedEntityCollection.Add(rec);

            // Act
            var odataSmileCollection = odataUser.GetRelatedEntityCollection(nameof(Smile));

            // Assert
            Assert.AreEqual(2, odataSmileCollection.Count);
            Assert.AreEqual("7", odataSmileCollection[0].Id);
            var jObj0 = JObject.Parse(odataSmileCollection[0].Object.ToString());

            Assert.AreEqual("Wide", jObj0["Type"]);
            Assert.AreEqual("8", odataSmileCollection[1].Id);
            var jObj1 = JObject.Parse(odataSmileCollection[1].Object.ToString());

            Assert.AreEqual("Flat", jObj1["Type"]);
        }
Пример #3
0
        public void ToOdataObjectTest()
        {
            // Arrange
            var re = new RelatedEntity {
                Id = "7"
            };
            var smile = new Smile {
                Id = 7, SmileType = "Wide"
            };
            var json = JsonConvert.SerializeObject(smile);

            re.Object = new JRaw(json);

            // Act
            var actualObj = re.ToOdataObject <Smile, int>();

            // Assert
            Assert.AreEqual(7, actualObj.Id);
            Assert.AreEqual(7, actualObj.Object.Id);
            Assert.AreEqual("Wide", actualObj.Object.SmileType);
        }
Пример #4
0
        public void GetRelatedEntity_Generic_Test()
        {
            // Arrange
            var odataUser = new OdataObject <User, int>();
            var re1       = new RelatedEntity {
                Id = "7"
            };
            var smile1 = new Smile {
                Id = 7, SmileType = "Wide"
            };
            var json1 = JsonConvert.SerializeObject(smile1);

            re1.Object = new JRaw(json1);

            var re2 = new RelatedEntity {
                Id = "8"
            };
            var smile2 = new Smile {
                Id = 8, SmileType = "Flat"
            };
            var json2 = JsonConvert.SerializeObject(smile2);

            re2.Object = new JRaw(json2);
            var rec = new RelatedEntityCollection {
                re1, re2
            };

            rec.RelatedEntity = "Smile";
            odataUser.RelatedEntityCollection.Add(rec);

            // Act
            var odataSmileCollection = odataUser.GetRelatedEntityCollection <Smile, int>();

            // Assert
            Assert.AreEqual(2, odataSmileCollection.Count);
            Assert.AreEqual(7, odataSmileCollection[0].Id);
            Assert.AreEqual("Wide", odataSmileCollection[0].Object.SmileType);
            Assert.AreEqual(8, odataSmileCollection[1].Id);
            Assert.AreEqual("Flat", odataSmileCollection[1].Object.SmileType);
        }