public void Linq_CqlQueryBase_Execute_Anonymous_Single_Value_Type() { //It does not have much sense to use an anonymous type with a single value but here it goes! var table = GetSession(TestDataHelper.CreateMultipleValuesRowSet(new[] { "intvalue" }, new[] { 25 })).GetTable <AllTypesEntity>(); var result = (from e in table select new { user_age = e.IntValue }).Execute().ToList(); Assert.AreEqual(25, result[0].user_age); }
public void Linq_CqlQueryBase_Execute_Anonymous_Type() { var table = GetSession(TestDataHelper.CreateMultipleValuesRowSet(new[] { "IntValue", "Int64Value" }, new[] { 25, 1000 })).GetTable <AllTypesEntity>(); var result = (from e in table select new { user_age = e.IntValue, identifier = e.Int64Value }).Execute().ToList(); Assert.AreEqual(1000L, result[0].identifier); Assert.AreEqual(25, result[0].user_age); }
public void DeleteIf_Cql_Applied_True_Test() { var session = GetSession((q, args) => { }, TestDataHelper.CreateMultipleValuesRowSet(new[] { "[applied]" }, new[] { true })); var mapper = new Mapper(session, new MappingConfiguration()); var appliedInfo = mapper.DeleteIf <Song>(Cql.New("WHERE id = ? IF title = ?", Guid.NewGuid(), "All of My love")); Assert.True(appliedInfo.Applied); Assert.Null(appliedInfo.Existing); }
public void DeleteIf_Cql_Applied_False_Test() { var session = GetSession((q, args) => { }, TestDataHelper.CreateMultipleValuesRowSet(new[] { "[applied]", "title" }, new object[] { false, "I Feel Free" })); var mapper = new Mapper(session, new MappingConfiguration()); var appliedInfo = mapper.DeleteIf <Song>(Cql.New("WHERE id = ? IF title = ?", Guid.NewGuid(), "All of My love")); Assert.False(appliedInfo.Applied); Assert.NotNull(appliedInfo.Existing); Assert.AreEqual("I Feel Free", appliedInfo.Existing.Title); }
public void ExecuteConditional_Batch_Applied_True_Test() { var rs = TestDataHelper.CreateMultipleValuesRowSet(new[] { "[applied]" }, new[] { true }); var mapper = GetMapper(() => TestHelper.DelayedTask(rs)); var batch = mapper.CreateBatch(); batch.InsertIfNotExists(new PlainUser()); batch.InsertIfNotExists(new PlainUser()); var info = mapper.ExecuteConditional <PlainUser>(batch); Assert.True(info.Applied); Assert.Null(info.Existing); }
public void ExecuteConditional_Batch_Applied_False_Test() { var id = Guid.NewGuid(); var rs = TestDataHelper.CreateMultipleValuesRowSet(new[] { "[applied]", "userid", "lastlogindate" }, new object[] { false, id, DateTimeOffset.Parse("2015-03-01 +0") }); var mapper = GetMapper(() => TestHelper.DelayedTask(rs)); var batch = mapper.CreateBatch(); batch.Delete <PlainUser>(Cql.New("WHERE userid = ? IF laslogindate = ?", id, DateTimeOffset.Now)); batch.Insert(new PlainUser()); var info = mapper.ExecuteConditional <PlainUser>(batch); Assert.False(info.Applied); Assert.NotNull(info.Existing); Assert.AreEqual(id, info.Existing.UserId); Assert.AreEqual(DateTimeOffset.Parse("2015-03-01 +0"), info.Existing.LastLoginDate); }
public void Select_Project_To_New_Type_Constructor() { string query = null; object[] parameters = null; var session = GetSession((q, v) => { query = q; parameters = v; }, TestDataHelper.CreateMultipleValuesRowSet(new[] { "val", "id" }, new[] { 1, 200 })); var map = new Map <AllTypesEntity>() .ExplicitColumns() .Column(t => t.DoubleValue, cm => cm.WithName("val")) .Column(t => t.IntValue, cm => cm.WithName("id")) .PartitionKey(t => t.UuidValue) .TableName("tbl1"); var table = GetTable <AllTypesEntity>(session, map); (from t in table where t.IntValue == 200 select new Tuple <double, int>(t.DoubleValue, t.IntValue)).Execute(); Assert.AreEqual("SELECT val, id FROM tbl1 WHERE id = ?", query); CollectionAssert.AreEqual(parameters, new object[] { 200 }); }
public void UpdateIf_AppliedInfo_True_Test() { string query = null; var sessionMock = new Mock <ISession>(MockBehavior.Strict); sessionMock .Setup(s => s.ExecuteAsync(It.IsAny <BoundStatement>())) .Returns(TestHelper.DelayedTask(TestDataHelper.CreateMultipleValuesRowSet(new[] { "[applied]" }, new [] { true }))) .Callback <BoundStatement>(b => query = b.PreparedStatement.Cql) .Verifiable(); sessionMock .Setup(s => s.PrepareAsync(It.IsAny <string>())) .Returns <string>(cql => TestHelper.DelayedTask(GetPrepared(cql))) .Verifiable(); var mapper = GetMappingClient(sessionMock); const string partialQuery = "SET title = ?, releasedate = ? WHERE id = ? IF artist = ?"; var appliedInfo = mapper.UpdateIf <Song>(Cql.New(partialQuery, "Ramble On", new DateTime(1969, 1, 1), Guid.NewGuid(), "Led Zeppelin")); sessionMock.Verify(); Assert.AreEqual("UPDATE Song " + partialQuery, query); Assert.True(appliedInfo.Applied); Assert.Null(appliedInfo.Existing); }
public void Select_With_Keyspace_Defined() { string query = null; object[] parameters = null; var session = GetSession((q, v) => { query = q; parameters = v; }, TestDataHelper.CreateMultipleValuesRowSet(new[] { "id" }, new[] { 5000 })); var map = new Map <AllTypesEntity>() .ExplicitColumns() .Column(t => t.DoubleValue, cm => cm.WithName("val")) .Column(t => t.IntValue, cm => cm.WithName("id")) .PartitionKey(t => t.UuidValue) .CaseSensitive() .KeyspaceName("ks1") .TableName("tbl1"); var table = GetTable <AllTypesEntity>(session, map); (from t in table where t.IntValue == 199 select new { Age = t.IntValue }).Execute(); Assert.AreEqual(@"SELECT ""id"" FROM ""ks1"".""tbl1"" WHERE ""id"" = ?", query); CollectionAssert.AreEqual(parameters, new object[] { 199 }); }