public void ClientOwnerAsyncCreateNotUsername()
        {
            withSuccessfulResults(client =>
            {
                Owner owner = new Owner.Builder().Build();

                Assert.That(() => client.CreateAsync(owner).Wait(),
                            Throws.TypeOf <AggregateException>()
                            .With.InnerException.TypeOf <ArgumentException>()
                            .With.InnerException.Message.EqualTo("username cannot be blank."));
            });
        }
        public void ClientOwnerSyncCreateUsernamePasswordValidator(string username, string errorMessage, string password)
        {
            Owner owner = new Owner.Builder()
            {
                Username = username,
                Password = password
            };

            Assert.That(() => ownerClient.Create(owner),
                        Throws.TypeOf <ArgumentException>()
                        .With.Message.EqualTo(errorMessage));
        }
        public void ClientOwnerAsyncCreateEmptyUsername(string username, string errorMsg, string password)
        {
            Owner owner = new Owner.Builder()
            {
                Username = username,
                Password = password
            };

            Assert.That(() => ownerClient.CreateAsync(owner).Wait(),
                        Throws.TypeOf <AggregateException>()
                        .With.InnerException.TypeOf <ArgumentException>()
                        .With.InnerException.Message.EqualTo(errorMsg));
        }
Пример #4
0
        public void ClientOwnerAsyncCreateUsernamePasswordValidator(string username, string errorMessage, string password)
        {
            withSuccessfulResults(client =>
            {
                Owner owner = new Owner.Builder()
                {
                    Username = username,
                    Password = password
                };

                Assert.That(() => client.CreateAsync(owner).Wait(),
                            Throws.TypeOf <AggregateException>()
                            .With.InnerException.TypeOf <ArgumentException>()
                            .With.InnerException.Message.EqualTo(errorMessage));
            });
        }
        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);
        }
Пример #6
0
        public void TestDelete()
        {
            String uuid          = Guid.NewGuid().ToString();
            Owner  ownerToDelete = new Owner.Builder()
            {
                Username = "******" + uuid,
                Password = "******" + uuid
            };

            client.Owners.Create(ownerToDelete);
            client.Owners.Delete(ownerToDelete.Username);

            try {
                client.Owners.Delete(ownerToDelete.Username);
                Assert.Fail("Cannot delete on an owner that does not exists");
            } catch {
                //expected
            }
        }
Пример #7
0
        /// <summary>
        /// Implements <see cref="IOwnerClient.UpdatePasswordAsync" />
        /// </summary>
        public async Task UpdatePasswordAsync(string username, string password)
        {
            if (string.IsNullOrEmpty(username))
            {
                throw new ArgumentException("username cannot be blank.");
            }

            if (string.IsNullOrEmpty(password))
            {
                throw new ArgumentException("password cannot be blank.");
            }

            Owner owner = new Owner.Builder()
            {
                Username = username,
                Password = password
            };

            await client.SendAsyncRequest(HttpMethod.Put,
                                          string.Format("/api/v3/owners/{0}/password", username),
                                          OwnerSerializer.SerializeOwner(owner));
        }
        public void OwnerBuilderTest()
        {
            DateTime now = TestUtils.GetNowIgnoringMilis();

            Owner owner = new Owner.Builder()
            {
                Username         = "******",
                Password         = "******",
                RegistrationDate = now,
                Attributes       = new Dictionary <string, object>()
                {
                    { "String", "text" }
                },
            };

            Assert.AreEqual(owner.Password, "password");
            Assert.AreEqual(owner.Username, "username");
            Assert.AreEqual(owner.RegistrationDate, now);
            CollectionAssert.AreEqual(owner.Attributes, new Dictionary <string, object>()
            {
                { "String", "text" }
            });
        }
Пример #9
0
        public void SmartObjectBuilderTestWithOwner()
        {
            DateTime now      = TestUtils.GetNowIgnoringMilis();
            Guid     eventId  = Guid.NewGuid();
            Guid     objectId = Guid.NewGuid();
            Dictionary <string, object> attributes = new Dictionary <string, object>();

            attributes.Add("String", "text");

            Owner owner = new Owner.Builder()
            {
                Username = "******"
            };

            SmartObject myObject = new SmartObject.Builder()
            {
                EventId          = eventId,
                ObjectId         = objectId,
                ObjectType       = "objectType",
                RegistrationDate = now,
                Attributes       = new Dictionary <string, object>()
                {
                    { "String", "text" }
                },
                DeviceId = "deviceId",
                Username = "******"
            };

            Assert.AreEqual(myObject.EventId, eventId);
            Assert.AreEqual(myObject.ObjectId, objectId);
            Assert.AreEqual(myObject.ObjectType, "objectType");
            Assert.AreEqual(myObject.RegistrationDate, now);
            CollectionAssert.AreEqual(myObject.Attributes, attributes);
            Assert.AreEqual(myObject.DeviceId, "deviceId");
            Assert.AreEqual(myObject.Username, "username");
        }
Пример #10
0
        public void TestClaimUnclaimWithBody()
        {
            String uuid   = Guid.NewGuid().ToString();
            String value1 = "value-" + uuid;
            Owner  owner  = new Owner.Builder()
            {
                Username   = "******" + uuid,
                Password   = "******" + uuid,
                Attributes = new Dictionary <string, object>()
                {
                    { "owner_text_attribute", value1 }
                }
            };
            Dictionary <string, object> body = new Dictionary <string, object>()
            {
                { "x_timestamp", "2017-04-24T16:13:11+00:00" }
            };

            SmartObject smartObject = new SmartObject.Builder()
            {
                DeviceId   = "deviceId-" + uuid,
                ObjectType = "object_type1",
                Attributes = new Dictionary <string, object>()
                {
                    { "object_text_attribute", value1 }
                }
            };

            client.Owners.Create(owner);
            client.Objects.Create(smartObject);

            try {
                client.Owners.Claim(uuid, smartObject.DeviceId, body);
                Assert.Fail("Claim on a non existent owner should fail");
            } catch {
                //expected
            }

            try {
                client.Owners.Claim(owner.Username, uuid, body);
                Assert.Fail("Claim on a non existent owner should fail");
            } catch {
                //expected
            }

            client.Owners.Claim(owner.Username, smartObject.DeviceId, body);

            try {
                client.Owners.Unclaim(uuid, smartObject.DeviceId, body);
                Assert.Fail("Unclaim on an non-existing owner should fail");
            } catch {
                //expected
            }
            try {
                client.Owners.Unclaim(owner.Username, uuid, body);
                Assert.Fail("Unclaim on an non-existing object should fail");
            } catch {
                //expected
            }

            client.Owners.Unclaim(owner.Username, smartObject.DeviceId, body);

            try {
                client.Owners.Unclaim(owner.Username, smartObject.DeviceId);
                Assert.Fail("Unclaim on an already unclaimed object should fail");
            } catch {
                //expected
            }
        }
Пример #11
0
        /// <summary>
        /// deserialize a json string to an owner instance
        /// </summary>
        /// <param name="obj">json string</param>
        /// <returns>owner instance</returns>
        public static Owner DeserializeOwner(string obj)
        {
            Owner.Builder builder = new Owner.Builder();
            Dictionary <string, object> attributes = new Dictionary <string, object>();

            var rawOwner = JsonConvert.DeserializeObject <Dictionary <string, object> >(obj,
                                                                                        new JsonSerializerSettings
            {
                NullValueHandling    = NullValueHandling.Ignore,
                DateFormatString     = EventSerializer.DatetimeFormat,
                DateTimeZoneHandling = DateTimeZoneHandling.Utc
            });

            foreach (KeyValuePair <string, object> token in rawOwner)
            {
                switch (token.Key)
                {
                case UsernameProperty:
                {
                    if (!(token.Value is string))
                    {
                        throw new InvalidOperationException("Field 'username' does not match TYPE 'TEXT'");
                    }
                    builder.Username = token.Value as string;
                    break;
                }

                case RegistrationDateProperty:
                {
                    if (token.Value == null || !(token.Value is DateTime))
                    {
                        throw new InvalidOperationException("Field 'x_registration_date' does not match TYPE 'DATETIME'");
                    }
                    builder.RegistrationDateTime = new DateTimeOffset((DateTime)token.Value);
                    break;
                }

                case PasswordProperty:
                {
                    if (!(token.Value is string))
                    {
                        throw new InvalidOperationException("Field 'x_password' does not match TYPE 'TEXT'");
                    }
                    builder.Password = token.Value as string;
                    break;
                }

                default:
                {
                    if (token.Value is JArray)
                    {
                        attributes.Add(token.Key, (token.Value as JArray).ToObject <string[]>());
                    }
                    else
                    {
                        attributes.Add(token.Key, token.Value);
                    }
                    break;
                }
                }
            }
            builder.Attributes = attributes;

            return(builder.Build());
        }
Пример #12
0
        public void TestClaimUnclaim()
        {
            String uuid   = Guid.NewGuid().ToString();
            String value1 = "value-" + uuid;
            Owner  owner  = new Owner.Builder()
            {
                Username   = "******" + uuid,
                Password   = "******" + uuid,
                Attributes = new Dictionary <string, object>()
                {
                    { "owner_text_attribute", value1 }
                }
            };

            SmartObject smartObject = new SmartObject.Builder()
            {
                DeviceId   = "deviceId-" + uuid,
                ObjectType = "object_type1",
                Attributes = new Dictionary <string, object>()
                {
                    { "object_text_attribute", value1 }
                }
            };

            client.Owners.Create(owner);
            client.Objects.Create(smartObject);

            try {
                client.Owners.Claim(uuid, smartObject.DeviceId);
                Assert.Fail("Claim on a non existent owner should fail");
            } catch {
                //expected
            }

            try {
                client.Owners.Claim(owner.Username, uuid);
                Assert.Fail("Claim on a non existent owner should fail");
            } catch {
                //expected
            }

            client.Owners.Claim(owner.Username, smartObject.DeviceId);

            ITTestHelper.EventuallyAssert(() => {
                ResultSet resultOwn = client.Restitution.Search(ITTestHelper.searchObjectByOwnerQuery(owner.Username));
                Assert.AreEqual(1, resultOwn.Rows.Count);
            });

            try {
                client.Owners.Unclaim(uuid, smartObject.DeviceId);
                Assert.Fail("Unclaim on an non-existing owner should fail");
            } catch {
                //expected
            }
            try {
                client.Owners.Unclaim(owner.Username, uuid);
                Assert.Fail("Unclaim on an non-existing object should fail");
            } catch {
                //expected
            }

            client.Owners.Unclaim(owner.Username, smartObject.DeviceId);

            try {
                client.Owners.Unclaim(owner.Username, smartObject.DeviceId);
                Assert.Fail("Unclaim on an already unclaimed object should fail");
            } catch {
                //expected
            }
        }