예제 #1
0
        /// <summary>
        /// Convert a DbCustomer into a domain Customer
        /// </summary>
        public static Customer FromDbCustomer(DbCustomer sqlCustomer)
        {
            if (sqlCustomer == null)
            {
                return null;
            }

            var id = CustomerId.Create(sqlCustomer.Id);
            var name = PersonalName.Create(sqlCustomer.FirstName, sqlCustomer.LastName);
            var email = EmailAddress.Create(sqlCustomer.Email);
            var cust = Customer.Create(id, name, email);
            return cust;
        }
        public void Update(DbCustomer customer)
        {
            if (!Data.ContainsKey(customer.Id))
            {
                // Emulate a SQL error
                throw new SqlException("KeyNotFound");
            }

            // use the customer id to trigger some special cases
            switch (customer.Id)
            {
                case 42:
                    // Emulate a SQL error
                    throw new SqlException("Timeout");
                default:
                    Data[customer.Id] = customer;
                    break;
            }
        }
        public void Insert(DbCustomer customer)
        {
            if (Data.ContainsKey(customer.Id))
            {
                // Emulate a SQL error
                throw new SqlException("DuplicateKey");
            }

            // use the customer id to trigger some special cases
            switch (customer.Id)
            {
            case 42:
                // Emulate a SQL error
                throw new SqlException("Timeout");

            default:
                Data[customer.Id] = customer;
                break;
            }
        }
예제 #4
0
        public void Update(DbCustomer customer)
        {
            if (!Data.ContainsKey(customer.Id))
            {
                // Emulate a SQL error
                throw new SqlException("KNF"); //KeyNotFound
            }

            // use the customer id to trigger some special cases
            switch (customer.Id)
            {
                case 42:
                    // Emulate a SQL error
                    throw new SqlException("TO"); // Timeout
                case 43:
                    // Emulate a SQL error
                    throw new SqlException("AE");  // AuthenticationError
                default:
                    Data[customer.Id] = customer;
                    break;
            }
        }
예제 #5
0
파일: DbContext.cs 프로젝트: vietnt/Katas
        public void Update(DbCustomer customer)
        {
            if (!Data.ContainsKey(customer.Id))
            {
                // Emulate a SQL error
                throw new SqlException("KNF"); //KeyNotFound
            }

            // use the customer id to trigger some special cases
            switch (customer.Id)
            {
            case 42:
                // Emulate a SQL error
                throw new SqlException("TO");     // Timeout

            case 43:
                // Emulate a SQL error
                throw new SqlException("AE");      // AuthenticationError

            default:
                Data[customer.Id] = customer;
                break;
            }
        }