示例#1
0
        public void LinqAttributes_Counter_AttemptInsert()
        {
            // Create config that uses linq based attributes
            var mappingConfig = new MappingConfiguration();

            mappingConfig.MapperFactory.PocoDataFactory.AddDefinitionDefault(typeof(CounterEntityWithLinqAttributes),
                                                                             () => LinqAttributeBasedTypeDefinition.DetermineAttributes(typeof(CounterEntityWithLinqAttributes)));
            var table = new Table <CounterEntityWithLinqAttributes>(Session, mappingConfig);

            CounterEntityWithLinqAttributes pocoAndLinqAttributesLinqPocos = new CounterEntityWithLinqAttributes()
            {
                KeyPart1 = Guid.NewGuid(),
                KeyPart2 = (decimal)123,
            };

            var expectedErrMsg = "INSERT statement(s)? are not allowed on counter tables, use UPDATE instead";

            TestCluster.PrimeFluent(
                b => b.WhenQuery(
                    "INSERT INTO \"CounterEntityWithLinqAttributes\" (\"Counter\", \"KeyPart1\", \"KeyPart2\") VALUES (?, ?, ?)",
                    when => pocoAndLinqAttributesLinqPocos.WithParams(when))
                .ThenServerError(
                    ServerError.Invalid, expectedErrMsg));

            var e = Assert.Throws <InvalidQueryException>(() => Session.Execute(table.Insert(pocoAndLinqAttributesLinqPocos)));

            Assert.AreEqual(expectedErrMsg, e.Message);
        }
示例#2
0
 private void PrimeLinqCounterQuery(CounterEntityWithLinqAttributes counter)
 {
     TestCluster.PrimeDelete();
     TestCluster.PrimeFluent(
         b => b.WhenQuery(
             "SELECT \"Counter\", \"KeyPart1\", \"KeyPart2\" " +
             "FROM \"CounterEntityWithLinqAttributes\" " +
             "WHERE \"KeyPart1\" = ? AND \"KeyPart2\" = ?",
             when => counter.WithParams(when, "KeyPart1", "KeyPart2"))
         .ThenRowsSuccess(counter.CreateRowsResult()));
 }