public void AddNewAsset_ProductIsNull()
        {
            var product = new Product()
            {
                ProductSeq = 99
            };

            Action action = () => { assetRepository.AddNewAsset(product); };

            action.Should().Throw <DataNotFoundException>();

            dbConnection.Received().QueryableProducts.Any(p => p.ProductSeq == product.ProductSeq);
            dbConnection.DidNotReceive().QueryableAssets.Any(p => p.ProductSeq == product.ProductSeq);
            dbConnection.DidNotReceive().Modified(Arg.Is <Asset>(p => p.ProductSeq == product.ProductSeq), EntityState.Added);
            dbConnection.DidNotReceive().SaveChanges();
        }
Example #2
0
        /// <summary>
        /// 判斷買入流程
        /// 如為零股的話就更新現有零股資料累加上去
        /// 如零股累加後能湊成一張,就更新成一張再新增一筆零股資料
        /// </summary>
        /// <param name="product"></param>
        /// <param name="txViewModel">本次的交易資料</param>
        /// <param name="txRecord">傳入的現有零股資料供計算,更新零股交易才會傳值</param>
        private void CheckBuyReceived(Product product, TransactionViewModel txViewModel, TransactionRecord txRecord = null)
        {
            dbConnection.Received().QueryableTransactionRecords.FirstOrDefault(p => p.ProductSeq == txViewModel.ProductSeq && p.InStock < 1000);

            var isUpdateOddLotTx = txViewModel.Num < 1000 && txRecord != null;
            var updateNum        = isUpdateOddLotTx ? txRecord.Num + txViewModel.Num : txViewModel.Num;

            //判斷零股累加是否可湊成一張
            var totalOddLotNum = isUpdateOddLotTx ? txViewModel.Num + txRecord.InStock : 0;

            if (isUpdateOddLotTx && totalOddLotNum > 1000)
            {
                //拆成兩筆Transaction紀錄
                var remainderNum = totalOddLotNum % 1000;
                updateNum = txViewModel.Num - remainderNum;
                //餘數股票作新增
                dbConnection.Received().Modified(Arg.Is <TransactionRecord>(p =>
                                                                            p.ProductSeq == product.ProductSeq && p.Num == remainderNum),
                                                 EntityState.Added);
                dbConnection.Received().Modified(Arg.Is <TransactionRecord>(p =>
                                                                            p.ProductSeq == product.ProductSeq && p.Num == 1000),
                                                 EntityState.Modified);
            }
            else
            {
                //判斷買入經過的資料
                dbConnection.Received().Modified(Arg.Is <TransactionRecord>(p =>
                                                                            p.ProductSeq == product.ProductSeq && p.Num == updateNum),
                                                 isUpdateOddLotTx ? EntityState.Modified : EntityState.Added);
            }


            //判斷沒有經過賣出的資料
            dbConnection.DidNotReceive().Modified(Arg.Is <TransactionRecord>(p =>
                                                                             p.ProductSeq == txViewModel.ProductSeq &&
                                                                             p.InStock == 0
                                                                             ), EntityState.Modified);
            dbConnection.DidNotReceive().Modified(Arg.Is <TransactionRecord>(p =>
                                                                             p.ProductSeq == txViewModel.ProductSeq &&
                                                                             p.SaleTime == txViewModel.TransactionTime
                                                                             ), EntityState.Modified);
            dbConnection.DidNotReceive()
            .Modified(Arg.Is <Bookkeeping>(p => p.ProductSeq == txViewModel.ProductSeq), EntityState.Added);
        }
Example #3
0
        public void SetDividendsSchedule_DividendsKeyIsNull()
        {
            var addDividends = new Dividends();

            Action action = () =>
            {
                dividendsRepository.SetDividendsSchedule(addDividends);
            };

            action.Should().Throw <DataKeyIsNullException>();


            dbConnection.DidNotReceive().QueryableTransactionRecords.Where(p =>
                                                                           p.ProductSeq == addDividends.ProductSeq && p.SalePrice == null &&
                                                                           p.TransactionTime <= addDividends.ExRightDate.Date);
            //確認沒有進入AddTransaction的重新計算資產的
            dbConnection.DidNotReceive().Modified(Arg.Is <TransactionRecord>(p => p.ProductSeq == addDividends.ProductSeq), EntityState.Added);
            dbConnection.DidNotReceive().QueryableAssets.FirstOrDefault(p => p.ProductSeq == addDividends.ProductSeq);
            dbConnection.DidNotReceive().SaveChanges();
        }
Example #4
0
        public void EditProduct_AddProduct()
        {
            var addproduct = new Product()
            {
                ProductName = "new product", ProductValue = "value", Owner = "owner"
            };


            var except = "Success";
            var actual = productRepository.EditProduct(addproduct);

            Assert.AreEqual(except, actual);

            dbConnection.DidNotReceive().QueryableProducts.FirstOrDefault(p => p.ProductSeq == addproduct.ProductSeq);
            dbConnection.DidNotReceive().Modified(addproduct, EntityState.Modified);
            dbConnection.Received().Modified(addproduct, EntityState.Added);
            dbConnection.Received(1).SaveChanges();
            assetRepository.Received(1).AddNewAsset(addproduct);
        }