Esempio n. 1
0
        public void TestCreateCurrency()
        {
            var userID = new Random().Next(1, 10);
            var values = Enum.GetValues(typeof(CurrencyType));
            var randomNum = new Random().Next(1, values.Length);
            var currency = default(Currency);
            var currencyID = 0;
            while (true)
            {
                currencyID = (int)values.GetValue(randomNum);
                var currencyCode = values.GetValue(randomNum).ToString();
                currency = IoC.Resolve<IRepository>().FindById<Currency>(currencyID);
                var createCommand = new CreateCurrency(currencyID, currencyCode, currencyCode, userID);

                if (currency == null)
                {
                    Assert.DoesNotThrow(() =>
                    {
                        this.commandBus.Send(createCommand);
                    });
                    break;
                }
            }

            var savedCurrency = IoC.Resolve<IRepository>().FindById<Currency>(currencyID);

            Assert.NotNull(savedCurrency);
        }
Esempio n. 2
0
        public ActionResult Create(CurrencyCreateModel currency)
        {
            currency.Code = Enum.Parse(typeof(CurrencyType), currency.CurrencyID.ToString()).ToString();
            var existResult = IoC.Resolve<ICurrencyQuery>().ExistCurrency(currency.Code, currency.Name);

            if (existResult.Item1) return Json(new JsonResult(-1));
            if (existResult.Item2) return Json(new JsonResult(-2));

            try
            {
                var cmd = new CreateCurrency(currency.CurrencyID, currency.Code, currency.Name, this.CurrentUser.UserID);
                this.CommandBus.Send(cmd);

                return Json(JsonResult.Success);
            }
            catch (CommandExecutionException ex)
            {
                return Json(new JsonResult(ex.ErrorCode));
            }
        }
Esempio n. 3
0
        private Currency GetOneCurrency()
        {
            var userID = new Random().Next(1, 10);
            var values = Enum.GetValues(typeof(CurrencyType));
            var randomNum = new Random().Next(1, values.Length);
            var currency = default(Currency);

            randomNum = new Random().Next(1, values.Length);

            var currencyID = (int)values.GetValue(randomNum);
            var currencyCode = values.GetValue(randomNum).ToString();
            currency = IoC.Resolve<IRepository>().FindById<Currency>(currencyID);
            if (currency == null)
            {
                var createCommand = new CreateCurrency(currencyID, currencyCode, currencyCode, userID);
                this.commandBus.Send(createCommand);
                currency = IoC.Resolve<IRepository>().FindById<Currency>(currencyID);
            }
            return currency;
        }