示例#1
0
        public void Then_the_object_must_be_the_same_if_registered_as_singleton()
        {
            FluentApplicationContext.Register <ObjectWithProperties>();
            FluentApplicationContext.Register(
                c => new ObjectWithConstructor(c.GetObject <ObjectWithProperties>()));

            IApplicationContext context = _applicationContextContainer.InitialiseContext();

            ObjectWithConstructor objectA = context.GetObject <ObjectWithConstructor>();
            ObjectWithConstructor objectB = context.GetObject <ObjectWithConstructor>();

            Assert.AreSame(objectA, objectB);
        }
示例#2
0
        public void Then_the_object_must_be_instantiated_with_the_context_injected_values()
        {
            FluentApplicationContext.Register <ObjectWithProperties>();
            FluentApplicationContext.Register(
                c => new ObjectWithConstructor(c.GetObject <ObjectWithProperties>()));

            IApplicationContext context = _applicationContextContainer.InitialiseContext();

            ObjectWithConstructor objectWithConstructor = context.GetObject <ObjectWithConstructor>();
            ObjectWithProperties  childObject           = context.GetObject <ObjectWithProperties>();

            Assert.IsNotNull(objectWithConstructor);
            Assert.IsNotNull(objectWithConstructor.ObjectInferface);
            Assert.AreSame(childObject, objectWithConstructor.ObjectInferface);
        }
示例#3
0
        public void Then_the_object_must_be_retrievable_by_name_with_the_context_injected_values()
        {
            FluentApplicationContext.Register <ObjectWithProperties>();

            FluentApplicationContext.Register(
                c => new ObjectWithConstructor(c.GetObject <ObjectWithProperties>()), "objectA");
            FluentApplicationContext.Register(
                c => new ObjectWithConstructor("somestring"), "objectB");

            IApplicationContext context = _applicationContextContainer.InitialiseContext();

            ObjectWithConstructor objectA = context.GetObject <ObjectWithConstructor>("objectA");
            ObjectWithConstructor objectB = context.GetObject <ObjectWithConstructor>("objectB");

            Assert.IsNotNull(objectA.ObjectInferface);
            Assert.AreEqual("somestring", objectB.First);
        }
示例#4
0
        public void ConstructorByApi(string hexBuffer, int expectedId, string expectedName, int expectedAge)
        {
            CborOptions options = new CborOptions();

            options.Registry.ObjectMappingRegistry.Register <ObjectWithConstructor>(objectMapping =>
                                                                                    objectMapping
                                                                                    .AutoMap()
                                                                                    .MapCreator(o => new ObjectWithConstructor(o.Id, o.Name))
                                                                                    );

            ObjectWithConstructor obj = Helper.Read <ObjectWithConstructor>(hexBuffer, options);

            Assert.NotNull(obj);
            Assert.Equal(expectedId, obj.Id);
            Assert.Equal(expectedName, obj.Name);
            Assert.Equal(expectedAge, obj.Age);
        }
示例#5
0
        public void ConstructorByApi(string json, int expectedId, string expectedName, int expectedAge)
        {
            JsonSerializerOptions options = new JsonSerializerOptions();

            options.SetupExtensions();
            options.GetObjectMappingRegistry().Register <ObjectWithConstructor>(objectMapping =>
                                                                                objectMapping
                                                                                .AutoMap()
                                                                                .MapCreator(o => new ObjectWithConstructor(o.Id, o.Name))
                                                                                );

            ObjectWithConstructor obj = Helper.Read <ObjectWithConstructor>(json, options);

            Assert.NotNull(obj);
            Assert.Equal(expectedId, obj.Id);
            Assert.Equal(expectedName, obj.Name);
            Assert.Equal(expectedAge, obj.Age);
        }
示例#6
0
        public void FactoryByApi(string hexBuffer, int expectedId, string expectedName, int expectedAge)
        {
            Factory factory = new Factory();
            Func <int, string, ObjectWithConstructor> creatorFunc = (int id, string name) => factory.NewObjectWithConstructor(id, name);

            CborOptions options = new CborOptions();

            options.Registry.ObjectMappingRegistry.Register <ObjectWithConstructor>(objectMapping =>
                                                                                    objectMapping
                                                                                    .AutoMap()
                                                                                    .MapCreator(creatorFunc)
                                                                                    );

            ObjectWithConstructor obj = Helper.Read <ObjectWithConstructor>(hexBuffer, options);

            Assert.NotNull(obj);
            Assert.Equal(expectedId, obj.Id);
            Assert.Equal(expectedName, obj.Name);
            Assert.Equal(expectedAge, obj.Age);
        }
示例#7
0
        public void FactoryByApi(string json, int expectedId, string expectedName, int expectedAge)
        {
            Factory factory = new Factory();
            Func <int, string, ObjectWithConstructor> creatorFunc = (int id, string name) => factory.NewObjectWithConstructor(id, name);

            JsonSerializerOptions options = new JsonSerializerOptions();

            options.SetupExtensions();
            options.GetObjectMappingRegistry().Register <ObjectWithConstructor>(objectMapping =>
                                                                                objectMapping
                                                                                .AutoMap()
                                                                                .MapCreator(creatorFunc)
                                                                                );

            ObjectWithConstructor obj = Helper.Read <ObjectWithConstructor>(json, options);

            Assert.NotNull(obj);
            Assert.Equal(expectedId, obj.Id);
            Assert.Equal(expectedName, obj.Name);
            Assert.Equal(expectedAge, obj.Age);
        }