protected override void Arrange() { _modelActivator = new ModelActivator(); _anemicType = new AnemicType { FirstName = "Edward", LastName = "Blackburn", Age = 33 }; }
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); }
public void Null_Configuration_Throws() { var activator = new ModelActivator(null); activator.Invoking(x => x.CreateInstance(null)) .Should() .ThrowExactly <NullReferenceException>(); }
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>(); }
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>(); }
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>(); }
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>(); }
protected override void Arrange() { _modelActivator = new ModelActivator(); }
protected override void Arrange() { _modelActivator = new ModelActivator(); _anemicType = new AnemicType {FirstName = "Edward", LastName = "Blackburn", Age = 33}; }