示例#1
0
        public void Update_Poco_WithCql()
        {
            // Get a user to update
            Guid userId       = TestDataHelper.Users[5].UserId;
            var  userToUpdate = CqlClient.Single <UserWithPrimaryKeyDecoration>("WHERE userid = ?", userId);

            userToUpdate.Should().NotBeNull();

            // Modify some values on the user (just so we can assert against it)
            userToUpdate.Name = "SomeNameChangedWithCql";
            userToUpdate.LuckyNumbers.Add(54);
            userToUpdate.FavoriteColor = Enum.GetValues(typeof(RainbowColor)).Cast <RainbowColor>().First(v => v != userToUpdate.FavoriteColor);

            // Update the user using a CQL string (we aren't passing a POCO here, just CQL + params)
            CqlClient.Update <UserWithPrimaryKeyDecoration>("SET name = ?, luckynumbers = ?, favoritecolor = ? WHERE userid = ?",
                                                            userToUpdate.Name, userToUpdate.LuckyNumbers,
                                                            CqlClient.ConvertCqlArgument <RainbowColor, string>(userToUpdate.FavoriteColor), userId);

            // Fetch and validate
            var foundUser = CqlClient.Single <UserWithPrimaryKeyDecoration>("WHERE userid = ?", userId);

            foundUser.ShouldBeEquivalentTo(userToUpdate, opt => opt.AccountForTimestampAccuracy());
        }