public void OwnerSerializeTest()
        {
            DateTime now = TestUtils.GetNowIgnoringMilis();

            Dictionary <string, object> attributes = new Dictionary <string, object>();

            attributes.Add("string", "stringValue");
            attributes.Add("double", 10d);
            attributes.Add("float", 10.5f);
            attributes.Add("boolean", false);

            Owner owner = new Owner.Builder()
            {
                Username         = "******",
                Password         = "******",
                RegistrationDate = now,
                Attributes       = attributes,
                EventId          = Guid.Parse("9ab392d8-a865-48da-9035-0dc0a728b454")
            };

            string json = OwnerSerializer.SerializeOwner(owner);

            Assert.AreEqual(
                "{\"username\":\"username\"," +
                "\"x_registration_date\":\"" + now.ToString(EventSerializerTest.DatetimeFormat) + "\"," +
                "\"x_password\":\"password\"," +
                "\"event_id\":\"9ab392d8-a865-48da-9035-0dc0a728b454\"," +
                "\"boolean\":false," +
                "\"float\":10.5," +
                "\"double\":10.0," +
                "\"string\":\"stringValue\"}",
                json);
        }
Exemplo n.º 2
0
        public void OwnerSerializeTestDeprecatedDate()
        {
            DateTimeOffset now = new DateTimeOffset(2017, 06, 12, 18, 05, 05, TimeSpan.FromHours(5d));

            Dictionary <string, object> attributes = new Dictionary <string, object>();

            attributes.Add("string", "stringValue");
            attributes.Add("double", 10d);
            attributes.Add("float", 10.5f);
            attributes.Add("boolean", false);

            Owner owner = new Owner.Builder()
            {
                Username         = "******",
                Password         = "******",
                RegistrationDate = now.UtcDateTime,
                Attributes       = attributes,
            };

            string json = OwnerSerializer.SerializeOwner(owner);

            TestUtils.AssertJsonEquals(json, new List <string>
            {
                "\"username\":\"username\"",
                "\"x_registration_date\":\"2017-06-12T13:05:05Z\"",
                "\"x_password\":\"password\"",
                "\"float\":10.5",
                "\"boolean\":false",
                "\"double\":10.0",
                "\"string\":\"stringValue\""
            });
        }
        public void OwnerSerializeTestWithEmptyOwner()
        {
            Owner owner = new Owner.Builder().Build();

            string json = OwnerSerializer.SerializeOwner(owner);

            Assert.AreEqual("{}", json);
        }
        public void OwnerSerializeTestAttributeList()
        {
            Dictionary <string, object> attributes = new Dictionary <string, object>();

            attributes.Add("list", new List <string>()
            {
                "1", "2"
            });

            Owner owner = new Owner.Builder()
            {
                Attributes = attributes
            };

            string json = OwnerSerializer.SerializeOwner(owner);

            Assert.AreEqual("{\"list\":[\"1\",\"2\"]}", json);
        }