Ejemplo n.º 1
0
 public void OnCreate(ISimpleFactory <IResourceLoadingTaskImpl> implFactory)
 {
     if (Impl == null)
     {
         Impl = implFactory.Get();
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 点击测试连接
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnTestConn_Click(object sender, EventArgs e)
        {
            ISimpleFactory <string, IDbConnection> factory = AutofacTool.Resolve <ISimpleFactory <string, IDbConnection> >();
            IDbConnection dbConnection = factory.Create(cbxDataSourceType.SelectedItem.ToString());

            try
            {
                dbConnection.ConnectionString = GetDbConnectionString();
                dbConnection.Open();
                if (dbConnection.State == ConnectionState.Open)
                {
                    dbConnection.Close();
                    dbConnection.Dispose();

                    MessageBox.Show("连接成功");
                }
                else
                {
                    MessageBox.Show("连接失败");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
            public void It_should_fill_all_properties_recursively(ISimpleFactory <Customer> factory)
            {
                var customer = factory.Many(3).Build().ToArray();

                customer[0].Address.ZipCode.Should().Be("ZipCode1");
                customer[1].Address.ZipCode.Should().Be("ZipCode2");
                customer[2].Address.ZipCode.Should().Be("ZipCode3");
            }
Ejemplo n.º 4
0
 /// <summary>
 /// 构造方法
 /// </summary>
 /// <param name="next">下一个中间件处理委托</param>
 /// <param name="options">路由权限选项配置</param>
 /// <param name="reader">读取API权限配置</param>
 /// <param name="userService">用户服务</param>
 /// <param name="localize">本地化</param>
 /// <param name="comDataFactory">通用数据工厂</param>
 public RoutePermissionMiddleware(RequestDelegate next, IOptions <RoutePermissionOptions> options, IReader <RoutePermissionInfo[]> reader,
                                  IUserService userService, ILocalization localize,
                                  ISimpleFactory <HttpContext, CommonUseData> comDataFactory = null)
     : base(next, options, reader, localize)
 {
     this.userService    = userService;
     this.comDataFactory = comDataFactory;
 }
Ejemplo n.º 5
0
        public void It_should_fill_all_properties_with_empty_values(ISimpleFactory <Customer> factory)
        {
            var customer = factory.Build();

            customer.Name.Should().Be(string.Empty);
            customer.FirstYearInBusiness.Should().Be(0);
            customer.Address.Should().NotBeNull();
            customer.Address.ZipCode.Should().Be(string.Empty);
        }
            public void It_should_fill_all_properties_with_empty_values_without_recursion(
                ISimpleFactory <Customer> factory)
            {
                var customer = factory.Build();

                customer.Name.Should().Be("Name1");
                customer.Age.Should().Be(1);
                customer.Birthday.Should().Be(1.January(1753));
                customer.Address.Should().BeNull();
            }
Ejemplo n.º 7
0
        public void It_should_be_possible_to_chain_another_one_builder(ISimpleFactory <Person> factory)
        {
            var persons = factory
                          .One().With(x => x.Age     = 99)
                          .PlusOne().With(x => x.Age = 100)
                          .Build()
                          .ToList();

            persons.Should().HaveCount(2);

            persons[0].Age.Should().Be(99);
            persons[1].Age.Should().Be(100);
        }
 public void TearDown()
 {
     m_DownloadService.OnShutdown();
     m_DownloadService = null;
     m_RefPoolService.OnShutdown();
     m_RefPoolService          = null;
     m_TickService             = null;
     m_DownloadTaskImplFactory = null;
     m_DirectoryInfo           = null;
     if (Directory.Exists(SavePathRoot))
     {
         Directory.Delete(SavePathRoot, true);
     }
 }
Ejemplo n.º 9
0
 public void TearDown()
 {
     m_DownloadTaskPool = null;
     m_DownloadModule.ShutDown();
     m_DownloadModule = null;
     m_ObjectPoolModule.ShutDown();
     m_ObjectPoolModule        = null;
     m_DownloadTaskImplFactory = null;
     m_DirectoryInfo           = null;
     if (Directory.Exists(SavePathRoot))
     {
         Directory.Delete(SavePathRoot, true);
     }
 }
Ejemplo n.º 10
0
        public void It_should_be_possible_to_chain_many_more_after_many(ISimpleFactory <Person> factory)
        {
            var persons = factory
                          .Many(2).With(x => x.Age = 99)
                          .Plus(2).With(x => x.Age = 100)
                          .Build()
                          .ToList();

            persons.Should().HaveCount(4);

            persons[0].Age.Should().Be(99);
            persons[1].Age.Should().Be(99);
            persons[2].Age.Should().Be(100);
            persons[3].Age.Should().Be(100);
        }
            public void It_should_fill_all_nullable_properties_of_supported_types(ISimpleFactory <Customer> factory)
            {
                var customers = factory.Many(2).Build().ToArray();

                var secondCustomer = customers[1];

                secondCustomer.NullableByteProperty.Should().Be(2);
                secondCustomer.NullableShortProperty.Should().Be(2);
                secondCustomer.NullableUShortProperty.Should().Be(2);
                secondCustomer.NullableIntProperty.Should().Be(2);
                secondCustomer.NullableUIntProperty.Should().Be(2);
                secondCustomer.NullableLongProperty.Should().Be(2);
                secondCustomer.NullableULongProperty.Should().Be(2);
                secondCustomer.NullableFloatProperty.Should().Be(2f);
                secondCustomer.NullableDoubleProperty.Should().Be(2d);
                secondCustomer.NullableDecimalProperty.Should().Be(2m);
                secondCustomer.NullableDateTimeProperty.Should().Be(RecursiveTransformFactoryOptions.DefaultStartDate.AddDays(1));
            }
        public void SetUp()
        {
            if (Directory.Exists(SavePathRoot))
            {
                Directory.Delete(SavePathRoot, true);
            }

            if (!Directory.Exists(SavePathRoot))
            {
                Directory.CreateDirectory(SavePathRoot);
            }

            m_DirectoryInfo = new DirectoryInfo(SavePathRoot);

            m_TickService = new MockTickService();

            m_RefPoolService = new RefPoolService();
            var refPoolServiceConfigReader = Substitute.For <IRefPoolServiceConfigReader>();

            refPoolServiceConfigReader.DefaultCapacity.Returns(1);
            m_RefPoolService.ConfigReader = refPoolServiceConfigReader;
            m_RefPoolService.OnInit();

            m_DownloadService = new DownloadService {
                TickService = m_TickService, TickOrder = 0
            };
            var configReader = Substitute.For <IDownloadServiceConfigReader>();

            configReader.TempFileExtension.Returns(".tmp");
            configReader.Timeout.Returns(1f);
            configReader.ChunkSizeToSave.Returns(32);
            configReader.ConcurrentDownloadCountLimit.Returns(2);
            m_DownloadService.ConfigReader = configReader;

            m_DownloadTaskImplFactory = new MockDownloadTaskImplFactory();
            var mockDownloadTaskImplFactory = m_DownloadTaskImplFactory as MockDownloadTaskImplFactory;

            mockDownloadTaskImplFactory.TaskShouldNeverStart = false;

            m_DownloadService.RefPoolService          = m_RefPoolService;
            m_DownloadService.DownloadTaskImplFactory = m_DownloadTaskImplFactory;
            m_DownloadService.OnInit();
        }
Ejemplo n.º 13
0
        public void SetUp()
        {
            if (Directory.Exists(SavePathRoot))
            {
                Directory.Delete(SavePathRoot, true);
            }

            if (!Directory.Exists(SavePathRoot))
            {
                Directory.CreateDirectory(SavePathRoot);
            }

            m_DirectoryInfo = new DirectoryInfo(SavePathRoot);

            m_ObjectPoolModule = new RefPoolModule();
            m_ObjectPoolModule.Init();

            m_DownloadModule = new DownloadModule();
            m_DownloadModule.ChunkSizeToSave = 32;
            m_DownloadModule.ConcurrentDownloadCountLimit = 2;
            m_DownloadModule.TempFileExtension            = ".tmp";
            m_DownloadModule.Timeout = 10000f;

            m_DownloadTaskPool = Substitute.For <IDownloadTaskPool>();
            m_DownloadTaskPool.Acquire().Returns(callInfo => new DownloadTask());

            m_DownloadTaskImplFactory = new MockDownloadTaskImplFactory();
            var mockDownloadTaskImplFactory = m_DownloadTaskImplFactory as MockDownloadTaskImplFactory;

            mockDownloadTaskImplFactory.TaskShouldNeverStart = false;

            m_DownloadModule.DownloadTaskPool        = m_DownloadTaskPool;
            m_DownloadModule.RefPoolModule           = m_ObjectPoolModule;
            m_DownloadModule.DownloadTaskImplFactory = m_DownloadTaskImplFactory;
            m_DownloadModule.Init();
        }
Ejemplo n.º 14
0
        /// <summary>
        /// 创建通用数据
        /// </summary>
        /// <param name="context">上下文</param>
        /// <param name="factory">通用数据工厂</param>
        /// <param name="key">键</param>
        /// <param name="menuCode">菜单编码</param>
        /// <param name="functionCodes">功能编码数组</param>
        /// <returns>通用数据</returns>
        public static CommonUseData CreateCommonUseData(this HttpContext context, ISimpleFactory <HttpContext, CommonUseData> factory, string key = null, string menuCode = null, params string[] functionCodes)
        {
            if (factory != null)
            {
                var result = factory.Create(context);
                if (result != null)
                {
                    result.Key           = key;
                    result.MenuCode      = menuCode;
                    result.FunctionCodes = functionCodes;

                    return(result);
                }
            }

            var comData = context.CreateBasicCommonUseData();

            if (string.IsNullOrWhiteSpace(comData.EventId))
            {
                comData.EventId = StringUtil.NewShortGuid();
            }

            return(comData);
        }
            public void It_should_fill_all_objects_properties_with_sequential_numbers(ISimpleFactory <Customer> factory)
            {
                var customers = factory.Many(3).Build().ToArray();

                customers[0].Birthday.Should().Be(25.December(2020).At(22.Hours()));
                customers[1].Birthday.Should().Be(25.December(2020).At(23.Hours()));
                customers[2].Birthday.Should().Be(26.December(2020).At(0.Hours()));
            }
Ejemplo n.º 16
0
        public void Default_filling_behavior_should_be_not_filling_properties_values(ISimpleFactory <Person> factory)
        {
            var person = factory.Build();

            person.Age.Should().Be(default);
Ejemplo n.º 17
0
        public void It_should_fill_all_properties_with_empty_values_without_recursion(ISimpleFactory <Customer> factory)
        {
            var customer = factory.Build();

            customer.Name.Should().Be(string.Empty, "it should fill properties in root level");
            customer.Address.Should().BeNull("it should not fill nested objects");
        }
            public void It_should_fill_all_objects_properties_with_sequential_numbers(ISimpleFactory <Customer> factory)
            {
                var customers = factory.Many(3).Build().ToArray();

                customers[0].Name.Should().Be("Name1");
                customers[0].Age.Should().Be(1);
                customers[0].Birthday.Should().Be(1.January(1753));
                customers[1].Name.Should().Be("Name2");
                customers[1].Age.Should().Be(2);
                customers[1].Birthday.Should().Be(2.January(1753));
                customers[2].Name.Should().Be("Name3");
                customers[2].Age.Should().Be(3);
                customers[2].Birthday.Should().Be(3.January(1753));
            }
Ejemplo n.º 19
0
        public void It_should_not_fill_nullable_properties_if_this_option_is_explicitly_disabled(ISimpleFactory <Customer> factory)
        {
            var customer = factory.Build();

            customer.FirstYearInBusiness.Should().BeNull("filling nullables is disabled");
        }