Ejemplo n.º 1
0
 protected override void Arrange()
 {
     _modelActivator = new ModelActivator();
     _anemicType     = new AnemicType {
         FirstName = "Edward", LastName = "Blackburn", Age = 33
     };
 }
Ejemplo n.º 2
0
        public object ConvertProperty(cTSOProperty property)
        {
            var _struct = DataDefinition.GetStruct(property.StructType);

            if (_struct == null)
            {
                return(null);
            }

            if (!ModelTypeById.ContainsKey(_struct.ID))
            {
                return(null);
            }

            var type     = ModelTypeById[_struct.ID];
            var instance = ModelActivator.NewInstance(type);

            foreach (var field in property.StructFields)
            {
                var _field = _struct.Fields.FirstOrDefault(x => x.ID == field.StructFieldID);
                if (_field == null)
                {
                    continue;
                }

                SetFieldValue(instance, _field.Name, GetUpdateValue(field.Value));
            }

            return(instance);
        }
Ejemplo n.º 3
0
        public void Null_Configuration_Throws()
        {
            var activator = new ModelActivator(null);

            activator.Invoking(x => x.CreateInstance(null))
            .Should()
            .ThrowExactly <NullReferenceException>();
        }
Ejemplo n.º 4
0
        public void FactoryMethod_Succeeds()
        {
            var activator = new ModelActivator(null);
            var source    = new ListConfiguration(typeof(Request), typeof(Item), typeof(Result))
            {
                ModelActivatorConfiguration = new ModelActivatorConfiguration(_ => new Request())
            };

            var result = activator.CreateInstance(source);

            result.Should().BeOfType <Request>();
        }
Ejemplo n.º 5
0
        public void NoFactory_Throws()
        {
            var activator = new ModelActivator(null);
            var source    = new ListConfiguration(typeof(Request), typeof(Item), typeof(Result))
            {
                ModelActivatorConfiguration = new ModelActivatorConfiguration(null, null, null)
            };

            activator.Invoking(x => x.CreateInstance(source))
            .Should()
            .ThrowExactly <ArgumentException>();
        }
Ejemplo n.º 6
0
        public void FactoryType_Service_Succeeds()
        {
            var serviceProvider = new ServiceCollection().AddSingleton <Factory>().BuildServiceProvider();
            var httpContext     = new Mock <HttpContext>();
            var hca             = new Mock <IHttpContextAccessor>();

            hca.SetupGet(x => x.HttpContext).Returns(httpContext.Object);
            httpContext.SetupGet(x => x.RequestServices).Returns(serviceProvider);

            var activator = new ModelActivator(hca.Object);
            var source    = new ListConfiguration(typeof(Request), typeof(Item), typeof(Result))
            {
                ModelActivatorConfiguration = new ModelActivatorConfiguration(typeof(Factory))
            };

            var result = activator.CreateInstance(source);

            result.Should().BeOfType <Request>();
        }
Ejemplo n.º 7
0
        public void UnableToResolveFactory_Throws()
        {
            var serviceProvider = new ServiceCollection().BuildServiceProvider();
            var httpContext     = new Mock <HttpContext>();
            var hca             = new Mock <IHttpContextAccessor>();

            hca.SetupGet(x => x.HttpContext).Returns(httpContext.Object);
            httpContext.SetupGet(x => x.RequestServices).Returns(serviceProvider);

            var activator = new ModelActivator(hca.Object);
            var source    = new ListConfiguration(typeof(Request), typeof(Item), typeof(Result))
            {
                ModelActivatorConfiguration = new ModelActivatorConfiguration(typeof(Request))
            };

            activator.Invoking(x => x.CreateInstance(source))
            .Should()
            .ThrowExactly <NullReferenceException>();
        }
Ejemplo n.º 8
0
 protected override void Arrange()
 {
     _modelActivator = new ModelActivator();
 }
 protected override void Arrange()
 {
     _modelActivator = new ModelActivator();
     _anemicType = new AnemicType {FirstName = "Edward", LastName = "Blackburn", Age = 33};
 }
Ejemplo n.º 10
0
 protected override void Arrange()
 {
     _modelActivator = new ModelActivator();
 }