Ejemplo n.º 1
0
        public async void FetchAsyncAll_FluentPocos_WithOptions()
        {
            List <FluentUser> users = await CqlClient.FetchAsync <FluentUser>(new CqlQueryOptions().DoNotPrepare());

            users.ShouldAllBeEquivalentTo(TestDataHelper.Users, opt => opt.AccountForTimestampAccuracy().Using(FluentUserToTestUserMatchingRule.Instance).ExcludingMissingProperties());
            users.Select(u => u.SomeIgnoredProperty).Should().OnlyContain(p => p == null);
        }
Ejemplo n.º 2
0
        public async void FetchAsync_Pocos_WithPredicateOnly()
        {
            // Lookup the first 2 users by id with only a FROM + WHERE
            TestUser[]       usersToGet = TestDataHelper.Users.Take(2).ToArray();
            List <PlainUser> users      = await CqlClient.FetchAsync <PlainUser>("FROM users WHERE userid IN (?, ?)", usersToGet[0].UserId, usersToGet[1].UserId);

            users.ShouldAllBeEquivalentTo(usersToGet, opt => opt.AccountForTimestampAccuracy());
        }
Ejemplo n.º 3
0
        public async void FetchAsync_FluentPocos_WithPredicateOnly()
        {
            // Lookup users 3 and 4 with just a WHERE clause
            TestUser[] usersToGet = TestDataHelper.Users.Skip(2).Take(2).ToArray();

            List <FluentUser> users = await CqlClient.FetchAsync <FluentUser>("WHERE userid IN (?, ?)", usersToGet[0].UserId, usersToGet[1].UserId);

            users.ShouldAllBeEquivalentTo(usersToGet, opt => opt.AccountForTimestampAccuracy().Using(FluentUserToTestUserMatchingRule.Instance).ExcludingMissingProperties());
            users.Select(u => u.SomeIgnoredProperty).Should().OnlyContain(p => p == null);
        }
Ejemplo n.º 4
0
        public async void FetchAsync_ExplicitColumnsPocos_WithCql()
        {
            List <ExplicitColumnsUser> users = await CqlClient.FetchAsync <ExplicitColumnsUser>("SELECT * FROM users");

            // Compare to test users but exclude missing properties since we only queried a subset, as well as explicitly ignore
            // the name property because that should not have been mapped because it's missing a Column attribute
            users.ShouldAllBeEquivalentTo(TestDataHelper.Users, opt => opt.ExcludingMissingProperties().Excluding(u => u.Name));

            // All name properties should be null
            users.Select(u => u.Name).Should().OnlyContain(name => name == null);
        }
Ejemplo n.º 5
0
        public async void FetchAsyncAll_ExplicitColumnsPocos()
        {
            // We should be able to fetch explicit columns poco with no CQL (i.e. have it generated for us)
            List <ExplicitColumnsUser> users = await CqlClient.FetchAsync <ExplicitColumnsUser>();

            // Compare to test users but exclude missing properties since we only queried a subset, as well as explicitly ignore
            // the name property because that should not have been mapped because it's missing a Column attribute
            users.ShouldAllBeEquivalentTo(TestDataHelper.Users, opt => opt.ExcludingMissingProperties().Excluding(u => u.Name));

            // All name properties should be null
            users.Select(u => u.Name).Should().OnlyContain(name => name == null);
        }
Ejemplo n.º 6
0
        public async void FetchAsync_ExplicitColumnsPocos_WithPredicateOnly()
        {
            // Lookup users 5 and 6 with just a WHERE clause
            TestUser[] usersToGet = TestDataHelper.Users.Skip(4).Take(2).ToArray();

            List <ExplicitColumnsUser> users = await CqlClient.FetchAsync <ExplicitColumnsUser>("WHERE userid IN (?, ?)", usersToGet[0].UserId, usersToGet[1].UserId);

            // Compare to test users but exclude missing properties since we only queried a subset, as well as explicitly ignore
            // the name property because that should not have been mapped because it's missing a Column attribute
            users.ShouldAllBeEquivalentTo(usersToGet, opt => opt.ExcludingMissingProperties().Excluding(u => u.Name));

            // All name properties should be null
            users.Select(u => u.Name).Should().OnlyContain(name => name == null);
        }
Ejemplo n.º 7
0
        public async void FetchAsync_DecoratedPocos_WithCql()
        {
            List <DecoratedUser> users = await CqlClient.FetchAsync <DecoratedUser>("SELECT * FROM users");

            foreach (DecoratedUser user in users)
            {
                // Match users from UserId -> Id property and test that matching properties are equivalent
                TestUser testUser = TestDataHelper.Users.SingleOrDefault(u => u.UserId == user.Id);
                user.ShouldBeEquivalentTo(testUser, opt => opt.ExcludingMissingProperties());

                // Also make sure that ignored property was ignored
                user.AnUnusedProperty.Should().NotHaveValue();
            }
        }
Ejemplo n.º 8
0
        public async void FetchAsyncAll_DecoratedPocos_WithOptions()
        {
            // We should be able to get all the decorated POCOs without any CQL (i.e. have it generated for us)
            List <DecoratedUser> users = await CqlClient.FetchAsync <DecoratedUser>(CqlQueryOptions.New().EnableTracing());

            foreach (DecoratedUser user in users)
            {
                // Match users from UserId -> Id property and test that matching properties are equivalent
                TestUser testUser = TestDataHelper.Users.SingleOrDefault(u => u.UserId == user.Id);
                user.ShouldBeEquivalentTo(testUser, opt => opt.ExcludingMissingProperties());

                // Also make sure that ignored property was ignored
                user.AnUnusedProperty.Should().NotHaveValue();
            }
        }
Ejemplo n.º 9
0
        public async void FetchAsync_DecoratedPocos_WithPredicateOnly()
        {
            // Lookup users 3 and 4 with just a WHERE clause
            TestUser[]           usersToGet = TestDataHelper.Users.Skip(2).Take(2).ToArray();
            List <DecoratedUser> users      = await CqlClient.FetchAsync <DecoratedUser>("WHERE userid IN (?, ?)", usersToGet[0].UserId, usersToGet[1].UserId);

            foreach (DecoratedUser user in users)
            {
                // Match users from UserId -> Id property and test that matching properties are equivalent
                TestUser testUser = usersToGet.SingleOrDefault(u => u.UserId == user.Id);
                user.ShouldBeEquivalentTo(testUser, opt => opt.ExcludingMissingProperties());

                // Also make sure that ignored property was ignored
                user.AnUnusedProperty.Should().NotHaveValue();
            }
        }
Ejemplo n.º 10
0
        public async void FetchAsync_OneColumnFlattened_WithCql()
        {
            // Try regular value type
            List <int> ages = await CqlClient.FetchAsync <int>("SELECT age FROM users");

            ages.Should().BeEquivalentTo(TestDataHelper.Users.Select(u => u.Age).ToList());

            // Try nullable type (truncate to ms to account for C* storing timestamps with ms precision)
            List <DateTimeOffset?> lastLogins = await CqlClient.FetchAsync <DateTimeOffset?>("SELECT lastlogindate FROM users");

            lastLogins.Should().BeEquivalentTo(TestDataHelper.Users.Select(u => u.LastLoginDate.ToMillisecondPrecision()));

            // Try string -> enum conversion
            List <RainbowColor> faveColors = await CqlClient.FetchAsync <RainbowColor>("SELECT favoritecolor FROM users");

            faveColors.Should().BeEquivalentTo(TestDataHelper.Users.Select(u => u.FavoriteColor));
        }
Ejemplo n.º 11
0
        public async void FetchAsync_Pocos_WithCqlAndOptions()
        {
            List <PlainUser> users = await CqlClient.FetchAsync <PlainUser>(Cql.New("SELECT * FROM users").WithOptions(opt => opt.SetConsistencyLevel(ConsistencyLevel.Quorum)));

            users.ShouldAllBeEquivalentTo(TestDataHelper.Users, opt => opt.AccountForTimestampAccuracy());
        }
Ejemplo n.º 12
0
        public async void FetchAsync_Pocos_WithCql()
        {
            List <PlainUser> users = await CqlClient.FetchAsync <PlainUser>("SELECT * FROM users");

            users.ShouldAllBeEquivalentTo(TestDataHelper.Users, opt => opt.AccountForTimestampAccuracy());
        }