Example #1
0
        public async Task FindOrganizationLogsPaging()
        {
            var organization = await _organizationsApi.CreateOrganization(GenerateName("Constant Pro"));

            foreach (var i in Enumerable.Range(0, 19))
            {
                organization.Name = $"{i}_{organization.Name}";

                await _organizationsApi.UpdateOrganization(organization);
            }

            var logs = await _organizationsApi.FindOrganizationLogs(organization);

            Assert.AreEqual(20, logs.Count);
            Assert.AreEqual("Organization Created", logs[0].Description);
            Assert.AreEqual("Organization Updated", logs[19].Description);

            var findOptions = new FindOptions {
                Limit = 5, Offset = 0
            };

            var entries = await _organizationsApi.FindOrganizationLogs(organization, findOptions);

            Assert.AreEqual(5, entries.Logs.Count);
            Assert.AreEqual("Organization Created", entries.Logs[0].Description);
            Assert.AreEqual("Organization Updated", entries.Logs[1].Description);
            Assert.AreEqual("Organization Updated", entries.Logs[2].Description);
            Assert.AreEqual("Organization Updated", entries.Logs[3].Description);
            Assert.AreEqual("Organization Updated", entries.Logs[4].Description);

            findOptions.Offset += 5;

            entries = await _organizationsApi.FindOrganizationLogs(organization, findOptions);

            Assert.AreEqual(5, entries.Logs.Count);
            Assert.AreEqual("Organization Updated", entries.Logs[0].Description);
            Assert.AreEqual("Organization Updated", entries.Logs[1].Description);
            Assert.AreEqual("Organization Updated", entries.Logs[2].Description);
            Assert.AreEqual("Organization Updated", entries.Logs[3].Description);
            Assert.AreEqual("Organization Updated", entries.Logs[4].Description);

            findOptions.Offset += 5;

            entries = await _organizationsApi.FindOrganizationLogs(organization, findOptions);

            Assert.AreEqual(5, entries.Logs.Count);
            Assert.AreEqual("Organization Updated", entries.Logs[0].Description);
            Assert.AreEqual("Organization Updated", entries.Logs[1].Description);
            Assert.AreEqual("Organization Updated", entries.Logs[2].Description);
            Assert.AreEqual("Organization Updated", entries.Logs[3].Description);
            Assert.AreEqual("Organization Updated", entries.Logs[4].Description);

            findOptions.Offset += 5;

            entries = await _organizationsApi.FindOrganizationLogs(organization, findOptions);

            Assert.AreEqual(5, entries.Logs.Count);
            Assert.AreEqual("Organization Updated", entries.Logs[0].Description);
            Assert.AreEqual("Organization Updated", entries.Logs[1].Description);
            Assert.AreEqual("Organization Updated", entries.Logs[2].Description);
            Assert.AreEqual("Organization Updated", entries.Logs[3].Description);
            Assert.AreEqual("Organization Updated", entries.Logs[4].Description);

            findOptions.Offset += 5;

            entries = await _organizationsApi.FindOrganizationLogs(organization, findOptions);

            Assert.AreEqual(0, entries.Logs.Count);

            //
            // Order
            //
            findOptions = new FindOptions {
                Descending = false
            };
            entries = await _organizationsApi.FindOrganizationLogs(organization, findOptions);

            Assert.AreEqual(20, entries.Logs.Count);

            Assert.AreEqual("Organization Updated", entries.Logs[19].Description);
            Assert.AreEqual("Organization Created", entries.Logs[0].Description);
        }