Esempio n. 1
0
        public void CreateFuelExpenseOperationTest()
        {
            // arrange

            expenseCategoryMock = Substitute.For <ExpenseCategory>();
            CategoryRepository.FuelDocumentExpenseCategoryTestGap = (arg) => expenseCategoryMock;

            FuelType fuelTypeMock = Substitute.For <FuelType>();

            fuelTypeMock.Cost.Returns(30);

            Car carMock = Substitute.For <Car>();

            carMock.IsCompanyCar.Returns(false);

            Organization organisationMock = Substitute.For <Organization>();

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

            VodovozRouteList routeListMock   = Substitute.For <VodovozRouteList>();
            Subdivision      subdivisionMock = Substitute.For <Subdivision>();

            routeListMock.ClosingSubdivision = subdivisionMock;

            IFuelRepository fuelRepositoryMock = Substitute.For <IFuelRepository>();

            fuelRepositoryMock.GetFuelBalanceForSubdivision(uowMock, subdivisionMock, fuelTypeMock).Returns(50);

            OrganizationParametersProvider organisationParametersProviderMock =
                Substitute.For <OrganizationParametersProvider>();

            CashDistributionCommonOrganisationProvider commonOrganisationProviderMock =
                Substitute.For <CashDistributionCommonOrganisationProvider>(organisationParametersProviderMock);

            commonOrganisationProviderMock.GetCommonOrganisation(uowMock).Returns(organisationMock);

            var fuelDocument = new FuelDocument();

            fuelDocument.Driver       = Substitute.For <Employee>();
            fuelDocument.Car          = carMock;
            fuelDocument.Date         = DateTime.Now;
            fuelDocument.LastEditDate = DateTime.Now;
            fuelDocument.Fuel         = fuelTypeMock;
            fuelDocument.RouteList    = routeListMock;
            fuelDocument.UoW          = uowMock;
            fuelDocument.FuelCoupons  = 40;
            fuelDocument.PayedForFuel = null;
            fuelDocument.Subdivision  = subdivisionMock;

            // act
            fuelDocument.CreateOperations(fuelRepositoryMock, commonOrganisationProviderMock);

            // assert
            AssertsAccumulator.Create
            .Accumulate(() => Assert.That(fuelDocument.FuelExpenseOperation.FuelDocument, Is.SameAs(fuelDocument), "Документ в операции должен совпадать с документом выдачи топлива"))
            .Accumulate(() => Assert.That(fuelDocument.FuelExpenseOperation.FuelTransferDocument, Is.Null, "Документ перемещения топлива не должен быть заполнен"))
            .Accumulate(() => Assert.That(fuelDocument.FuelExpenseOperation.RelatedToSubdivision, Is.SameAs(fuelDocument.RouteList.ClosingSubdivision), "Подразделение в операции должно совпадать с подразделением в маршрутном листе"))
            .Accumulate(() => Assert.That(fuelDocument.FuelExpenseOperation.FuelLiters, Is.EqualTo(fuelDocument.FuelCoupons), "Списанное топливо должно совпадать с топливом выданным талонами в документе выдачи"))
            .Release();
        }
Esempio n. 2
0
        public void CreateFuelCashExpenseTest()
        {
            // arrange
            var categoryRepositoryMock = Substitute.For <ICategoryRepository>();

            expenseCategoryMock = Substitute.For <ExpenseCategory>();
            categoryRepositoryMock.FuelDocumentExpenseCategory(null).Returns(expenseCategoryMock);

            FuelType fuelTypeMock = Substitute.For <FuelType>();

            fuelTypeMock.Cost.Returns(30);

            Car carMock = Substitute.For <Car>();

            carMock.IsCompanyCar.Returns(false);

            Organization organisationMock = Substitute.For <Organization>();

            VodovozRouteList routeListMock      = Substitute.For <VodovozRouteList>();
            Subdivision      subdivisionMock    = Substitute.For <Subdivision>();
            IUnitOfWork      uowMock            = Substitute.For <IUnitOfWork>();
            IFuelRepository  fuelRepositoryMock = Substitute.For <IFuelRepository>();

            fuelRepositoryMock.GetFuelBalanceForSubdivision(uowMock, subdivisionMock, fuelTypeMock).Returns(50);

            routeListMock.ClosingSubdivision = subdivisionMock;

            OrganizationParametersProvider organisationParametersProviderMock =
                Substitute.For <OrganizationParametersProvider>(_parametersProvider);

            CashDistributionCommonOrganisationProvider commonOrganisationProviderMock =
                Substitute.For <CashDistributionCommonOrganisationProvider>(organisationParametersProviderMock);

            commonOrganisationProviderMock.GetCommonOrganisation(uowMock).Returns(organisationMock);

            var fuelDocument = new FuelDocument();

            fuelDocument.Driver          = Substitute.For <Employee>();
            fuelDocument.FuelPaymentType = FuelPaymentType.Cash;
            fuelDocument.Car             = carMock;
            fuelDocument.Date            = DateTime.Now;
            fuelDocument.LastEditDate    = DateTime.Now;
            fuelDocument.Fuel            = fuelTypeMock;
            fuelDocument.RouteList       = routeListMock;
            fuelDocument.UoW             = uowMock;
            fuelDocument.FuelCoupons     = 40;
            fuelDocument.PayedForFuel    = 500;
            fuelDocument.Subdivision     = subdivisionMock;

            // act
            fuelDocument.CreateOperations(fuelRepositoryMock, commonOrganisationProviderMock, categoryRepositoryMock);

            // assert
            AssertsAccumulator.Create
            .Accumulate(() => Assert.That(fuelDocument.FuelCashExpense.Casher, Is.SameAs(fuelDocument.Author)))
            .Accumulate(() => Assert.That(fuelDocument.FuelCashExpense.Employee, Is.SameAs(fuelDocument.Driver)))
            .Accumulate(() => Assert.That(fuelDocument.FuelCashExpense.RelatedToSubdivision, Is.SameAs(fuelDocument.RouteList.ClosingSubdivision)))
            .Release();
        }
Esempio n. 3
0
        public void CreateFuelCashExpenseTest_Money(decimal payedForFuel, decimal result)
        {
            // arrange
            var categoryRepositoryMock = Substitute.For <ICategoryRepository>();

            expenseCategoryMock = Substitute.For <ExpenseCategory>();
            categoryRepositoryMock.FuelDocumentExpenseCategory(null).Returns(expenseCategoryMock);

            FuelType fuelTypeMock = Substitute.For <FuelType>();

            fuelTypeMock.Cost.Returns(30);

            Car carMock = Substitute.For <Car>();

            carMock.IsCompanyCar.Returns(false);

            Organization organisationMock = Substitute.For <Organization>();

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

            VodovozRouteList routeListMock   = Substitute.For <VodovozRouteList>();
            Subdivision      subdivisionMock = Substitute.For <Subdivision>();

            routeListMock.ClosingSubdivision = subdivisionMock;

            IFuelRepository fuelRepositoryMock = Substitute.For <IFuelRepository>();

            fuelRepositoryMock.GetFuelBalanceForSubdivision(uowMock, subdivisionMock, fuelTypeMock).Returns(50);

            var organisationParametersProviderMock = Substitute.For <OrganizationParametersProvider>(_parametersProvider);

            organisationParametersProviderMock.CommonCashDistributionOrganisationId.Returns(2);

            CashDistributionCommonOrganisationProvider commonOrganisationProviderMock =
                Substitute.For <CashDistributionCommonOrganisationProvider>(organisationParametersProviderMock);

            commonOrganisationProviderMock.GetCommonOrganisation(uowMock).Returns(organisationMock);

            var fuelDocument = new FuelDocument();

            fuelDocument.Driver          = Substitute.For <Employee>();
            fuelDocument.Car             = carMock;
            fuelDocument.FuelPaymentType = FuelPaymentType.Cash;
            fuelDocument.Date            = DateTime.Now;
            fuelDocument.LastEditDate    = DateTime.Now;
            fuelDocument.Fuel            = fuelTypeMock;
            fuelDocument.RouteList       = routeListMock;
            fuelDocument.UoW             = uowMock;
            fuelDocument.FuelCoupons     = 40;
            fuelDocument.PayedForFuel    = payedForFuel;
            fuelDocument.Subdivision     = subdivisionMock;

            // act
            fuelDocument.CreateOperations(fuelRepositoryMock, commonOrganisationProviderMock, categoryRepositoryMock);

            // assert
            Assert.That(fuelDocument.FuelCashExpense.Money, Is.EqualTo(result));
        }
Esempio n. 4
0
        public void CreateFuelCashExpenseTest__Incorrect_FuelCoupons_and_PayedForFuel__Thrown_ValidationException_and_FuelCashExpense_must_be_null()
        {
            // arrange
            // arrange
            var categoryRepositoryMock = Substitute.For <ICategoryRepository>();

            expenseCategoryMock = Substitute.For <ExpenseCategory>();
            categoryRepositoryMock.FuelDocumentExpenseCategory(null).Returns(expenseCategoryMock);

            FuelType fuelTypeMock = Substitute.For <FuelType>();

            fuelTypeMock.Cost.Returns(30);

            Car carMock = Substitute.For <Car>();

            carMock.IsCompanyCar.Returns(true);

            Organization organisationMock = Substitute.For <Organization>();

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

            VodovozRouteList routeListMock   = Substitute.For <VodovozRouteList>();
            Subdivision      subdivisionMock = Substitute.For <Subdivision>();

            routeListMock.ClosingSubdivision = subdivisionMock;

            IFuelRepository fuelRepositoryMock = Substitute.For <IFuelRepository>();

            fuelRepositoryMock.GetFuelBalanceForSubdivision(uowMock, subdivisionMock, fuelTypeMock).Returns(50);

            OrganizationParametersProvider organisationParametersProviderMock =
                Substitute.For <OrganizationParametersProvider>(_parametersProvider);

            CashDistributionCommonOrganisationProvider commonOrganisationProviderMock =
                Substitute.For <CashDistributionCommonOrganisationProvider>(organisationParametersProviderMock);

            commonOrganisationProviderMock.GetCommonOrganisation(uowMock).Returns(organisationMock);

            var fuelDocument = new FuelDocument();

            fuelDocument.Driver       = Substitute.For <Employee>();
            fuelDocument.Car          = carMock;
            fuelDocument.Date         = DateTime.Now;
            fuelDocument.LastEditDate = DateTime.Now;
            fuelDocument.Fuel         = fuelTypeMock;
            fuelDocument.RouteList    = routeListMock;
            fuelDocument.UoW          = uowMock;
            fuelDocument.PayedForFuel = 0;

            // act, assert
            Assert.Throws(typeof(ValidationException),
                          () => fuelDocument.CreateOperations(fuelRepositoryMock, commonOrganisationProviderMock, categoryRepositoryMock));

            // additional assert
            Assert.That(fuelDocument.FuelCashExpense, Is.Null, "При исключении в момент создания операций, операции оплаты топлива не должно быть создано");
        }
        public void CreateFuelCashExpenseTest__With_Zero_PayedFor_Fuel__FuelCashExpense_must_be_null()
        {
            // arrange
            var categoryRepositoryMock = Substitute.For <ICategoryRepository>();

            expenseCategoryMock = Substitute.For <ExpenseCategory>();
            categoryRepositoryMock.FuelDocumentExpenseCategory(null).Returns(expenseCategoryMock);

            FuelType fuelTypeMock = Substitute.For <FuelType>();

            fuelTypeMock.Cost.Returns(30);

            CarVersion carVersionMock = Substitute.For <CarVersion>();

            carVersionMock.IsCompanyCar.Returns(true);

            Organization organisationMock = Substitute.For <Organization>();

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

            VodovozRouteList routeListMock   = Substitute.For <VodovozRouteList>();
            Subdivision      subdivisionMock = Substitute.For <Subdivision>();

            routeListMock.ClosingSubdivision = subdivisionMock;

            IFuelRepository fuelRepositoryMock = Substitute.For <IFuelRepository>();

            fuelRepositoryMock.GetFuelBalanceForSubdivision(uowMock, subdivisionMock, fuelTypeMock).Returns(50);

            OrganizationParametersProvider organisationParametersProviderMock =
                Substitute.For <OrganizationParametersProvider>(_parametersProvider);

            CashDistributionCommonOrganisationProvider commonOrganisationProviderMock =
                Substitute.For <CashDistributionCommonOrganisationProvider>(organisationParametersProviderMock);

            commonOrganisationProviderMock.GetCommonOrganisation(uowMock).Returns(organisationMock);

            var fuelDocument = new FuelDocument();

            fuelDocument.Driver       = Substitute.For <Employee>();
            fuelDocument.Car          = carVersionMock.Car;
            fuelDocument.Date         = DateTime.Now;
            fuelDocument.LastEditDate = DateTime.Now;
            fuelDocument.Fuel         = fuelTypeMock;
            fuelDocument.RouteList    = routeListMock;
            fuelDocument.UoW          = uowMock;
            fuelDocument.FuelCoupons  = 40;
            fuelDocument.PayedForFuel = 0;
            fuelDocument.Subdivision  = subdivisionMock;

            // act
            fuelDocument.CreateOperations(fuelRepositoryMock, commonOrganisationProviderMock, categoryRepositoryMock);

            // assert
            Assert.That(fuelDocument.FuelCashExpense, Is.Null);
        }
Esempio n. 6
0
        public void CreateFuelOperationTest_Car_IsCompanyHavings()
        {
            // arrange

            expenseCategoryMock = Substitute.For <ExpenseCategory>();
            CategoryRepository.FuelDocumentExpenseCategoryTestGap = (arg) => expenseCategoryMock;

            FuelType fuelTypeMock = Substitute.For <FuelType>();

            fuelTypeMock.Cost.Returns(30);

            Car carMock = Substitute.For <Car>();

            carMock.IsCompanyCar.Returns(true);

            Organization organisationMock = Substitute.For <Organization>();

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

            VodovozRouteList routeListMock   = Substitute.For <VodovozRouteList>();
            Subdivision      subdivisionMock = Substitute.For <Subdivision>();

            routeListMock.ClosingSubdivision = subdivisionMock;

            IFuelRepository fuelRepositoryMock = Substitute.For <IFuelRepository>();

            fuelRepositoryMock.GetFuelBalanceForSubdivision(uowMock, subdivisionMock, fuelTypeMock).Returns(50);

            OrganizationParametersProvider organisationParametersProviderMock =
                Substitute.For <OrganizationParametersProvider>();

            CashDistributionCommonOrganisationProvider commonOrganisationProviderMock =
                Substitute.For <CashDistributionCommonOrganisationProvider>(organisationParametersProviderMock);

            commonOrganisationProviderMock.GetCommonOrganisation(uowMock).Returns(organisationMock);

            var fuelDocument = new FuelDocument();

            fuelDocument.Driver       = Substitute.For <Employee>();
            fuelDocument.Car          = carMock;
            fuelDocument.Date         = DateTime.Now;
            fuelDocument.LastEditDate = DateTime.Now;
            fuelDocument.Fuel         = fuelTypeMock;
            fuelDocument.RouteList    = routeListMock;
            fuelDocument.UoW          = uowMock;
            fuelDocument.FuelCoupons  = 40;
            fuelDocument.PayedForFuel = null;
            fuelDocument.Subdivision  = subdivisionMock;

            // act
            fuelDocument.CreateOperations(fuelRepositoryMock, commonOrganisationProviderMock);

            // assert
            AssertsAccumulator.Create
            .Accumulate(() => Assert.That(fuelDocument.FuelOperation.LitersGived, Is.EqualTo(fuelDocument.FuelCoupons), "Количество топлива в операции не совпадает с количеством в документе"))
            .Accumulate(() => Assert.That(fuelDocument.FuelOperation.PayedLiters, Is.EqualTo(fuelDocument.PayedLiters), "Количество топлива оплаченного деньгами не совпадает с количеством топлива оплаченного деньгами в документе"))
            .Accumulate(() => Assert.That(fuelDocument.FuelOperation.Car, Is.SameAs(fuelDocument.Car), "Автомобиль в операции не совпадает с автомобилем в документе"))
            .Accumulate(() => Assert.That(fuelDocument.FuelOperation.Driver, Is.Null, "Водитель не должен быть заполнен"))
            .Accumulate(() => Assert.That(fuelDocument.FuelOperation.Fuel, Is.SameAs(fuelDocument.Fuel), "Тип топлива в операции не совпадает с типом топлива в документе"))
            .Release();
        }