public void VirtualPropertiesTest()
        {
            var table  = SessionExtensions.GetTable <InheritedEntity>(GetSession((_, __) => {}));
            var query1 = table.Where(e => e.Id == 10);

            Assert.AreEqual("SELECT \"Id\", \"Description\", \"Name\" FROM \"InheritedEntity\" WHERE \"Id\" = ?", query1.ToString());
            var query2 = (from e in table where e.Id == 1 && e.Name == "MyName" select new { e.Id, e.Name, e.Description });

            Assert.AreEqual("SELECT \"Id\", \"Name\", \"Description\" FROM \"InheritedEntity\" WHERE \"Id\" = ? AND \"Name\" = ?", query2.ToString());
            var sessionMock = new Mock <ISession>(MockBehavior.Strict);
            var config      = new Configuration();
            var metadata    = new Metadata(config);
            var ccMock      = new Mock <IControlConnection>(MockBehavior.Strict);

            ccMock.Setup(cc => cc.Serializer).Returns(new Serializer(ProtocolVersion.MaxSupported));
            metadata.ControlConnection = ccMock.Object;
            var clusterMock = new Mock <ICluster>();

            clusterMock.Setup(c => c.Metadata).Returns(metadata);
            clusterMock.Setup(c => c.Configuration).Returns(config);
            sessionMock.Setup(s => s.Cluster).Returns(clusterMock.Object);
            string createQuery = null;

            sessionMock
            .Setup(s => s.Execute(It.IsAny <string>()))
            .Returns(() => new RowSet())
            .Callback <string>(q => createQuery = q)
            .Verifiable();
            var table2 = SessionExtensions.GetTable <InheritedEntity>(sessionMock.Object);

            table2.CreateIfNotExists();
            Assert.AreEqual("CREATE TABLE \"InheritedEntity\" (\"Id\" int, \"Description\" text, \"Name\" text, PRIMARY KEY (\"Id\"))", createQuery);
        }
        public void TestCqlNullValuesLinqSupport()
        {
            var table = SessionExtensions.GetTable <TestTable>(null);

            Assert.AreEqual(
                @"INSERT INTO ""x_t""(""x_pk"", ""x_ck1"", ""x_ck2"", ""x_f1"") VALUES ('x', null, 2, 3)",
                (table.Insert(new TestTable()
            {
                ck1 = null, ck2 = 2, f1 = 3, pk = "x"
            })).ToString());

            Assert.AreEqual(
                @"UPDATE ""x_t"" SET ""x_f1"" = 1223 WHERE ""x_ck1"" IN (10, 30, 40)",
                (from ent in table where new int?[] { 10, 30, 40 }.Contains(ent.ck1) select new { f1 = 1223 }).Update().ToString());

            Assert.AreEqual(
                @"UPDATE ""x_t"" SET ""x_f1"" = 1223, ""x_ck1"" = NULL WHERE ""x_ck1"" IN (10, 30, 40)",
                (from ent in table where new int?[] { 10, 30, 40 }.Contains(ent.ck1) select new TestTable()
            {
                f1 = 1223, ck1 = null
            }).Update().ToString());

            Assert.AreEqual(
                @"UPDATE ""x_t"" SET ""x_f1"" = 1223, ""x_ck1"" = NULL WHERE ""x_ck1"" = 1",
                (from ent in table where ent.ck1 == 1 select new TestTable()
            {
                f1 = 1223, ck1 = null
            }).Update().ToString());

            Assert.AreEqual(
                @"UPDATE ""x_t"" SET ""x_f1"" = 1223, ""x_ck1"" = NULL WHERE ""x_ck1"" IN (10, 30, 40) IF ""x_f1"" = 123",
                (from ent in table where new int?[] { 10, 30, 40 }.Contains(ent.ck1) select new { f1 = 1223, ck1 = (int?)null }).UpdateIf((a) => a.f1 == 123).ToString());
        }
        public void TestCqlNullValuesLinqSupport()
        {
            var table = SessionExtensions.GetTable <LinqDecoratedEntity>(GetSession((_, __) => {}));

            Assert.AreEqual(
                @"INSERT INTO ""x_t"" (""x_pk"", ""x_ck1"", ""x_ck2"", ""x_f1"") VALUES (?, ?, ?, ?)",
                (table.Insert(new LinqDecoratedEntity()
            {
                ck1 = null, ck2 = 2, f1 = 3, pk = "x"
            })).ToString());

            Assert.AreEqual(
                @"UPDATE ""x_t"" SET ""x_f1"" = ? WHERE ""x_ck1"" IN ?",
                (from ent in table where new int?[] { 10, 30, 40 }.Contains(ent.ck1) select new { f1 = 1223 }).Update().ToString());

            Assert.AreEqual(
                @"UPDATE ""x_t"" SET ""x_f1"" = ?, ""x_ck1"" = ? WHERE ""x_ck1"" IN ?",
                (from ent in table where new int?[] { 10, 30, 40 }.Contains(ent.ck1) select new LinqDecoratedEntity()
            {
                f1 = 1223, ck1 = null
            }).Update().ToString());

            Assert.AreEqual(
                @"UPDATE ""x_t"" SET ""x_f1"" = ?, ""x_ck1"" = ? WHERE ""x_ck1"" = ?",
                (from ent in table where ent.ck1 == 1 select new LinqDecoratedEntity()
            {
                f1 = 1223, ck1 = null
            }).Update().ToString());

            Assert.AreEqual(
                @"UPDATE ""x_t"" SET ""x_f1"" = ?, ""x_ck1"" = ? WHERE ""x_ck1"" IN ? IF ""x_f1"" = ?",
                (from ent in table where new int?[] { 10, 30, 40 }.Contains(ent.ck1) select new { f1 = 1223, ck1 = (int?)null }).UpdateIf((a) => a.f1 == 123).ToString());
        }
        public void CreateTableCounterTest()
        {
            var actualCqlQueries = new List <string>();
            var sessionMock      = new Mock <ISession>(MockBehavior.Strict);
            var config           = new Configuration();
            var metadata         = new Metadata(config);
            var ccMock           = new Mock <IControlConnection>(MockBehavior.Strict);

            ccMock.Setup(cc => cc.Serializer).Returns(new Serializer(ProtocolVersion.MaxSupported));
            metadata.ControlConnection = ccMock.Object;
            var clusterMock = new Mock <ICluster>();

            clusterMock.Setup(c => c.Metadata).Returns(metadata);
            clusterMock.Setup(c => c.Configuration).Returns(config);
            sessionMock.Setup(s => s.Cluster).Returns(clusterMock.Object);
            sessionMock
            .Setup(s => s.Execute(It.IsAny <string>()))
            .Returns(() => new RowSet())
            .Callback <string>(actualCqlQueries.Add)
            .Verifiable();

            var session = sessionMock.Object;
            var table1  = SessionExtensions.GetTable <CounterTestTable1>(session);

            table1.CreateIfNotExists();

            var table2 = SessionExtensions.GetTable <CounterTestTable2>(session);

            table2.CreateIfNotExists();

            sessionMock.Verify();
            Assert.Greater(actualCqlQueries.Count, 0);
            Assert.AreEqual("CREATE TABLE \"CounterTestTable1\" (\"RowKey1\" int, \"RowKey2\" int, \"Value\" counter, PRIMARY KEY (\"RowKey1\", \"RowKey2\"))", actualCqlQueries[0]);
            Assert.AreEqual("CREATE TABLE \"CounterTestTable2\" (\"RowKey1\" int, \"RowKey2\" int, \"CKey1\" int, \"Value\" counter, PRIMARY KEY ((\"RowKey1\", \"RowKey2\"), \"CKey1\"))", actualCqlQueries[1]);
        }
        public void Select_OrderBy_Columns()
        {
            var table = SessionExtensions.GetTable <AllTypesEntity>(GetSession((_, __) => {}));
            var query = table.OrderBy(t => t.UuidValue).OrderByDescending(t => t.DateTimeValue);

            Assert.AreEqual(@"SELECT ""BooleanValue"", ""DateTimeValue"", ""DecimalValue"", ""DoubleValue"", ""Int64Value"", ""IntValue"", ""StringValue"", ""UuidValue"" FROM ""AllTypesEntity"" ORDER BY ""UuidValue"", ""DateTimeValue"" DESC", query.ToString());
        }
        public void LinqGeneratedUpdateStatementTest()
        {
            var    table = SessionExtensions.GetTable <AllTypesEntity>(GetSession((_, __) => {}));
            string query;
            string expectedQuery;

            query = table
                    .Where(r => r.StringValue == "key")
                    .Select(r => new AllTypesEntity()
            {
                IntValue = 1
            })
                    .Update()
                    .ToString();
            expectedQuery = "UPDATE \"AllTypesEntity\" SET \"IntValue\" = ? WHERE \"StringValue\" = ?";
            Assert.AreEqual(expectedQuery, query);

            Assert.Throws <CqlArgumentException>(() =>
            {
                //Update without a set statement
                //Must include SELECT to project to a new form
                query = table
                        .Where(r => r.StringValue == "key")
                        .Update()
                        .ToString();
            });
        }
        public void Select_One_Columns()
        {
            var table = SessionExtensions.GetTable <LinqDecoratedEntity>(GetSession((_, __) => {}));
            var query = table.Select(t => t.f1);

            Assert.AreEqual(@"SELECT ""x_f1"" FROM ""x_t"" ALLOW FILTERING", query.ToString());
        }
        public void LinqGeneratedUpdateStatementForCounterTest()
        {
            var table = SessionExtensions.GetTable <CounterTestTable1>(GetSession((_, __) => {}));
            var query = table
                        .Where(r => r.RowKey1 == 5 && r.RowKey2 == 6)
                        .Select(r => new CounterTestTable1()
            {
                Value = 2
            })
                        .Update()
                        .ToString();

            Assert.AreEqual("UPDATE \"CounterTestTable1\" SET \"Value\" = \"Value\" + ? WHERE \"RowKey1\" = ? AND \"RowKey2\" = ?", query);
            int x = 4;

            query = table
                    .Where(r => r.RowKey1 == 5 && r.RowKey2 == 6)
                    .Select(r => new CounterTestTable1()
            {
                Value = x
            })
                    .Update()
                    .ToString();
            Assert.AreEqual("UPDATE \"CounterTestTable1\" SET \"Value\" = \"Value\" + ? WHERE \"RowKey1\" = ? AND \"RowKey2\" = ?", query);
        }
        public void CreateTableCounterTest()
        {
            var actualCqlQueries = new List <string>();
            var sessionMock      = new Mock <ISession>();

            sessionMock
            .Setup(s => s.Execute(It.IsAny <string>()))
            .Returns(() => new RowSet())
            .Callback <string>(q => actualCqlQueries.Add(q))
            .Verifiable();

            var session = sessionMock.Object;
            var table1  = SessionExtensions.GetTable <CounterTestTable1>(session);

            table1.CreateIfNotExists();

            var table2 = SessionExtensions.GetTable <CounterTestTable2>(session);

            table2.CreateIfNotExists();

            sessionMock.Verify();
            Assert.Greater(actualCqlQueries.Count, 0);
            Assert.AreEqual("CREATE TABLE \"CounterTestTable1\"(\"RowKey1\" int, \"RowKey2\" int, \"Value\" counter, PRIMARY KEY(\"RowKey1\", \"RowKey2\"));", actualCqlQueries[0]);
            Assert.AreEqual("CREATE TABLE \"CounterTestTable2\"(\"RowKey1\" int, \"RowKey2\" int, \"CKey1\" int, \"Value\" counter, PRIMARY KEY((\"RowKey1\", \"RowKey2\"), \"CKey1\"));", actualCqlQueries[1]);
        }
Esempio n. 10
0
        protected void InitTest(IUserAuthRepository userAuthRepository)
        {
            ((IClearable)userAuthRepository).Clear();

            var appsettingsMock = new Mock <IAppSettings>();
            var appSettings     = appsettingsMock.Object;

            new AuthFeature(null, new IAuthProvider[] {
                new CredentialsAuthProvider(),
                new BasicAuthProvider(),
                new FacebookAuthProvider(appSettings),
                new TwitterAuthProvider(appSettings)
            })
            .Register(null);

            mockService = new Mock <IServiceBase>();
            mockService.Expect(x => x.TryResolve <IAuthRepository>()).Returns(userAuthRepository);
            requestContext = new BasicRequest {
                Headers =
                {
                    { "X-ss-id", SessionExtensions.CreateRandomSessionId() }
                }
            };
            mockService.Expect(x => x.Request).Returns(requestContext);
            service = mockService.Object;

            RegisterDto = new Register {
                UserName    = "******",
                Password    = "******",
                Email       = "*****@*****.**",
                DisplayName = "DisplayName",
                FirstName   = "FirstName",
                LastName    = "LastName",
            };
        }
Esempio n. 11
0
        public void EmptyListTest()
        {
            var table = SessionExtensions.GetTable <LinqDecoratedEntity>(GetSession((_, __) => {}));
            var keys  = new string[0];
            var query = table.Where(item => keys.Contains(item.pk));

            Assert.True(query.ToString().Contains("\"x_pk\" IN ?"), "The query must contain an empty IN statement");
        }
Esempio n. 12
0
        public virtual string CreateApiKey(string environment, string keyType, int sizeBytes)
        {
            if (CachedBytes == null)
                CachedBytes = new byte[sizeBytes];

            SessionExtensions.PopulateWithSecureRandomBytes(CachedBytes);
            return CachedBytes.ToBase64UrlSafe();
        }
        public void EmptyListTest()
        {
            var table = SessionExtensions.GetTable <TestTable>(null);
            var keys  = new string[0];
            var query = table.Where(item => keys.Contains(item.pk));

            Assert.True(query.ToString().Contains("\"x_pk\" IN ()"), "The query must contain an empty IN statement");
        }
Esempio n. 14
0
        public void Select_Count()
        {
            var table = SessionExtensions.GetTable <LinqDecoratedEntity>(GetSession((_, __) => {}));

            Assert.AreEqual(
                (from ent in table select ent).Count().ToString(),
                @"SELECT count(*) FROM ""x_t"" ALLOW FILTERING");
        }
        public void Deprecated_EntryPoint_Defaults_To_LinqBasedAttributes()
        {
            var table = SessionExtensions.GetTable <AllTypesEntity>(null);

            Assert.AreEqual(
                @"SELECT ""BooleanValue"", ""DateTimeValue"", ""DecimalValue"", ""DoubleValue"", ""Int64Value"", ""IntValue"", ""StringValue"", ""UuidValue"" FROM ""AllTypesEntity""",
                table.ToString());
        }
Esempio n. 16
0
        public void Select_Where_Contains()
        {
            var table = SessionExtensions.GetTable <AllTypesDecorated>(null);
            var ids   = new [] { 1, 2, 3 };
            var query = table.Where(t => ids.Contains(t.IntValue) && t.Int64Value == 10);

            Assert.AreEqual(@"SELECT * FROM ""atd"" WHERE ""int_VALUE"" IN (?, ?, ?) AND ""int64_VALUE"" = ?", query.ToString());
        }
        public IActionResult GenerateInvoice()
        {
            string json = SessionExtensions.GetRawJSON(HttpContext.Session, "Cart");

            new CartInfoSender().SendMessage(json);
            HttpContext.Session.Clear();
            return(View("InvoiceGenerated"));
        }
Esempio n. 18
0
        public void Select_Count()
        {
            var table = SessionExtensions.GetTable <LinqDecoratedEntity>(null);

            Assert.AreEqual(
                (from ent in table select ent).Count().ToString(),
                @"SELECT count(*) FROM ""x_t""");
        }
Esempio n. 19
0
            public override Task ProcessRequestAsync(IRequest req, IResponse res, string operationName)
            {
                res.ContentType = MimeTypes.ServerSentEvents;
                res.AddHeader(HttpHeaders.CacheControl, "no-cache");
                res.KeepAlive = true;
                res.Flush();

                IAuthSession session    = req.GetSession();
                var          userAuthId = session != null ? session.UserAuthId : null;
                var          feature    = HostContext.GetPlugin <SimpleServerEventsFeature>();

                //var now = DateTime.UtcNow;
                var subscriptionId = SessionExtensions.CreateRandomSessionId();
                var eventClient    = new EventClient(res)
                {
                    SubscriptionId = subscriptionId,     // A session can have multiple subscriptions / clients
                };

                if (feature.OnCreated != null)
                {
                    feature.OnCreated(eventClient, req);
                }

                //var heartbeatUrl = req.ResolveAbsoluteUrl("~/".CombineWith(feature.HeartbeatPath))
                //    .AddQueryParam("id", subscriptionId);

                var privateArgs = new Dictionary <string, string>(eventClient.Meta)
                {
                    { "id", subscriptionId },
                    //{"heartbeatUrl", heartbeatUrl},
                    //{"heartbeatIntervalMs", ((long)feature.HeartbeatInterval.TotalMilliseconds).ToString(CultureInfo.InvariantCulture) }
                };

                // Register the client
                req.TryResolve <IServerEventsBroker>().Connect(eventClient);

                if (feature.OnConnected != null)
                {
                    feature.OnConnected(eventClient, privateArgs);
                }

                // Welcome our new client
                res.OutputStream.Write(": " + subscriptionId + " connected\n\n");     // Write initial stream so the client knows we're alive
                res.Flush();
                var tcs = new TaskCompletionSource <bool>();

                eventClient.OnDispose = client =>
                {
                    try
                    {
                        res.EndHttpHandlerRequest(skipHeaders: true);
                    }
                    catch { }
                    tcs.SetResult(true);
                };

                return(tcs.Task);
            }
Esempio n. 20
0
        public IActionResult Remove(int id)
        {
            List <Cart> cart  = SessionExtensions.GetComplexData <List <Cart> >(HttpContext.Session, "cart");
            int         index = isExist(id);

            cart.RemoveAt(index);
            SessionExtensions.SetComplexData(HttpContext.Session, "cart", cart);
            return(RedirectToAction("Index"));
        }
        private static string GetRandomFilename(string folder = "")
        {
            if (!folder.IsNullOrEmpty() && !folder.EndsWith("/"))
            {
                folder = folder + '/';
            }

            return($"{folder}{SessionExtensions.CreateRandomBase62Id(24)}.png");
        }
Esempio n. 22
0
 private void CheckNullSession()
 {
     if (SessionExtensions.GetObjectFromJson <List <Item> >(HttpContext.Session, "cart") == null)
     {
         SessionExtensions.SetObjectAsJson <List <Item> >(HttpContext.Session, "cart", new List <Item>()
         {
         });
     }
 }
Esempio n. 23
0
 public ActionResult RemoveSession(string sessionguid)
 {
     if (SessionExtensions.ContainsKey(sessionguid))
     {
         TaskList.Remove(sessionguid);
         return(new HttpStatusCodeResult(HttpStatusCode.OK, "Multiplayer session was removed from the tasklist."));
     }
     return(new HttpStatusCodeResult(HttpStatusCode.NotFound, "Session not found."));
 }
        public void Deprecated_EntryPoint_Honors_Mapping_Defined()
        {
            MappingConfiguration.Global.Define(new Map <AllTypesEntity>().TableName("tbl1"));
            var table = SessionExtensions.GetTable <AllTypesEntity>(null);

            Assert.AreEqual(
                @"SELECT BooleanValue, DateTimeValue, DecimalValue, DoubleValue, Int64Value, IntValue, StringValue, UuidValue FROM tbl1",
                table.ToString());
        }
        public void Deprecated_EntryPoint_Uses_Keyspace_Provided()
        {
            MappingConfiguration.Global.Define(new Map <AllTypesEntity>().TableName("tbl1"));
            var table = SessionExtensions.GetTable <AllTypesEntity>(null, "linqTable", "linqKs");

            Assert.AreEqual(
                @"SELECT BooleanValue, DateTimeValue, DecimalValue, DoubleValue, Int64Value, IntValue, StringValue, UuidValue FROM linqKs.linqTable",
                table.ToString());
        }
Esempio n. 26
0
        public IActionResult Remove(int id)
        {
            List <ItemOrder> cart = SessionExtensions.Get <List <ItemOrder> >(HttpContext.Session, "cart");
            int index             = isExist(id);

            cart.RemoveAt(index);
            SessionExtensions.Set(HttpContext.Session, "cart", cart);
            return(RedirectToAction("Index"));
        }
Esempio n. 27
0
        public void Select_Specific_Columns()
        {
            var table = SessionExtensions.GetTable <LinqDecoratedEntity>(GetSession((_, __) => {}));
            var query = table.Select(t => new LinqDecoratedEntity {
                f1 = t.f1, pk = t.pk
            });

            Assert.AreEqual(@"SELECT ""x_f1"", ""x_pk"" FROM ""x_t"" ALLOW FILTERING", query.ToString());
        }
Esempio n. 28
0
        public IActionResult dRemove(int id)
        {
            List <DailyDealOrder> dcart = SessionExtensions.Get <List <DailyDealOrder> >(HttpContext.Session, "dcart");
            int index = disExist(id);

            dcart.RemoveAt(index);
            SessionExtensions.Set(HttpContext.Session, "dcart", dcart);
            return(RedirectToAction("Index"));
        }
 public void Does_CreateRandomSessionId_without_url_unfriendly_chars()
 {
     1000.Times(i =>
     {
         var sessionId = SessionExtensions.CreateRandomSessionId();
         Assert.That(sessionId, Does.Not.Contain("+"));
         Assert.That(sessionId, Does.Not.Contain("/"));
     });
 }
Esempio n. 30
0
        // GET: PublisherDashboard
        public IActionResult Index()
        {
            PublisherProfile publisherProfile = _context.PublisherProfiles
                                                .Include(pp => pp.User)
                                                .Where(pp => pp.UserId == SessionExtensions.GetInt32(HttpContext.Session, "UserId"))
                                                .FirstOrDefault();

            return(View(publisherProfile));
        }