示例#1
0
        public async Task GetCollection()
        {
            var testItems = new[]
            {
                new TestResource {
                    Foo = "foo1"
                },
                new TestResource {
                    Foo = "foo2", Bar = true
                },
                new TestResource {
                    Foo = "foo3", Bar = false
                },
            };
            var mockRequestExecutor = new MockedCollectionRequestExecutor <TestResource>(pageSize: 2, items: testItems);
            var dataStore           = new DefaultDataStore(
                mockRequestExecutor,
                new DefaultSerializer(),
                new ResourceFactory(null, null),
                NullLogger.Instance);

            var client = new TestableOktaClient(dataStore);

            var items = await client.GetCollection <TestResource>("https://stuff").ToArray();

            items.Count().Should().Be(3);
            items.ElementAt(0).Foo.Should().Be("foo1");
            items.ElementAt(0).Bar.Should().BeNull();

            items.ElementAt(1).Foo.Should().Be("foo2");
            items.ElementAt(1).Bar.Should().Be(true);

            items.ElementAt(2).Foo.Should().Be("foo3");
            items.ElementAt(2).Bar.Should().Be(false);
        }
        public async Task GetAllItemsWithManualEnumeration()
        {
            var mockRequestExecutor = new MockedCollectionRequestExecutor <IUser>(pageSize: 2, items: TestUsers);
            var dataStore           = new DefaultDataStore(
                mockRequestExecutor,
                new DefaultSerializer(),
                new ResourceFactory(null, null),
                NullLogger.Instance);

            var collection = new CollectionClient <User>(
                dataStore,
                new HttpRequest {
                Uri = "http://mock-collection.dev"
            },
                new RequestContext());

            var items = new List <IUser>();

            var enumerator = collection.GetPagedEnumerator();

            while (await enumerator.MoveNextAsync())
            {
                items.AddRange(enumerator.CurrentPage.Items);
            }

            items.Count.Should().Be(5);
        }
        public async Task GetCollection()
        {
            // Arrange
            var testItems = new[]
            {
                new TestResource {
                    Foo = "foo1"
                },
                new TestResource {
                    Foo = "foo2", Bar = true
                },
                new TestResource {
                    Foo = "foo3", Bar = false
                },
            };
            var mockRequestExecutor = new MockedCollectionRequestExecutor <TestResource>(pageSize: 2, items: testItems);
            var client = new TestableOktaClient(mockRequestExecutor);

            // Act
            var items = await client.GetCollection <TestResource>("https://stuff").ToArray();

            // Assert
            items.Count().Should().Be(3);
            items.ElementAt(0).Foo.Should().Be("foo1");
            items.ElementAt(0).Bar.Should().BeNull();

            items.ElementAt(1).Foo.Should().Be("foo2");
            items.ElementAt(1).Bar.Should().Be(true);

            items.ElementAt(2).Foo.Should().Be("foo3");
            items.ElementAt(2).Bar.Should().Be(false);
        }
        public async Task GetAllItems()
        {
            var mockRequestExecutor = new MockedCollectionRequestExecutor <IUser>(pageSize: 2, items: TestUsers);
            var dataStore           = new DefaultDataStore(
                mockRequestExecutor,
                new DefaultSerializer(),
                new ResourceFactory(null, null),
                NullLogger.Instance);

            var collection = new CollectionClient <User>(
                dataStore,
                new HttpRequest {
                Uri = "http://mock-collection.dev"
            },
                new RequestContext());

            var all = await collection.ToArrayAsync();

            all.Length.Should().Be(5);
        }
        public async Task FilterCollectionAsynchronously()
        {
            var mockRequestExecutor = new MockedCollectionRequestExecutor <IUser>(pageSize: 2, items: TestUsers);
            var dataStore           = new DefaultDataStore(
                mockRequestExecutor,
                new DefaultSerializer(),
                new ResourceFactory(null, null),
                NullLogger.Instance);

            var collection = new CollectionClient <User>(
                dataStore,
                new HttpRequest {
                Uri = "http://mock-collection.dev"
            },
                new RequestContext());

            var activeUsers = await collection.Where(x => x.Status == "ACTIVE").ToListAsync();

            activeUsers.Count.Should().Be(2);
        }
        public async Task CountCollectionAsynchronously()
        {
            var mockRequestExecutor = new MockedCollectionRequestExecutor <IUser>(pageSize: 2, items: TestUsers);
            var dataStore           = new DefaultDataStore(
                mockRequestExecutor,
                new DefaultSerializer(),
                new ResourceFactory(null, null),
                NullLogger.Instance);

            var collection = new CollectionClient <User>(
                dataStore,
                new HttpRequest {
                Uri = "http://mock-collection.dev"
            },
                new RequestContext());

            var count = await collection.CountAsync();

            count.Should().Be(5);
        }
示例#7
0
        public async Task RetrieveQuestionFactorAsInterface()
        {
            var mockRequestExecutor = new MockedCollectionRequestExecutor <IFactor>(pageSize: 2, items: AllFactors);
            var dataStore           = new DefaultDataStore(
                mockRequestExecutor,
                new DefaultSerializer(),
                new ResourceFactory(null, null),
                NullLogger.Instance);

            var collection = new CollectionClient <Factor>(
                dataStore,
                new HttpRequest {
                Uri = "http://mock-collection.dev"
            },
                new RequestContext());

            var retrievedItems = await collection.ToArray();

            var securityQuestionFactor = retrievedItems.OfType <ISecurityQuestionFactor>().FirstOrDefault();

            securityQuestionFactor.Should().NotBeNull();
        }