Ejemplo n.º 1
0
        private void AssertThatEventSavedToTable(string tableName)
        {
            var sql = $"SELECT COUNT(*) FROM {tableName} WHERE Id = '{_testEvent.Id}'";

            _logger.Debug(sql);
            var numberOfEventsInserted =
                _sqlExecutor.ExecuteScalar <int>(sql);

            Assert.That(numberOfEventsInserted, Is.EqualTo(1));
        }
Ejemplo n.º 2
0
        private void AssertCreated(Guid id)
        {
            var createdDate = _sqlExecutor.ExecuteScalar <DateTime>($"SELECT Created FROM dbo.EventsToPublish WHERE Id = '{id}'");
            var tolerance   = new TimeSpan(0, 0, 5);

            Assert.That(createdDate, Is.EqualTo(DateTime.Now).Within(tolerance));
        }
    private static bool CheckCount(bool isFailed, List <object> failures, int restartCount, string serviceName, string host, StringBuilder builder, int maxCount, string name, string failedMessage, string query)
    {
        int  result = (int)SqlExecutor.ExecuteScalar(LoginUser.Anonymous, query);
        bool isBad  = false;

        if (result > maxCount)
        {
            isBad = true;
            AddQueryRow(builder, name, false, maxCount, result, failedMessage);
            string message = string.Format("Service: {0} ({1}) records - {2}", name, result.ToString(), failedMessage);
            SendMessageToSlack(message);
        }
        else
        {
            string message = failedMessage;
            AddQueryRow(builder, name, true, maxCount, result, "");
        }

        if (result > restartCount)
        {
            failures.Add(GetServiceObject(serviceName, host));
        }


        return(isFailed || isBad);
    }
Ejemplo n.º 4
0
        private void AssertThatEventSavedInEventStore()
        {
            var numberOfEventsWithCurrentId =
                _sqlExecutor.ExecuteScalar <int>($"SELECT COUNT(*) FROM dbo.Events WHERE Id = '{_id}'");

            Assert.That(numberOfEventsWithCurrentId, Is.EqualTo(1));
        }
Ejemplo n.º 5
0
        private int GetCreatedCount(LoginUser loginUser)
        {
            SqlCommand command = new SqlCommand("SELECT COUNT(*) FROM Tasks WHERE CreatorID = @UserID AND UserID <> @UserID");

            command.Parameters.AddWithValue("UserID", loginUser.UserID);
            return((int)SqlExecutor.ExecuteScalar(loginUser, command));
        }
Ejemplo n.º 6
0
        public async Task TestExecuteScalar()
        {
            var result = await SqlExecutor.ExecuteScalar($"SELECT count(*) FROM customer");

            var expected = TpchData.Customers.Count;

            Assert.That(result, Is.EqualTo(expected));
        }
Ejemplo n.º 7
0
        public ValueTask <object> ExecuteScalar(string sql, SqlParameters sqlParameters, HttpContext httpContext)
        {
            CustomMetadataStore customMetadataStore = new CustomMetadataStore();

            return(_sqlExecutor.ExecuteScalar(sql, sqlParameters, new TableResolverData(
                                                  httpContext,
                                                  _serviceProvider,
                                                  customMetadataStore)));
        }
Ejemplo n.º 8
0
        private string GetImportID(int orgID)
        {
            SqlCommand command = new SqlCommand();

            command.CommandText = @"
        SELECT
          ImportID
        FROM
          OrgMoveEvent
        WHERE
          OrganizationID = @OrgID";
            command.Parameters.AddWithValue("OrgID", orgID);

            return(SqlExecutor.ExecuteScalar(GetCorrupteLoginUser(), command).ToString());
        }
Ejemplo n.º 9
0
        public async void AddTransactionAsync()
        {
            // arrange
            var serviceProvider = ServiceCreator.CreateServiceCollection();
            var transactionRepo = serviceProvider.GetService <ITransactionRepository>();
            var securityRepo    = serviceProvider.GetService <ISecurityRepository>();
            var portfolioRepo   = serviceProvider.GetService <IPortfolioRepository>();

            TransactionService transactionService = new TransactionService(transactionRepo, securityRepo, portfolioRepo);

            var sqlExecutor = new SqlExecutor();

            var portfolio = new Portfolio()
            {
                PortfolioName = Guid.NewGuid().ToString().Substring(1, 6)
            };

            // insert portfolio
            string sql = $"INSERT INTO Portfolio (PortfolioName) VALUES ({portfolio.PortfolioName})";

            portfolio.Id = (int)sqlExecutor.ExecuteScalar(sql);

            var transaction = new Transaction()
            {
                Action      = "Buy",
                Amount      = 200,
                Date        = DateTime.UtcNow,
                Description = "test",
                Fees        = 0,
                PortfolioId = portfolio.Id,
                Price       = 20,
                Quantity    = 10,
                Symbol      = "HD"
            };

            // act
            var result = await transactionService.AddTransactionAsync(transaction, portfolio.Id);

            // assert
            Assert.True(result);
        }
Ejemplo n.º 10
0
        public string GetPendoOptions()
        {
            LoginUser    loginUser = TSAuthentication.GetLoginUser();
            User         user      = Users.GetUser(loginUser, TSAuthentication.UserID);
            Organization org       = Organizations.GetOrganization(loginUser, TSAuthentication.OrganizationID);
            SqlCommand   command;
            DataTable    table;

            dynamic result = new ExpandoObject();

            result.apiKey              = SystemSettings.ReadString(loginUser, "PendoKey", "NO API IN SYSTEMSETTINGS");
            result.usePendoAgentAPI    = false;
            result.visitor             = new ExpandoObject();
            result.visitor.id          = user.UserID;
            result.visitor.email       = user.Email;
            result.visitor.role        = user.Title;
            result.visitor.name        = user.FirstLastName;
            result.visitor.dateCreated = user.DateCreated;
            //result.visitor.lastLogin =
            result.visitor.isAdmin = user.IsSystemAdmin;

            command = new SqlCommand("SELECT COUNT(*) FROM Tickets WHERE OrganizationID = @OrganizationID AND UserID = @UserID");
            command.Parameters.AddWithValue("UserID", user.UserID);
            command.Parameters.AddWithValue("OrganizationID", org.OrganizationID);
            result.visitor.assignedTickets = (int)SqlExecutor.ExecuteScalar(loginUser, command);

            command = new SqlCommand("SELECT COUNT(*) FROM Tickets WHERE OrganizationID = @OrganizationID AND CreatorID = @UserID");
            command.Parameters.AddWithValue("UserID", user.UserID);
            command.Parameters.AddWithValue("OrganizationID", org.OrganizationID);
            result.visitor.ticketsCreated = (int)SqlExecutor.ExecuteScalar(loginUser, command);

            command = new SqlCommand("SELECT COUNT(*) FROM Actions WHERE CreatorID = @UserID");
            command.Parameters.AddWithValue("UserID", user.UserID);
            //result.visitor.actionsCreated = (int)SqlExecutor.ExecuteScalar(loginUser, command);

            //result.visitor.groups =
            result.visitor.isChatUser = user.IsChatUser;

            result.account              = new ExpandoObject();
            result.account.id           = org.OrganizationID;
            result.account.name         = org.Name;
            result.account.planLevel    = org.UserSeats == 100 ? "Trial" : "Paying";
            result.account.creationDate = org.DateCreated;
            result.account.isActive     = org.IsActive;
            //result.account.lastLogin =
            result.account.seatCount  = org.UserSeats;
            result.account.apiEnabled = org.IsApiEnabled;
            command = new SqlCommand(
                @"SELECT COUNT(*) AS Cnt, TicketSource FROM Tickets 
                WHERE OrganizationID = @OrganizationID
                AND TicketSource IS NOT NULL
                AND TicketSource <> ''
                GROUP BY TicketSource
                ");
            command.Parameters.AddWithValue("OrganizationID", org.OrganizationID);
            table = SqlExecutor.ExecuteQuery(loginUser, command);
            result.account.ticketsCreatedByEmail       = 0;
            result.account.ticketsCreatedByFaceBook    = 0;
            result.account.ticketsCreatedByAgent       = 0;
            result.account.ticketsCreatedByForum       = 0;
            result.account.ticketsCreatedByWeb         = 0;
            result.account.ticketsCreatedByChatOffline = 0;
            result.account.ticketsCreatedByMobile      = 0;
            result.account.ticketsCreatedByChat        = 0;

            foreach (DataRow row in table.Rows)
            {
                try
                {
                    switch (row[1].ToString().ToLower())
                    {
                    case "forum": result.account.ticketsCreatedByForum = (int)row[0]; break;

                    case "agent": result.account.ticketsCreatedByAgent = (int)row[0]; break;

                    case "web": result.account.ticketsCreatedByWeb = (int)row[0]; break;

                    case "facebook": result.account.ticketsCreatedByFaceBook = (int)row[0]; break;

                    case "chatoffline": result.account.ticketsCreatedByChatOffline = (int)row[0]; break;

                    case "mobile": result.account.ticketsCreatedByMobile = (int)row[0]; break;

                    case "email": result.account.ticketsCreatedByEmail = (int)row[0]; break;

                    case "chat": result.account.ticketsCreatedByChat = (int)row[0]; break;

                    default:
                        break;
                    }
                }
                catch (Exception)
                {
                }
            }

            command = new SqlCommand("SELECT COUNT(*) FROM Tickets WHERE OrganizationID = @OrganizationID AND IsKnowledgeBase = 1");
            command.Parameters.AddWithValue("OrganizationID", org.OrganizationID);
            result.account.kbCount = (int)SqlExecutor.ExecuteScalar(loginUser, command);

            command = new SqlCommand("SELECT COUNT(*) FROM Tickets WHERE OrganizationID = @OrganizationID");
            command.Parameters.AddWithValue("OrganizationID", org.OrganizationID);
            result.account.ticketCount = (int)SqlExecutor.ExecuteScalar(loginUser, command);

            command = new SqlCommand("SELECT COUNT(*) FROM Organizations WHERE ParentID = @OrganizationID");
            command.Parameters.AddWithValue("OrganizationID", org.OrganizationID);
            result.account.customerCount = (int)SqlExecutor.ExecuteScalar(loginUser, command);

            command = new SqlCommand("SELECT COUNT(*) FROM CustomFields WHERE OrganizationID = @OrganizationID");
            command.Parameters.AddWithValue("OrganizationID", org.OrganizationID);
            result.account.customFieldCount = (int)SqlExecutor.ExecuteScalar(loginUser, command);

            command = new SqlCommand("SELECT COUNT(*) FROM Users WHERE OrganizationID = @OrganizationID AND MarkDeleted = 0");
            command.Parameters.AddWithValue("OrganizationID", org.OrganizationID);
            result.account.actualUsers = (int)SqlExecutor.ExecuteScalar(loginUser, command);

            command = new SqlCommand("SELECT COUNT(*) FROM Users WHERE OrganizationID = @OrganizationID AND IsSystemAdmin = 1 AND MarkDeleted = 0");
            command.Parameters.AddWithValue("OrganizationID", org.OrganizationID);
            result.account.adminCount = (int)SqlExecutor.ExecuteScalar(loginUser, command);

            command = new SqlCommand("SELECT COUNT(*) FROM Imports WHERE OrganizationID = @OrganizationID");
            command.Parameters.AddWithValue("OrganizationID", org.OrganizationID);
            result.account.importCount = (int)SqlExecutor.ExecuteScalar(loginUser, command);

            result.account.podName     = SystemSettings.GetPodName();
            result.account.productType = org.ProductType.ToString();
            return(JsonConvert.SerializeObject(result));
        }