public async Task RetrieveTop5Accounts()
        {
            var client = new TellmaClient(
                baseUrl: "https://web.tellma.com",
                authorityUrl: "https://web.tellma.com",
                clientId: "<your-client-id>",
                clientSecret: "<your-client-secret>");

            var response = await client
                           .Application(tenantId : 201)
                           .Accounts
                           .GetEntities(new GetArguments
            {
                Select  = "Id,Name,Name2,Code",
                OrderBy = "Id",
                Top     = 5
            });

            var accounts = response.Data;

            // Do something with accounts
        }
        public async Task Scenario01()
        {
            try
            {
                #region Deployment Experiment

                //// https://stackoverflow.com/questions/10438258/using-microsoft-build-evaluation-to-publish-a-database-project-sqlproj

                //const string projectPath = "";
                //const string connString = "";

                ////This Snapshot should be created by our build process using MSDeploy
                //const string snapshotPath = "";

                //var project = ProjectCollection.GlobalProjectCollection.LoadProject(projectPath);
                //project.Build();

                //DacServices dbServices = new DacServices(connString);
                //DacPackage dbPackage = DacPackage.Load(snapshotPath);



                //DacDeployOptions dbDeployOptions = new DacDeployOptions();

                ////Cut out a lot of options here for configuring deployment, but are all part of DacDeployOptions
                //dbDeployOptions.SqlCommandVariableValues.Add("debug", "false");

                //string dbName = "Tellma.101";
                //dbServices.Deploy(dbPackage, dbName, true, dbDeployOptions);

                #endregion

                #region Access Token

                //var tokenResponse = await Client.RequestPasswordTokenAsync(new PasswordTokenRequest
                //{
                //    Address = "/connect/token",
                //    ClientId = Services.Utilities.Constants.WebClientName,
                //    ClientSecret = "top-secret",
                //    Scope = Services.Utilities.Constants.ApiResourceName, // What about the others?
                //    UserName = "******",
                //    Password = "******"
                //});

                var tokenResponse = await Client.RequestClientCredentialsTokenAsync(new ClientCredentialsTokenRequest
                {
                    Address      = "/connect/token",
                    ClientId     = "m2m-5d3f198c-287b-49e9-bf7c-5879b6f2a4d8",
                    ClientSecret = "aced45ff3450ff81afb9c73492e069fbc8cd92faae113635ef1fae766b6e4591",
                    Scope        = Services.Utilities.Constants.ApiResourceName,
                });

                Assert.False(tokenResponse.IsError, $"Admin authentication failed, Error: {tokenResponse.Error}.");
                var accessToken = tokenResponse.AccessToken;
                Assert.NotNull(accessToken);

                #endregion

                // Call the protected API
                var accessTokenFactory = new StaticAccessTokenFactory(accessToken);
                var client             = new TellmaClient(Client, accessTokenFactory);

                const int totalCount = 34;
                var       clientApp  = client.Application(tenantId: 201);

                #region GetEntities
                {
                    var response = await clientApp
                                   .Units
                                   .GetEntities(new GetArguments
                    {
                        Select        = $"{nameof(Unit.Name)},{nameof(Unit.CreatedBy)}.{nameof(User.Name)}",
                        OrderBy       = nameof(Unit.Id),
                        Top           = 5,
                        CountEntities = true
                    });

                    Assert.Equal(totalCount, response.Count);
                    Assert.NotNull(response.Data);
                    Assert.Equal(5, response.Data.Count);

                    var unit = response.Data[0];
                    Assert.NotNull(unit.CreatedBy);
                    Assert.Equal("Mohamad Akra", unit.CreatedBy.Name);
                }
                #endregion

                #region GetFact
                {
                    var response = await clientApp
                                   .Units
                                   .GetFact(new FactArguments
                    {
                        Select        = $"{nameof(Unit.Name)},{nameof(Unit.CreatedBy)}.{nameof(User.Name)}",
                        OrderBy       = nameof(Unit.Id),
                        Top           = 5,
                        CountEntities = true
                    });

                    Assert.Equal(totalCount, response.Count);
                    Assert.NotNull(response.Data);
                    Assert.Equal(5, response.Data.Count);

                    var row = response.Data[0];
                    Assert.Equal(2, row.Count);
                    Assert.Equal("pure", row[0]);
                    Assert.Equal("Mohamad Akra", row[1]);
                }
                #endregion

                #region Get Null
                {
                    var response = await clientApp
                                   .Units
                                   .GetFact(new FactArguments
                    {
                        Select = $"null",
                        Top    = 1
                    });

                    Assert.NotNull(response.Data);
                    var row   = Assert.Single(response.Data);
                    var datum = Assert.Single(row);
                    Assert.Null(datum);
                }
                #endregion

                #region GetAggregate
                {
                    var response = await clientApp
                                   .Units
                                   .GetAggregate(new GetAggregateArguments
                    {
                        Select = $"Count({nameof(Unit.Id)})",
                    });

                    var rows  = response.Data;
                    var row   = Assert.Single(rows);
                    var datum = Assert.Single(row);

                    Assert.Equal(totalCount, Convert.ToInt32(datum));
                }
                #endregion

                #region GetById
                {
                    var response = await clientApp
                                   .Units
                                   .GetById(1, new GetByIdArguments
                    {
                        Select = $"{nameof(Unit.Name)},{nameof(Unit.CreatedBy)}.{nameof(User.Name)}",
                    });

                    var unit = response.Entity;
                    Assert.Equal("pure", unit.Name);
                    Assert.NotNull(unit.CreatedBy);
                    Assert.Equal("Mohamad Akra", unit.CreatedBy.Name);
                }
                #endregion

                #region Save
                int id;
                {
                    var unitForSave = new UnitForSave
                    {
                        Name        = "ly",
                        Description = "Lightyear",
                        UnitType    = UnitTypes.Distance,
                        Code        = "ly",
                        BaseAmount  = 1,
                        UnitAmount  = 1000
                    };

                    var response = await clientApp
                                   .Units
                                   .Save(new List <UnitForSave> {
                        unitForSave
                    },
                                         new SaveArguments
                    {
                        Expand         = nameof(Unit.CreatedBy),
                        ReturnEntities = true
                    });

                    var unit = Assert.Single(response.Data);

                    Assert.Equal(unitForSave.Name, unit.Name);
                    Assert.Equal(unitForSave.Description, unit.Description);
                    Assert.Equal(unitForSave.UnitType, unit.UnitType);
                    Assert.Equal(unitForSave.Code, unit.Code);
                    Assert.Equal(unitForSave.BaseAmount, unit.BaseAmount);
                    Assert.Equal(unitForSave.UnitAmount, unit.UnitAmount);

                    Assert.NotNull(unit.CreatedBy);
                    Assert.Equal("Integration Tests", unit.CreatedBy.Name);

                    id = unit.Id;
                    Assert.NotEqual(0, id);
                }
                #endregion

                #region Delete
                {
                    await clientApp.Units.DeleteById(id);
                }
                #endregion

                {
                    var response = await clientApp.Resources(definitionId : 41).GetById(id: 3429, new GetByIdArguments {
                    });

                    Assert.NotNull(response.Entity);
                    Assert.Equal("Raw Light Speckled Bean", response.Entity.Name);
                }

                {
                    var user = await clientApp.Users.GetByIdForSave(1);

                    Assert.NotEmpty(user.Roles);
                }

                {
                    var docsClient = clientApp.Documents(definitionId: 29);
                    var doc        = await docsClient.GetByIdForSave(19431);

                    Assert.NotEmpty(doc.Lines);

                    doc.PostingDate = doc.PostingDate.Value.AddDays(-1);

                    var response = await docsClient.Save(new List <DocumentForSave> {
                        doc
                    });

                    Assert.Null(response.Data);
                }

                {
                    var response = await clientApp.Units.Deactivate(new List <int> {
                        41
                    });

                    Assert.Null(response.Data);
                }

                {
                    var response = await clientApp.Units.Activate(new List <int> {
                        41
                    }, new ActivateArguments { ReturnEntities = true });

                    var unit = Assert.Single(response.Data);
                    Assert.True(unit.IsActive);
                }

                //var settings = await response.Content.ReadAsAsync<Versioned<SettingsForClient>>();
                //Assert.Equal("Soreti Trading", settings.Data.ShortCompanyName);
            }
            catch (TellmaException ex)
            {
                _output.WriteLine(ex.ToString());
                throw;
            }
        }