예제 #1
0
        public void CreateConnectionShouldDelegateToConnectionManagerWithCorrectParameters()
        {
            var connection = new Connection();
            _client.CreateConnection(connection);

            _connectionManager.Received(1).CreateConnection(connection);
        }
예제 #2
0
        public void GetConnectionsShouldDelegateToConnectionManagerWithCorrectParameters()
        {
            var connection = new Connection();
            var enityList = new List<UsergridEntity>();
            _connectionManager.GetConnections(connection).Returns(enityList);

            IList<UsergridEntity> returnedEntityList = _client.GetConnections(connection);

            _connectionManager.Received(1).GetConnections(connection);
            Assert.AreEqual(enityList, returnedEntityList);
        }
예제 #3
0
        public void ShouldGetAndGetSimpleConnection()
        {
            IClient client = InitializeClientAndLogin(AuthType.Organization);
            DeleteEntityIfExists<Customer>(client, "customers", "customer1");
            DeleteEntityIfExists<Order>(client, "orders", "order1");

            client.CreateEntity("customers", new Customer
                {
                    Name = "customer1",
                    No = "1"
                });
            client.CreateEntity("orders", new Order
                {
                    Name = "order1",
                    Id = "1"
                });

            //to get a collection you need connector details and the connection name
            var getConnectionDetails = new Connection()
                {
                    ConnectorCollectionName = "customers",
                    ConnectorIdentifier = "customer1",
                    ConnectionName = "has"
                };
            //to create/delete a collection you need all the connector and connectee details and the connection name.
            var createDeleteConnectionDetails = new Connection()
            {
                ConnectorCollectionName = "customers",
                ConnectorIdentifier = "customer1",
                ConnecteeCollectionName = "orders",
                ConnecteeIdentifier = "order1",
                ConnectionName = "has"
            };

            //no connections yet
            IList<UsergridEntity> connections = client.GetConnections(getConnectionDetails);
            Assert.AreEqual(0, connections.Count);

            //create a connection between customer1 and order1
            client.CreateConnection(createDeleteConnectionDetails);

            //verify the connection
            connections = client.GetConnections(getConnectionDetails);
            Assert.AreEqual(1, connections.Count);
            Assert.AreEqual("order1", connections[0].Name);

            //delete the connection
            client.DeleteConnection(createDeleteConnectionDetails);

            //verify that it is deleted
            connections = client.GetConnections(getConnectionDetails);
            Assert.AreEqual(0, connections.Count);
        }
예제 #4
0
        public void ShouldFollowUserViaConnections()
        {
            IClient client = InitializeClientAndLogin(AuthType.Organization);
            DeleteUserIfExists(client, "user1");
            DeleteUserIfExists(client, "user2");
            
            UsergridUser user1 = new UsergridUser { UserName = "******", Email = "*****@*****.**" };
            client.CreateUser(user1);
            UsergridUser user2 = new UsergridUser { UserName = "******", Email = "*****@*****.**" };
            client.CreateUser(user2);
            
            var conn = new Connection();
            conn.ConnectorIdentifier = "user1";
            conn.ConnectorCollectionName = "users";
            conn.ConnecteeIdentifier = "user2";
            conn.ConnecteeCollectionName = "users";
            conn.ConnectionName = "following";
            
            client.CreateConnection(conn);

            //verify the connections
            var user1Uuid = client.GetEntities<UsergridUser>("users", limit: 1, query: "select * where username='******'").First().Uuid;
            var user2Uuid = client.GetEntities<UsergridUser>("users", limit: 1, query: "select * where username='******'").First().Uuid;

            //user1 should be following user2
            IList<UsergridEntity> followingConnections = client.GetConnections(new Connection()
            {
                ConnectorCollectionName = "users",
                ConnectorIdentifier = "user1",
                ConnectionName = "following"
            });

            Assert.AreEqual(1, followingConnections.Count);
            Assert.AreEqual(user2Uuid, followingConnections[0].Uuid);

            //also, user1 should be in the followers connection of user2
            IList<UsergridEntity> followersConnections = client.GetConnections(new Connection()
            {
                ConnectorCollectionName = "users",
                ConnectorIdentifier = "user2",
                ConnectionName = "followers"
            });

            Assert.AreEqual(1, followersConnections.Count);
            Assert.AreEqual(user1Uuid, followersConnections[0].Uuid);
        }