Example #1
0
 public void TestMigration()
 {
     using (var rep = new DataContainer(DbConnectionHelper.GetConnectionString()))
     {
         var result = rep.VoyagesLog.Find(0);
     }
 }
        public void Get()
        {
            using (var c = new DataContainer(DbConnectionHelper.GetConnectionString()))
            {
                var g = new EFUnitOfWork(c);
                //var rep = new ScrapRepository(g, new ScrapConfigurator(new ScrapStateFactory(new ApprovableScrapDomainService(new VesselDomainService))));

                //var res = rep.Find(r => true);
            }
        }
        public void Can_get_orders_by_filter()
        {
            try
            {
                using (var c = new DataContainer(DbConnectionHelper.GetConnectionString()))
                {
                    var g = new EFUnitOfWork(c);
                    var rep = new OrderRepository(g);
                    Order result = rep.First(d => d.Id > 0);
                }

            }
            catch (Exception ex)
            {

                throw;
            }
        }
Example #4
0
        public void Can_include_related_toVessel_in_order_query()
        {
            using (var rep = new DataContainer(DbConnectionHelper.GetConnectionString()))
            {

                var data = rep.Orders
                    .Include("toVessel")
                    .Where(o => o.FromVesselInCompanyId.HasValue).ToList();//

                Assert.That(data.Count > 0);

                var ent = data.First();
                Assert.That(ent.ToVesselInCompany != null);
                Assert.That(ent.ToVesselInCompany.Id == ent.ToVesselInCompanyId.Value);

                Assert.That(!string.IsNullOrEmpty(ent.ToVesselInCompany.Code));
                Assert.That(!string.IsNullOrEmpty(ent.ToVesselInCompany.Name));
            }
        }
Example #5
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);
            }
        }
Example #6
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);
            }
        }
Example #7
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);
            }
        }
Example #8
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();
        }
Example #9
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);

            }
        }
Example #10
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);
            }
        }
Example #11
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);
            }
        }
Example #12
0
        public void Execute()
        {
            #region create WindsorContainer and Locator

            var container = new WindsorContainer();
            container.Kernel.ReleasePolicy = new NoTrackingReleasePolicy();

            container.Register(Component.For<IWindsorContainer>().Instance(container).LifestyleSingleton());
            var serviceLocator = new WindsorServiceLocator(container);
            ServiceLocator.SetLocatorProvider(() => serviceLocator);

            #endregion

            #region register areas, filters, routes, boundles
            AreaRegistration.RegisterAllAreas();

            container.Register(
              Component.For<IApplicationLogger>()
              .ImplementedBy<ApplicationLogger>().
                  LifestyleSingleton());

            container.Register(
                Component.For<IFuelApplicationExceptionAdapter>()
                .ImplementedBy<FuelApplicationExceptionAdapter>().
                    LifestyleSingleton());

            container.Register(
                        Component.For<GlobalExceptionHandlingAttribute>()
                        .ImplementedBy<GlobalExceptionHandlingAttribute>().
                            LifestyleSingleton());

            #endregion

            #region register data container and repositories
            DataAccessConfigHelper.ConfigureContainer<PerHttpContextUnitOfWorkScope, DataContainer>(container,
               () =>
               {
                   var connectionString = ConfigurationManager.ConnectionStrings["DataContainer"];
                   var ctx = new DataContainer(connectionString.ConnectionString);
                   return ctx;
               });

            #endregion

            #region register MVC

            //register api controllers
            container.Register(Classes.FromThisAssembly()
                                   .BasedOn<ApiController>()
                                   .WithService.Self()
                                   .LifestyleTransient());
            //register controllers
            container.Register(Classes.FromThisAssembly()
                                   .BasedOn<Controller>()
                                   .WithService.Self()
                                   .LifestyleTransient());
            #endregion

            #region register IdGenerator

            //container.Register(Component.For<IOrderFactory>().ImplementedBy<OrderFactory>().LifestyleSingleton());

            #endregion

            var fromAssemblyDescriptor = Classes.FromAssemblyInDirectory(new AssemblyFilter("bin", "*Fuel*"));

            // factory
            container.Register(fromAssemblyDescriptor
                       .BasedOn(typeof(IFactory))
                       .WithService.FromInterface()
                       .LifestyleTransient());

            container.Register(fromAssemblyDescriptor
                       .BasedOn(typeof(ICodeGenerator))
                       .WithService.FromInterface()
                       .LifestyleTransient());

            container.Register(fromAssemblyDescriptor
                       .BasedOn(typeof(IEntityConfigurator<>))
                       .WithService.FromInterface()
                       .LifestyleTransient());

            // eventNotifier
            container.Register(fromAssemblyDescriptor
                       .BasedOn(typeof(IEventNotifier))
                       .WithService.FromInterface()
                       .LifestyleTransient());

            #region register AntiCorruption
            //adapters
            container.Register(fromAssemblyDescriptor
                                   .BasedOn(typeof(IAntiCorruptionAdapter))
                                   .WithService.FromInterface()
                                   .LifestyleTransient());

            //ServiceWrapper
            container.Register(fromAssemblyDescriptor
                                  .BasedOn(typeof(IAntiCorruptionServiceWrapper))
                                   .WithServiceAllInterfaces()
                // .WithService.FromInterface()
                                   .LifestyleTransient());

            //mappers
            container.Register(fromAssemblyDescriptor
                                   .BasedOn(typeof(IMapper))
                                      .WithService.FromInterface()
                                   .LifestyleTransient());

            #endregion

            #region register Application

            container.Register(fromAssemblyDescriptor
                                 .BasedOn<IApplicationService>()
                                 .WithServiceFromInterface()
                                 .LifestyleTransient());

            #endregion

            #region register Facade

            container.Register(

                fromAssemblyDescriptor
                    .BasedOn(typeof(IFacadeService))
                    .WithServiceFromInterface().LifestyleTransient());

            container.Register(
                Component.For<IFacadeService>().
                Interceptors(InterceptorReference.ForType<SecurityInterception>())
               .Anywhere, Component.For<SecurityInterception>());
            container.Register(
                Component.For<ISecurityServiceChecker>()
                .ImplementedBy<SecurityServiceChecker>()
                .LifestyleTransient());

            #endregion

            // Log
            container.Register(
               Component.For<ILoggerService>().ImplementedBy<DbLoggerService>().Named("DB").LifeStyle.Transient,
               Component.For<ILoggerService>().ImplementedBy<FileLoggerService>().Named("File").LifeStyle.Transient

               );

            //externalHostAddressHelper
            container.Register(Component.For<ExternalHostAddressHelper>()
                                   .ImplementedBy<ExternalHostAddressHelper>()
                                   .LifestyleTransient());

            //domainServices
            container.Register(
            fromAssemblyDescriptor

                                   .BasedOn(typeof(IDomainService<>))
                                   .WithServiceAllInterfaces()
                                   .LifestyleTransient());
            container.Register(
            fromAssemblyDescriptor

                                   .BasedOn(typeof(IDomainService))
                                   .WithServiceAllInterfaces()
                                   .LifestyleTransient());

            var assemblyDescriptor = Classes.FromAssemblyInDirectory(new AssemblyFilter("bin", "*AutomaticVoucher*"));
            container.Register(assemblyDescriptor
                              .BasedOn<IAutomaticVoucher>()
                              .WithServiceFromInterface()
                              .LifestyleTransient());

            #region register Repositories
            container.Register(Component.For(typeof(MITD.Domain.Repository.IRepository<>))
                                   .ImplementedBy(typeof(EFRepository<>))
                                   .LifestyleTransient());

            container.Register(
              fromAssemblyDescriptor
                                   .BasedOn<MITD.Domain.Repository.IRepository>()
                                   .WithServiceFromInterface()
                                   .LifestyleTransient());

            #endregion

            #region excute Bootstrapper
            foreach (var bootstrapper in this.GetBootstrappers())
            {
                bootstrapper.Execute();
            }
            #endregion

            #region set default resolver
            System.Web.Mvc.IDependencyResolver resolver = new MITD.Core.IocDependencyResolver();
            DependencyResolver.SetResolver(resolver);
            GlobalConfiguration.Configuration.DependencyResolver = resolver.ToServiceResolver();
            #endregion

            container.Register(Component.For<IEventPublisher>().ImplementedBy<EventPublisher>().LifeStyle.Transient);

            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            //BundleConfig.RegisterBundles(BundleTable.Bundles);

            //Buffer the Unit of Measure and Currencies data into the Application.
            //container.Resolve<IUnitOfMeasuresAndCurrenciesFacadeService>().Reload();
            UnitOfMeasuresAndCurrenciesRegsitrar.ReloadData();
        }