コード例 #1
0
 public void SetThreeYearOld()
 {
     TakeScreenshotWhenTestFailed(() =>
     {
         MainPage mainPage = new MainPage(Driver)
                             .FillInPickUpFields(CreatingOrder.PickUpFields())
                             .clickOnAgeCheckBox()
                             .InsertValueInAgeInput("3")
                             .SubmitInformation();
         Assert.AreEqual("НЕ КОРРЕКТНЫЙ ВОЗРАСТ", mainPage.errorMessage);
     });
 }
コード例 #2
0
        public void RentCarWithEmptyReturnFields()
        {
            TakeScreenshotWhenTestFailed(() =>
            {
                MainPage mainPage = new MainPage(Driver)
                                    .FillInPickUpFields(CreatingOrder.PickUpFields())
                                    .clickOnReturnPlaceCheckBox()
                                    .SubmitInformation();

                Assert.AreEqual("НЕ ОСТАВЛЯЙТЕ ПОЛЯ ДЛЯ ЗАПОЛНЕНИЯ ПУСТЫМИ", mainPage.errorMessage);
            });
        }
コード例 #3
0
        public void CheckAge()
        {
            TakeScreenshotWhenTestFailed(() =>
            {
                MainPage mainPage = new MainPage(Driver)
                                    .FillInPickUpFields(CreatingOrder.PickUpFields())
                                    .clickOnAgeCheckBox()
                                    .SubmitInformation();

                Assert.AreEqual("ВОЗРАСТ ВОДИТЕЛЯ", mainPage.errorMessage);
            });
        }
        public void CreateOrder(CreatingOrder order)
        {
            using (var connection = factory.CreateConnection())
            {
                connection.ConnectionString = connectionString;
                var command = connection.CreateCommand();
                command.CommandText =
                    "INSERT INTO Northwind.Orders (CustomerID, EmployeeID" +
                    ", OrderDate, ShippedDate, RequiredDate" +
                    ", ShipName, ShipAddress, ShipCity" +
                    ", ShipRegion, ShipPostalCode, ShipCountry) " +
                    "SELECT @custId, @empId " +
                    ", @ordDate, @shipDate, @reqDate" +
                    ", c.CompanyName, c.Address, c.City" +
                    ", c.Region, c.PostalCode, c.Country " +
                    "FROM Northwind.Customers AS c " +
                    "WHERE c.CustomerID = @custId; ";

                var custId = command.CreateParameter();
                custId.ParameterName = "@custId";
                custId.DbType        = DbType.String;
                custId.Value         = order.CustomerID;

                var empId = command.CreateParameter();
                empId.ParameterName = "@empId";
                empId.DbType        = DbType.Int32;
                empId.Value         = order.EmployeeID;

                var ordDate = command.CreateParameter();
                ordDate.ParameterName = "@ordDate";
                ordDate.DbType        = DbType.DateTime;
                ordDate.Value         = order.OrderDate;

                var shipDate = command.CreateParameter();
                shipDate.ParameterName = "@shipDate";
                shipDate.DbType        = DbType.DateTime;
                shipDate.Value         = order.ShippedDate;

                var reqDate = command.CreateParameter();
                reqDate.ParameterName = "@reqDate";
                reqDate.DbType        = DbType.DateTime;
                reqDate.Value         = order.RequiredDate;

                command.Parameters.AddRange(new[] { custId, empId, ordDate, shipDate, reqDate });
                connection.Open();
                command.ExecuteNonQuery();
            }
        }
        public void UpdateOrder(CreatingOrder order)
        {
            using (var connection = factory.CreateConnection())
            {
                connection.ConnectionString = connectionString;
                var command = connection.CreateCommand();
                command.CommandText =
                    "UPDATE Northwind.Orders " +
                    "SET CustomerID = @custId, EmployeeID = @empId, " +
                    "OrderDate = @ordDate, ShippedDate = @shipDate, RequiredDate = @reqDate " +
                    "WHERE OrderID = @orderId ";

                var custId = command.CreateParameter();
                custId.ParameterName = "@custId";
                custId.DbType        = DbType.String;
                custId.Value         = order.CustomerID;

                var empId = command.CreateParameter();
                empId.ParameterName = "@empId";
                empId.DbType        = DbType.Int32;
                empId.Value         = order.EmployeeID;

                var orderId = command.CreateParameter();
                orderId.ParameterName = "@orderId";
                orderId.DbType        = DbType.Int32;
                orderId.Value         = order.OrderID;

                var ordDate = command.CreateParameter();
                ordDate.ParameterName = "@ordDate";
                ordDate.DbType        = DbType.DateTime;
                ordDate.Value         = order.OrderDate;

                var shipDate = command.CreateParameter();
                shipDate.ParameterName = "@shipDate";
                shipDate.DbType        = DbType.DateTime;
                shipDate.Value         = order.ShippedDate;

                var reqDate = command.CreateParameter();
                reqDate.ParameterName = "@reqDate";
                reqDate.DbType        = DbType.DateTime;
                reqDate.Value         = order.RequiredDate;

                command.Parameters.AddRange(new[] { orderId, custId, empId, ordDate, shipDate, reqDate });
                connection.Open();
                command.ExecuteNonQuery();
            }
        }
        public void OrderCreating()
        {
            var order = new CreatingOrder()
            {
                CustomerID = "QUICK",
                EmployeeID = 1,
            };

            int orderId = repo.CreateOrder(order);
            var orders  = new List <CreatingOrder>();

            using (var connection = factory.CreateConnection())
            {
                connection.ConnectionString = connectionString;
                var command = connection.CreateCommand();
                command.CommandText =
                    "SELECT o.CustomerID, o.EmployeeID " +
                    "FROM Northwind.Orders AS o " +
                    "WHERE o.OrderID = " + orderId;

                connection.Open();

                using (IDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        orders.Add(new CreatingOrder()
                        {
                            CustomerID = (string)reader["CustomerID"],
                            EmployeeID = (int)reader["EmployeeID"]
                        });
                    }
                }

                command.CommandText =
                    "DELETE FROM Northwind.Orders " +
                    "WHERE OrderID = " + orderId;

                command.ExecuteNonQuery();
            }

            Assert.AreEqual(orders.Count, 1, "Неверное количество созданных элементов!");
            Assert.AreEqual(orders[0].CustomerID, order.CustomerID, "Получен неверный CustomerID");
            Assert.AreEqual(orders[0].EmployeeID, order.EmployeeID, "Получен неверный EmployeeID");
        }
        public int CreateOrder(CreatingOrder order)
        {
            using (var connection = factory.CreateConnection())
            {
                connection.ConnectionString = connectionString;
                var command = connection.CreateCommand();
                command.CommandText =
                    "INSERT INTO Northwind.Orders (CustomerID, EmployeeID" +
                    ", ShipName, ShipAddress, ShipCity" +
                    ", ShipRegion, ShipPostalCode, ShipCountry) " +
                    "SELECT @custId, @empId " +
                    ", c.CompanyName, c.Address, c.City" +
                    ", c.Region, c.PostalCode, c.Country " +
                    "FROM Northwind.Customers AS c " +
                    "WHERE c.CustomerID = @custId; " +
                    "SELECT CONVERT(int, SCOPE_IDENTITY()); ";

                var custId = command.CreateParameter();
                custId.ParameterName = "@custId";
                custId.DbType        = DbType.String;
                custId.Value         = order.CustomerID;

                var empId = command.CreateParameter();
                empId.ParameterName = "@empId";
                empId.DbType        = DbType.Int32;
                empId.Value         = order.EmployeeID;

                command.Parameters.AddRange(new[] { custId, empId });
                connection.Open();

                try
                {
                    return((int)command.ExecuteScalar());
                }
                catch                        //todo pn не нужно перехватывать все исключительные ситуации. лучше перехватить SQLException
                {
                    return(DefaultIntValue); //todo pn немного странная логика, если у нас что-то пошло не так и запись не создалась, для чего нам возвращать ИД? Лучше пусть выбросится исключение, которое мы обработаем не здесь, а на уровень выше.
                }
            }
        }