public void Accepts_custom_action()
 {
     var factory = new SimpleFactory<Rabbit>(x => x.Age = 3);
     var product = factory.Create(x => x.Name = "Fluffy");
     Assert.Equal(3, product.Age);
     Assert.Equal("Fluffy", product.Name);
 }
Exemple #2
0
        void Start()
        {
            this.gameObject.AddComponent <SimpleFactory>();
            SimpleFactory _factory = gameObject.GetComponent <SimpleFactory>();

            _facility = new Facility(_factory);
        }
Exemple #3
0
        public void TestShippingByStore_Seven_1_Order_Family_2_Orders()
        {
            var target = new ShipService();

            var orders = new List <Order>
            {
                new Order {
                    StoreType = StoreType.Seven, Id = 1
                },
                new Order {
                    StoreType = StoreType.Family, Id = 2
                },
                new Order {
                    StoreType = StoreType.Family, Id = 3
                },
            };

            var stubSeven = Substitute.For <IStoreService>();

            SimpleFactory.SetSevenService(stubSeven);

            var stubFamily = Substitute.For <IStoreService>();

            SimpleFactory.SetFamilyService(stubFamily);

            target.ShippingByStore(orders);

            stubSeven.Received(1).Ship(Arg.Is <Order>(a => a.StoreType == StoreType.Seven));
            stubFamily.Received(2).Ship(Arg.Is <Order>(a => a.StoreType == StoreType.Family));
        }
    static void Main()
    {
        var simpleFactory = new SimpleFactory();
        var entity        = simpleFactory.Create(1);

        entity.Something();
    }
 public PlayerController(PlayerViewBase _playerView, PlayerDataBase _playerData, SimpleFactory <SpawnableBase> _lazerFactory, LevelViewBase _levelView)
 {
     playerView   = _playerView;
     playerData   = _playerData;
     lazerFactory = _lazerFactory;
     levelView    = _levelView;
 }
 public void Can_handle_null_factory()
 {
     var parentFactory = new SimpleFactory<Rabbit>();
     var childFactory = new ChainedFactory<Rabbit>(parentFactory, x => x.Name = "Fluffy");
     var product = childFactory.Create(null);
     Assert.Equal("Fluffy", product.Name);
 }
Exemple #7
0
        public void Example1Test()
        {
            SimpleFactory factory = new SimpleFactory();
            IProduct      product = factory.Create();

            Assert.AreEqual <Type>(product.GetType(), typeof(ConcreteProductA));
        }
Exemple #8
0
            static void Main(string[] args)
            {
                SimpleFactory g = new SimpleFactory();
                produce       p = new produce(g);

                p.getgraph();
            }
Exemple #9
0
        public void PneumologistCreationWithoutReflectionTest()
        {
            SimpleFactory factory = SimpleFactory.GetFactory();
            IDoctor       x       = factory.GetDoctor(typeof(Pneumologist));

            Assert.AreSame(x.GetType(), typeof(Pneumologist));
        }
Exemple #10
0
        public void MathTeacherCreationTest()
        {
            SimpleFactory factory = SimpleFactory.GetFactory();
            IPerson       x       = factory.GetPerson <MathTeacher>();

            Assert.AreSame(x.GetType(), typeof(MathTeacher));
        }
Exemple #11
0
        public void SimpleFactoryTest()
        {
            Course course = new Course();

            course.Type = SimpleFactory.CreateClassrom(CourseType.Online);
            Assert.IsInstanceOfType(course.Type, typeof(OnlineCourse));
        }
Exemple #12
0
        public void PneumologistCreationTest()
        {
            SimpleFactory factory = SimpleFactory.GetFactory();
            IPerson       x       = factory.GetPerson <Pneumologist>();

            Assert.AreSame(x.GetType(), typeof(Pneumologist));
        }
Exemple #13
0
        //工厂类用于调用者和具体实现对象的解耦
        static void Main(string[] args)
        {
            //Simple Factory
            IPhone phone = SimpleFactory.Create <IMiPhone>();

            Console.WriteLine(phone.Name);

            phone = SimpleFactory.Create <IHWPhone>();
            Console.WriteLine(phone.Name);

            //Factory Method
            FactroyMethodBase method = new MiPhoneFactoryMethod();

            Console.WriteLine(method.CreatePhone().Name);

            method = new HwPhoneFactoryMethod();
            Console.WriteLine(method.CreatePhone().Name);

            //Virtual
            VirtualFactoryBase factory = new XiaoMiFactory();

            Console.WriteLine(factory.CreatePhone().Name);
            Console.WriteLine(factory.CreateTV().Name);

            factory = new HWFactory();
            Console.WriteLine(factory.CreatePhone().Name);
            Console.WriteLine(factory.CreateTV().Name);

            Console.ReadKey();
        }
Exemple #14
0
        public void Do()
        {
            SimpleFactory fac = new SimpleFactory();
            Product       p   = fac.GetMyProduct("ProductA");

            p.SayHi();
        }
Exemple #15
0
        public void CreateShipEmpty1()
        {
            SimpleFactory factory = SimpleFactory.Instance;
            var           ship    = factory.CreateCruiser(null);

            Assert.IsNull(ship);
        }
Exemple #16
0
        public void PainterCreationWithoutReflectionTest()
        {
            SimpleFactory factory = SimpleFactory.GetFactory();
            IArtist       x       = factory.GetArtist(typeof(Painter));

            Assert.AreSame(x.GetType(), typeof(Painter));
        }
Exemple #17
0
        public void CreateShipWrong()
        {
            SimpleFactory factory = SimpleFactory.Instance;
            var           ship    = factory.CreateFrigate("asdf");

            Assert.IsNull(ship);
        }
Exemple #18
0
        public void CreateShipWrong2()
        {
            SimpleFactory factory = SimpleFactory.Instance;
            var           ship    = factory.CreateCapitalShip("cobalt");

            Assert.IsNull(ship);
        }
Exemple #19
0
        public void CreateShip2()
        {
            SimpleFactory factory = SimpleFactory.Instance;
            var           ship    = factory.CreateCapitalShip("sova");

            Assert.IsNotNull(ship);
        }
Exemple #20
0
        public void CreateShip1()
        {
            SimpleFactory factory = SimpleFactory.Instance;
            var           ship    = factory.CreateCruiser("kodiak");

            Assert.IsNotNull(ship);
        }
Exemple #21
0
        public void CreateShip()
        {
            SimpleFactory factory = SimpleFactory.Instance;
            var           ship    = factory.CreateFrigate("cobalt");

            Assert.IsNotNull(ship);
        }
Exemple #22
0
        public void MathTeacherCreationWithoutReflectionTest()
        {
            SimpleFactory factory = SimpleFactory.GetFactory();
            ITeacher      x       = factory.GetTeacher(typeof(MathTeacher));

            Assert.AreSame(x.GetType(), typeof(MathTeacher));
        }
Exemple #23
0
        public void CreateShipEmpty2()
        {
            SimpleFactory factory = SimpleFactory.Instance;
            var           ship    = factory.CreateCapitalShip(null);

            Assert.IsNull(ship);
        }
Exemple #24
0
        public void PainterCreationTest()
        {
            SimpleFactory factory = SimpleFactory.GetFactory();
            IPerson       x       = factory.GetPerson <Painter>();

            Assert.AreSame(x.GetType(), typeof(Painter));
        }
Exemple #25
0
      /// <summary>
      /// 简单工厂模式
      /// 定义一个共同接口,创建不同的对象,简化创建过程,创建与表示分离
      /// </summary>
      // Use this for initialization
     void Start()
 {
     //根据不同的条件选择不同的动物
     SimpleFactory.CreateAnimal("HaiOu").Print();
     SimpleFactory.CreateAnimal("HaiYan").Print();
     SimpleFactory.CreateAnimal("TuoNiao").Print();
 }
Exemple #26
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie();

            services.AddMvc(
                options =>
            {
                options.EnableEndpointRouting = false;
            })
            .AddRazorPagesOptions(
                options =>
            {
                options.Conventions.AuthorizePage("/Account/NewUserVerfication");
            });

            services.Configure <AppSettings>(this.Configuration.GetSection("AppSettings"));

            SimpleFactory.ResolveUiDependencies(services, this.Configuration);

            SimpleFactory.ResolveApiDependencies(services, this.Configuration);

            //services.AddControllersWithViews().AddRazorPagesOptions(
            //    options =>
            //        {
            //            options.Conventions.AuthorizePage("/Account/NewUserVerification");
            //        });
        }
 public void Can_build_product()
 {
     var parentFactory = new SimpleFactory<Rabbit>(x => x.Name = "Fluffy");
     var childFactory = new ChainedFactory<Rabbit>(parentFactory, x => x.Name += " the Bunny");
     var product = childFactory.Create();
     Assert.Equal("Fluffy the Bunny", product.Name);
 }
Exemple #28
0
        public void TestMethod1()
        {
            var    result = SimpleFactory.GetOperateResult(1, 2, "+");
            double tvault = 3;

            Assert.AreEqual(result, tvault);
        }
Exemple #29
0
        public static void Main()
        {
            IFactory factory    = new SimpleFactory();
            var      controller = new UnitController(factory);
            IStudent student    = controller.GetAllStudents(new [] { "Online", "Iskra Radeva", "5.0 6 6" });

            Console.WriteLine($"Name {student.Name}");
        }
Exemple #30
0
        public void CreateFactoryTest()
        {
            var oper = SimpleFactory.CreateFactory("+");

            oper.NumberA = 1;
            oper.NumberA = 1;
            Assert.AreSame(2, oper.GetResult());
        }
 public void Accepts_custom_action()
 {
     var parentFactory = new SimpleFactory<Rabbit>(x => x.Age = 3);
     var childFactory = new ChainedFactory<Rabbit>(parentFactory, x => x.Name = "Fluffy");
     var product = childFactory.Create(x => x.Name += " the Bunny");
     Assert.Equal(3, product.Age);
     Assert.Equal("Fluffy the Bunny", product.Name);
 }
Exemple #32
0
        public DbQuery(IEntity entity)
        {
            SimpleFactory          factory    = new SimpleFactory();
            Tuple <Insert, Select> queriesTup = entity.GenerateQueries(factory);

            _insert = queriesTup.Item1;
            _select = queriesTup.Item2;
        }
        public Tuple <Insert, Select> GenerateQueries(SimpleFactory factory)
        {
            Insert insert = factory.GenerateContractorInsert(this);
            Select select = factory.GenerateContractorSelect(this);
            Tuple <Insert, Select> resultTup = new Tuple <Insert, Select>(insert, select);

            return(resultTup);
        }
Exemple #34
0
    static void Main(string[] args)
    {
        Operation opera = new Operation();

        opera         = SimpleFactory.CreateOperation("+");
        opera.NumberA = 5;
        opera.NumberB = 6;
        System.Console.Write(opera.NumberA + "+" + opera.NumberB + "=" + opera.getResult());
    }
 public void Can_handle_null_custom_action()
 {
     var factory = new SimpleFactory<Rabbit>();
     Rabbit product = null;
     Assert.DoesNotThrow(() =>
     {
         product = factory.Create(null);
     });
     Assert.NotNull(product);
 }
 public void Can_build_product()
 {
     var factory = new SimpleFactory<Rabbit>();
     var product = factory.Create();
     Assert.NotNull(product);
 }