public void ReturnFromClientWaybillService_Rows_Of_Different_Articles_MustBe_AddedOk()
        {
            var row = new ReturnFromClientWaybillRow(saleRow2.Object, 2)
            {
                Id = Guid.NewGuid()
            };

            returnFromClientWaybill.AddRow(row);

            Assert.AreEqual(2, returnFromClientWaybill.RowCount);
        }
        public void ReturnFromClientWaybill_Must_Throw_Exception_If_State_Is_Accepted()
        {
            try
            {
                row1 = new ReturnFromClientWaybillRow(saleRow1, 1);
                row2 = new ReturnFromClientWaybillRow(saleRow2, 1);

                returnFromClientWaybill.AddRow(row1);
                returnFromClientWaybill.Accept(Prices, false, curator, DateTime.Now);
                returnFromClientWaybill.AddRow(row2);

                Assert.Fail("Исключение не вызвано.");
            }
            catch (Exception ex)
            {
                Assert.AreEqual("Невозможно добавить позицию в накладную со статусом «Проведено».", ex.Message);
            }
        }
        public void ReturnFromClientWaybill_Must_Throw_Exception_If_RecipientAccountingPriceSum_Try_Set_AfterAccept()
        {
            try
            {
                var waybill = new ReturnFromClientWaybill("142", DateTime.Today, accountOrganization, deal, team, storage, returnFromClientReason, curator, curator, DateTime.Now);
                var row     = new ReturnFromClientWaybillRow(saleRow1, 1);
                waybill.AddRow(row);

                waybill.RecipientAccountingPriceSum = 100.5M;
                waybill.Accept(Prices, false, curator, DateTime.Now);
                waybill.RecipientAccountingPriceSum = 101.5M;

                Assert.Fail("Исключение не вызвано.");
            }
            catch (Exception ex)
            {
                Assert.AreEqual("Невозможно установить значение суммы в учетных ценах, т.к. накладная уже проведена.", ex.Message);
            }
        }
        public void Init()
        {
            // инициализация IoC
            IoCInitializer.Init();

            setting = new Setting()
            {
                UseReadyToAcceptStateForReturnFromClientWaybill = false
            };
            settingRepository = Mock.Get(IoCContainer.Resolve <ISettingRepository>());
            settingRepository.Setup(x => x.Get()).Returns(setting);

            storage = new Storage("qwe", StorageType.ExtraStorage)
            {
                Id = 42
            };
            accOrgSender = new Mock <AccountOrganization>();
            accOrgSender.Setup(x => x.Id).Returns(1);
            accOrgRecipient = new Mock <AccountOrganization>();
            accOrgRecipient.Setup(x => x.Id).Returns(2);

            valueAddedTax = new ValueAddedTax();
            user          = new Mock <User>();
            user.Setup(x => x.GetPermissionDistributionType(It.IsAny <Permission>())).Returns(PermissionDistributionType.All);
            createdBy = new Mock <User>();
            createdBy.Setup(x => x.GetPermissionDistributionType(It.IsAny <Permission>())).Returns(PermissionDistributionType.All);
            acceptedBy = new Mock <User>();
            acceptedBy.Setup(x => x.GetPermissionDistributionType(It.IsAny <Permission>())).Returns(PermissionDistributionType.All);
            receiptedBy = new Mock <User>();
            receiptedBy.Setup(x => x.GetPermissionDistributionType(It.IsAny <Permission>())).Returns(PermissionDistributionType.All);

            var articleGroup = new ArticleGroup("Тестовая группа", "Тестовая группа");
            var measureUnit  = new MeasureUnit("шт.", "Штука", "123", 0)
            {
                Id = 1
            };

            articleA = new Article("Тестовый товар A", articleGroup, measureUnit, true)
            {
                Id = 1
            };
            articleB = new Article("Тестовый товар Б", articleGroup, measureUnit, true)
            {
                Id = 2
            };

            receiptWaybillRow1 = new Mock <ReceiptWaybillRow>();
            receiptWaybillRow1.Setup(x => x.Article).Returns(articleA);

            receiptWaybillRow2 = new Mock <ReceiptWaybillRow>();
            receiptWaybillRow2.Setup(x => x.Article).Returns(articleB);


            articleAccountingPrice = new List <ArticleAccountingPrice>()
            {
                new ArticleAccountingPrice(articleA, 100)
            };

            returnFromClientWaybillRepository = Mock.Get(IoCContainer.Resolve <IReturnFromClientWaybillRepository>());

            articlePriceService = Mock.Get(IoCContainer.Resolve <IArticlePriceService>());
            articlePriceService.Setup(x => x.GetArticleAccountingPrices(It.Is <short>(y => y == storage.Id), It.IsAny <IEnumerable <int> >())).Returns(articleAccountingPrice);
            articlePriceService.Setup(x => x.GetArticleAccountingPrices(It.Is <short>(y => y == storage.Id), It.IsAny <ISubQuery>(), It.IsAny <DateTime>())).Returns(articleAccountingPrice);
            returnFromClientWaybillRepository = Mock.Get(IoCContainer.Resolve <IReturnFromClientWaybillRepository>());

            expenditureWaybillIndicatorService = Mock.Get(IoCContainer.Resolve <IExpenditureWaybillIndicatorService>());
            articleAvailabilityService         = Mock.Get(IoCContainer.Resolve <IArticleAvailabilityService>());

            returnFromClientWaybillService = new ReturnFromClientWaybillService(
                IoCContainer.Resolve <ISettingRepository>(),
                returnFromClientWaybillRepository.Object,
                IoCContainer.Resolve <ITeamRepository>(),
                IoCContainer.Resolve <IDealRepository>(),
                IoCContainer.Resolve <IStorageRepository>(),
                IoCContainer.Resolve <IUserRepository>(),
                IoCContainer.Resolve <IArticlePriceService>(),
                IoCContainer.Resolve <IAcceptedSaleIndicatorService>(),
                IoCContainer.Resolve <IReturnFromClientService>(),
                IoCContainer.Resolve <IFactualFinancialArticleMovementService>(),
                IoCContainer.Resolve <IArticleMovementOperationCountService>(),
                IoCContainer.Resolve <IArticleMovementService>(),
                IoCContainer.Resolve <IDealPaymentDocumentDistributionService>(),
                IoCContainer.Resolve <IDealIndicatorService>(),
                IoCContainer.Resolve <IArticleRevaluationService>(),
                expenditureWaybillIndicatorService.Object,
                articleAvailabilityService.Object
                );

            deal  = new Mock <Deal>();
            quota = new DealQuota("asd", 10, 45, 15000);
            team  = new Team("Тестовая команда", It.IsAny <User>())
            {
                Id = 1
            };

            contract = new Mock <ClientContract>();
            var economicAgent = new Mock <EconomicAgent>();

            accountOrganization = new AccountOrganization("asd", "asd", economicAgent.Object);

            deal.Setup(x => x.IsActive).Returns(true);
            deal.Setup(x => x.IsClosed).Returns(false);
            deal.Setup(x => x.Quotas).Returns(new List <DealQuota> {
                quota
            });
            deal.Setup(x => x.Contract).Returns(contract.Object);
            accountOrganization.AddStorage(storage);

            contract.Setup(x => x.AccountOrganization).Returns(accountOrganization);

            returnFromClientWaybill = new ReturnFromClientWaybill("123", DateTime.Now, accountOrganization, deal.Object, team, storage, new ReturnFromClientReason(), user.Object, createdBy.Object, DateTime.Now);

            sale = new Mock <ExpenditureWaybill>();
            sale.Setup(x => x.Sender).Returns(accountOrganization);
            sale.Setup(x => x.Team).Returns(team);
            sale.Setup(x => x.Is <ExpenditureWaybill>()).Returns(true);
            sale.Setup(x => x.As <ExpenditureWaybill>()).Returns(sale.Object);

            #region Создание позиции 1

            saleRow1 = new Mock <ExpenditureWaybillRow>();
            saleRow1.Setup(x => x.ExpenditureWaybill).Returns(sale.Object);
            saleRow1.Setup(x => x.SaleWaybill).Returns(sale.Object);
            saleRow1.Setup(x => x.Id).Returns(Guid.NewGuid());
            saleRow1.Setup(x => x.SellingCount).Returns(100);
            saleRow1.Setup(x => x.As <ExpenditureWaybillRow>()).Returns(saleRow1.Object);
            saleRow1.Setup(x => x.Is <ExpenditureWaybillRow>()).Returns(true);
            saleRow1.Setup(x => x.Article).Returns(articleA);
            saleRow1.Setup(x => x.SalePrice).Returns(128);
            saleRow1.Setup(x => x.ReceiptWaybillRow).Returns(receiptWaybillRow1.Object);

            #endregion

            #region Создание позиции 2

            saleRow2 = new Mock <ExpenditureWaybillRow>();
            saleRow2.Setup(x => x.ExpenditureWaybill).Returns(sale.Object);
            saleRow2.Setup(x => x.SaleWaybill).Returns(sale.Object);
            saleRow2.Setup(x => x.Id).Returns(Guid.NewGuid());
            saleRow2.Setup(x => x.SellingCount).Returns(100);
            saleRow2.Setup(x => x.As <ExpenditureWaybillRow>()).Returns(saleRow2.Object);
            saleRow2.Setup(x => x.Is <ExpenditureWaybillRow>()).Returns(true);
            saleRow2.Setup(x => x.Article).Returns(articleA);
            saleRow2.Setup(x => x.SalePrice).Returns(128);
            saleRow2.Setup(x => x.ReceiptWaybillRow).Returns(receiptWaybillRow2.Object);

            #endregion

            ReturnFromClientWaybillRow row = new ReturnFromClientWaybillRow(saleRow1.Object, 1);
            returnFromClientWaybill.AddRow(row);

            articleMovementService = new Mock <IArticleMovementService>();

            articleMovementService.Setup(x => x.CancelArticleAcceptance(It.IsAny <WriteoffWaybill>()))
            .Returns(new List <OutgoingWaybillRowSourceReservationInfo>()
            {
                new OutgoingWaybillRowSourceReservationInfo(row.Id, 1, 1)
            });
            articleMovementService.Setup(x => x.AcceptArticles(It.IsAny <WriteoffWaybill>()))
            .Returns(new List <OutgoingWaybillRowSourceReservationInfo>()
            {
                new OutgoingWaybillRowSourceReservationInfo(row.Id, 1, 1)
            });
        }