Esempio n. 1
0
        public void TestActionTypeInsertion()
        {
            ActionType actionType = new ActionType(1, Guid.NewGuid().ToString(), Guid.NewGuid().ToString());

            using (var ctx = new DataContainer())
            {
                ctx.ActionTypes.Add(actionType);

                ctx.SaveChanges();
            }

            using (var ctx = new DataContainer())
            {
                var insertedAction = ctx.ActionTypes.Single(a => a.Id == 1);

                Assert.AreEqual(insertedAction.Name, actionType.Name);
                Assert.AreEqual(insertedAction.Description, actionType.Description);
            }
        }
Esempio n. 2
0
        public void TestAdminUserInsertion()
        {
            User user;

            using (var ctx = new DataContainer())
            {
                user = new AdminUser( "f", "l", "e","fueluser");

                ctx.Parties.Add(user);

                ctx.SaveChanges();
            }

            using (var ctx2 = new DataContainer())
            {
                var user2 = ctx2.Parties.OfType<AdminUser>().Single(u => u.Id == 1);

                Assert.AreEqual(user.FirstName, user2.FirstName);
            }
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            var fuelContext = new DataContainer();
            UnitOfMeasuresAndCurrenciesRegsitrar.ReloadData();

            var reportTableAdapter = new VesselReportTableAdapter();
            var reportDetailsTableAdapter = new VesselReportDetailsTableAdapter();

            var reportDataTable = reportTableAdapter.GetData(1);

            var userId = 1101;

            var initialToApprovedFuelReportStep = fuelContext.ApproveFlows.Where(
                fl =>
                    fl.WorkflowEntity == WorkflowEntities.FuelReport &&
                    fl.ActorUserId == userId &&
                    fl.CurrentWorkflowStage == WorkflowStages.Initial &&
                    fl.WithWorkflowAction == WorkflowActions.Approve);

            var efUnitOfWork = new UnitOfWorkScope( new EFUnitOfWorkFactory(() => fuelContext));

            var vesselInInventoryRepository = new VesselInInventoryRepository(efUnitOfWork);
            var vesselInCompanyStateFactory  = new VesselInCompanyStateFactory();

            var fuelReportFactory = new FuelReportFactory(
                new FuelReportConfigurator(
                    new FuelReportStateFactory(),
                    vesselInInventoryRepository,
                    vesselInCompanyStateFactory),
                new WorkflowRepository(efUnitOfWork),
                new VesselInCompanyRepository(efUnitOfWork, new VesselInCompanyConfigurator(vesselInCompanyStateFactory, vesselInInventoryRepository)));

            foreach (var reportRow in reportDataTable)
            {
                var reportDetailsDataTable = reportDetailsTableAdapter.GetData(reportRow.Code);

                var fuelReport = fuelReportFactory.CreateFuelReport(reportRow.Code.ToString(), reportRow.Description, reportRow.EventDate, reportRow.ReportDate, reportRow.VesselInCompanyId, reportRow.VoyageId, (FuelReportTypes) reportRow.FuelReportType, States.Open);

                foreach (var reportDetailRow in reportDetailsDataTable)
                {

                    var fuelReportDetail = fuelReportFactory.CreateFuelReportDetail(
                        0,
                        reportDetailRow.ROB,
                        "TON",
                        reportDetailRow.Consumption,
                        reportDetailRow.IsRecieveNull() ? null : (double?) reportDetailRow.Recieve,
                        null,
                        reportDetailRow.IsTransferNull() ? null : (double?)(double) reportDetailRow.Transfer,
                        null,
                        reportDetailRow.IsCorrectionNull() ? null : (double?) (double) reportDetailRow.Correction,
                        null,
                        null, "USD", null, reportDetailRow.GoodId, reportDetailRow.GoodUnitId, 12001);

                    fuelReport.FuelReportDetails.Add(fuelReportDetail);
                }

                fuelContext.FuelReports.Add(fuelReport);

                fuelContext.SaveChanges();

                efUnitOfWork.Commit();
            }

            //foreach (FuelReport fuelReport in fuelContext.FuelReports)
            //{
            //    fuelReport.ApproveWorkFlows.Add(new FuelReportWorkflowLog(fuelReport.Id, WorkflowEntities.FuelReport, fuelReport.ReportDate.AddHours(5), WorkflowActions.Approve, 1, "", workflowStepId, true));
            //}

            //context.SaveChanges();
        }
Esempio n. 4
0
        public void TestCustomActionToUserAssignment()
        {
            using (var ctx = new DataContainer())
            {
                foreach (var action in ActionType.GetAllActions())
                {
                    ctx.ActionTypes.Add(action);
                }

                ctx.SaveChanges();
            }

            var user = new User(1, "User", Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "fueluser");

            var grantState = false;

            using (var ctx = new DataContainer())
            {
                ctx.Parties.Add(user);
                ctx.SaveChanges();

                user.AssignCustomActions(ActionType.AddCharterOut, grantState);
                ctx.SaveChanges();
            }

            using (var ctx = new DataContainer())
            {
                var insertedUser = ctx.Parties.OfType<User>().Single(u => u.Id == 1);

                Assert.IsTrue(insertedUser.CustomActions.Count == 1);

                var addedCustomAction = insertedUser.CustomActions[0];

                Assert.IsTrue(addedCustomAction.PartyId == user.Id &&
                    addedCustomAction.ActionTypeId == ActionType.AddCharterOut.Id &&
                    addedCustomAction.IsGranted == grantState);
            }
        }
Esempio n. 5
0
        public void TestUserGroupsInsertion()
        {
            var user = new User(1, "User", "f", "l", "e", "fueluser");

            using (var ctx = new DataContainer())
            {
                ctx.Parties.Add(user);
                ctx.SaveChanges();

                var group = new Group(2, "Group", "Desc");
                ctx.Parties.Add(group);
                ctx.SaveChanges();

                user.AssignGroup(group);
                ctx.SaveChanges();
            }

            using (var ctx = new DataContainer())
            {
                var insertedUser = ctx.Parties.OfType<User>().Single(u => u.Id == 1);

                Assert.IsTrue(
                    insertedUser.Groups.Count == 1 &&
                    insertedUser.Groups.Count(g => g.Id == 2) == 1);

            }
        }
Esempio n. 6
0
        public void TestGroupInsertion()
        {
            Group group = null;

            using (var ctx = new DataContainer())
            {
                group = new Group(1, "Party", "desc");

                ctx.Parties.Add(group);

                ctx.SaveChanges();
            }

            using (var ctx = new DataContainer())
            {
                var user2 = ctx.Parties.OfType<Group>().Single(u => u.Id == 1);

                Assert.AreEqual(group.Description, user2.Description);
            }
        }
Esempio n. 7
0
        public void TestCustomActionToUserAssignmentLowLevel()
        {
            using (var ctx = new DataContainer())
            {
                foreach (var action in ActionType.GetAllActions())
                {
                    ctx.ActionTypes.Add(action);
                }

                ctx.SaveChanges();
            }

            var user = new User(1, "User", Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "fueluser");

            var customAction = new PartyCustomAction(1, ActionType.AddCharterIn.Id, false);

            using (var ctx = new DataContainer())
            {
                ctx.Parties.Add(user);
                ctx.SaveChanges();

                ctx.PartyCustomActions.Add(customAction);
                ctx.SaveChanges();
            }

            using (var ctx = new DataContainer())
            {
                var insertedUser = ctx.Parties.OfType<User>().Single(u=>u.Id == 1);

                Assert.IsTrue(insertedUser.CustomActions.Count == 1 &&
                    insertedUser.CustomActions.Count(ca => ca.Id == customAction.Id) == 1);

                var addedCustomAction = insertedUser.CustomActions.Single(ca => ca.Id == customAction.Id);

                Assert.IsNotNull(addedCustomAction);

                Assert.IsTrue(addedCustomAction.ActionTypeId == customAction.ActionTypeId &&
                    addedCustomAction.IsGranted == customAction.IsGranted);
            }
        }