private void FillCarLoadDocument(CarLoadDocument document, IUnitOfWork uow, int routeListId, int warehouseId)
        {
            var currentEmployee = _employeeRepository.GetEmployeeForCurrentUser(uow);

            document.RouteList      = uow.GetById <RouteList>(routeListId);
            document.Author         = currentEmployee;
            document.LastEditor     = currentEmployee;
            document.LastEditedTime = DateTime.Now;
            document.Warehouse      = uow.GetById <Warehouse>(warehouseId);

            document.FillFromRouteList(uow, _routeListRepository, _subdivisionRepository, true);
            document.UpdateAlreadyLoaded(uow, _routeListRepository);
            document.UpdateStockAmount(uow, _stockRepository);
            document.UpdateAmounts();
        }
Esempio n. 2
0
        public void FillFromRouteList_WhenPassARouteList_CarLoadItemsCreatingCorrectly()
        {
            // arrange
            Vodovoz.Domain.Logistic.RouteList routeListMock01 = Substitute.For <Vodovoz.Domain.Logistic.RouteList>();
            Warehouse warehouseMock01 = Substitute.For <Warehouse>();
            ISubdivisionRepository subdivisionRepositoryMock01 = Substitute.For <ISubdivisionRepository>();
            Nomenclature           nomenclatureMock01          = Substitute.For <Nomenclature>();

            nomenclatureMock01.Id.Returns(101);
            Nomenclature nomenclatureMock02 = Substitute.For <Nomenclature>();

            nomenclatureMock02.Id.Returns(102);
            Nomenclature nomenclatureMock03 = Substitute.For <Nomenclature>();

            nomenclatureMock03.Id.Returns(103);

            List <GoodsInRouteListResult> listOfGoods = new List <GoodsInRouteListResult> {
                new GoodsInRouteListResult {
                    NomenclatureId = nomenclatureMock01.Id,
                    Amount         = 10
                },
                new GoodsInRouteListResult {
                    NomenclatureId = nomenclatureMock02.Id,
                    Amount         = 20
                },
                new GoodsInRouteListResult {
                    NomenclatureId = nomenclatureMock03.Id,
                    Amount         = 30
                }
            };

            IUnitOfWork uowMock = Substitute.For <IUnitOfWork>();

            uowMock.GetById <Nomenclature>(Arg.Any <int[]>()).Returns(
                new List <Nomenclature> {
                nomenclatureMock01,
                nomenclatureMock02,
                nomenclatureMock03
            }
                );

            IRouteListRepository routeListRepositoryMock = Substitute.For <IRouteListRepository>();

            routeListRepositoryMock.GetGoodsAndEquipsInRL(uowMock, routeListMock01, subdivisionRepositoryMock01, warehouseMock01).Returns(listOfGoods);

            CarLoadDocument loadDocumentUnderTest = new CarLoadDocument {
                Warehouse = warehouseMock01,
                RouteList = routeListMock01
            };

            // act
            loadDocumentUnderTest.FillFromRouteList(uowMock, routeListRepositoryMock, subdivisionRepositoryMock01, true);

            // assert
            Assert.That(loadDocumentUnderTest.Items.Count, Is.EqualTo(3));
            Assert.That(loadDocumentUnderTest.Items[0].Document, Is.EqualTo(loadDocumentUnderTest));
            Assert.That(loadDocumentUnderTest.Items[0].Nomenclature, Is.EqualTo(nomenclatureMock01));
            Assert.That(loadDocumentUnderTest.Items[0].AmountInRouteList, Is.EqualTo(listOfGoods.FirstOrDefault(x => x.NomenclatureId == nomenclatureMock01.Id).Amount));
            Assert.That(loadDocumentUnderTest.Items[0].Amount, Is.EqualTo(listOfGoods.FirstOrDefault(x => x.NomenclatureId == nomenclatureMock01.Id).Amount));
            Assert.That(loadDocumentUnderTest.Items[1].Document, Is.EqualTo(loadDocumentUnderTest));
            Assert.That(loadDocumentUnderTest.Items[1].Nomenclature, Is.EqualTo(nomenclatureMock02));
            Assert.That(loadDocumentUnderTest.Items[1].AmountInRouteList, Is.EqualTo(listOfGoods.FirstOrDefault(x => x.NomenclatureId == nomenclatureMock02.Id).Amount));
            Assert.That(loadDocumentUnderTest.Items[1].Amount, Is.EqualTo(listOfGoods.FirstOrDefault(x => x.NomenclatureId == nomenclatureMock02.Id).Amount));
            Assert.That(loadDocumentUnderTest.Items[2].Document, Is.EqualTo(loadDocumentUnderTest));
            Assert.That(loadDocumentUnderTest.Items[2].Nomenclature, Is.EqualTo(nomenclatureMock03));
            Assert.That(loadDocumentUnderTest.Items[2].AmountInRouteList, Is.EqualTo(listOfGoods.FirstOrDefault(x => x.NomenclatureId == nomenclatureMock03.Id).Amount));
            Assert.That(loadDocumentUnderTest.Items[2].Amount, Is.EqualTo(listOfGoods.FirstOrDefault(x => x.NomenclatureId == nomenclatureMock03.Id).Amount));
        }