Exemplo n.º 1
0
        public OperationResult <Order> PlaceOrder(Cart cart)
        {
            const int MAX_RETRY = 10;

            if (cart == null)
            {
                throw new ArgumentNullException("cart");
            }

            Dictionary <string, string> customerInfo = new Dictionary <string, string>();

            customerInfo.Add("Email", cart.Customer.Email);
            customerInfo.Add("Phone", cart.Customer.Phone);
            customerInfo.Add("Address", cart.Customer.Address);
            customerInfo.Add("CodeID", cart.Customer.Id.ToString());
            //customerInfo.Add("Name", cart.Customer.Email);

            cart.Order.Esnecils = new List <Esnecil>();
            foreach (ProductPrice productPrice in cart.ProductPrices)
            {
                RawEsnecil rawEsnecil = _esnecilGenerator.GenerateLicense(customerInfo);
                Esnecil    esnecil    = rawEsnecil.ToEsnecil();
                esnecil.ProductPriceId = productPrice.Id;
                cart.Order.Esnecils.Add(esnecil);
            }

            for (int i = 1; i <= MAX_RETRY; i++)
            {
                try
                {
                    Invoice invoice = _invoiceManager.GetNextInvoiceNo();
                    cart.Order.InvoiceNo = invoice.InvoiceNo;
                    cart.Order.SerialNo  = invoice.SerialNo;

                    _repository.Add(cart.Order);
                    _repository.Save();

                    break;
                }
                catch (Exception ex)
                {
                    if (ex.Message.Contains("Violation of UNIQUE KEY constraint"))
                    {
                        if (i == MAX_RETRY)
                        {
                            throw new Exception("Violation of UNIQUE KEY constraint. Cannot insert duplicate key in object. The statement has been terminated. Please try again.");
                        }
                    }
                    else
                    {
                        throw;
                    }
                }
            }

            return(new OperationResult <Order>(true)
            {
                Entity = cart.Order
            });
        }
Exemplo n.º 2
0
        public void GenerateLicense_Should_GenerateEsnecilSerialNoAndCode_WhenValidGeneratorFileAndCustomerInfoIsSet()
        {
            //Dictionary<string, string> customerInfo = new Dictionary<string, string>();
            //customerInfo.Add("Email", "*****@*****.**");
            //customerInfo.Add("Name", "Akuabata Egenti");
            //customerInfo.Add("Phone", "09087651122");
            //customerInfo.Add("Address", "99 Opebi road, Ikeja Lagos");
            //customerInfo.Add("CodeID", "109930");

            Dictionary <string, string> customerInfo = new Dictionary <string, string>
            {
                { "Email", "*****@*****.**" },
                { "Name", "Akuabata Egenti" },
                { "Phone", "09087651122" },
                { "Address", "99 Opebi road, Ikeja Lagos" },
                { "CodeID", "109930" }
            };

            //var discountsDictionary = new Dictionary<AccountStatus, IAccountDiscountCalculator>
            //  {
            //    {AccountStatus.NotRegistered, new NotRegisteredDiscountCalculator()},
            //    {AccountStatus.SimpleCustomer, new SimpleCustomerDiscountCalculator()},
            //    {AccountStatus.ValuableCustomer, new ValuableCustomerDiscountCalculator()},
            //    {AccountStatus.MostValuableCustomer, new MostValuableCustomerDiscountCalculator()}
            //};

            IEsnecilGeneratorResource esnecilGeneratorFile = new EsnecilGeneratorFile();
            IEsnecilGeneratorFactory  generatorFactory     = new EsnecilGeneratorFactory(esnecilGeneratorFile);
            EsnecilGeneratorBase      generator            = generatorFactory.Create(EsnecilType.Trial);
            RawEsnecil esnecil = generator.GenerateLicense(customerInfo);

            //RawEsnecil esnecil = generator.GenerateLicense(filePath, customerInfo);

            Assert.NotNull(esnecil);
            Assert.NotNull(esnecil.SerialCode);
            Assert.NotNull(esnecil.EsnecilCode);
            Assert.True(esnecil.GeneratedOn.Date == DateTime.Today.Date);
            Assert.True(esnecil.SerialCode.Length > 5);
            Assert.True(esnecil.EsnecilCode.Length > 5);
            Assert.True(esnecil.DetectDateRollback);
            Assert.True(esnecil.EnableTamperChecking);
            Assert.Equal(1, esnecil.NoOfUsers);
        }