public void GetComponentName()
        {
            var componentType = typeof(TestComponent1);

            _sourceDescriptions
            .GetComponentName(componentType)
            .Should().Be(SourceDescriptions.BuildTypeName(componentType));
        }
        public void GetEntityTypeByName()
        {
            var entityType = typeof(TestAsset);

            _sourceDescriptions
            .GetEntityType(SourceDescriptions.BuildTypeName(entityType))
            .Should().Be(entityType);
        }
Exemple #3
0
 public ComponentsConverter(
     IConvertersCollection converters,
     IComponentFactory componentFactory,
     SourceDescriptions descriptions)
 {
     _converters       = converters;
     _componentFactory = componentFactory;
     _descriptions     = descriptions;
 }
        public ListReferenceResolver(PropertyInfo property, SourceDescriptions descriptions, Func <int, TEntity> resolver)
            : base(descriptions, resolver)
        {
            _propertyName = property.Name;

            var owner = Typeof <TOwner> .Raw;

            _entityGetter = (Func <TOwner, IList <TEntity?> >)ExpressionUtils.BuildGetter(owner, property);
            _entitySetter = (Action <TOwner, List <TEntity?> >)ExpressionUtils.BuildSetter(owner, property);
        }
Exemple #5
0
        public JsonFileSource(IConvertersCollection converters, SourceDescriptions descriptions, string path)
            : base(converters, descriptions)
        {
            if (!File.Exists(path))
            {
                throw Error.FileNotFound(path);
            }

            _path = path;
        }
            public Enumerator(
                IConvertersCollection converters,
                SourceDescriptions descriptions,
                JsonTokenizer tokenizer)
            {
                _converters   = converters;
                _descriptions = descriptions;
                _tokenizer    = tokenizer;

                Current = null !;
            }
Exemple #7
0
        public ActorReferencesConverter(
            IActorContext actorContext,
            SourceDescriptions descriptions,
            IEntitySourceContext <Actor> sources,
            PropertyInfo property)
        {
            _actorContext = actorContext;
            _resolver     = ReferenceResolver <TOwner, TActor> .Build(property, descriptions, GetEntity);

            _sources = sources;
        }
Exemple #8
0
        public AssetReferencesConverter(
            SourceDescriptions descriptions,
            IServiceProvider provider,
            IEntitySourceContext <Asset> sources,
            PropertyInfo property)
        {
            _assetContext = new Lazy <IAssetContext>(provider.GetRequired <IAssetContext>);
            _resolver     = ReferenceResolver <TOwner, TAsset> .Build(property, descriptions, GetEntity);

            _sources = sources;
        }
Exemple #9
0
 /// <summary>
 /// Add a source description to the data set.
 /// </summary>
 /// <param name="sourceDescription">The source description to be added.</param>
 public void AddSourceDescription(SourceDescription sourceDescription)
 {
     if (sourceDescription != null)
     {
         if (SourceDescriptions == null)
         {
             SourceDescriptions = new List <SourceDescription>();
         }
         SourceDescriptions.Add(sourceDescription);
     }
 }
Exemple #10
0
        protected EntityConverter(IServiceProvider services, bool isCustomType)
        {
            Contract = Typeof <TEntity> .Raw;

            _customTypeName = isCustomType
                ? SourceDescriptions.BuildTypeName(Typeof <TEntity> .Raw)
                : null;

            _properties = SerializationUtils.ActivatePropertyConverters <TEntity>(services);

            _idConverter         = (IdConverter)_properties[nameof(IEntity.Id)];
            _componentsConverter = (ComponentsConverter)_properties[nameof(IEntity.Components)];
        }
Exemple #11
0
        public EntityState(
            IActorContext actors,
            IActorFactory actorFactory,
            IAssetContext assets,
            IConvertersCollection converters,
            SourceDescriptions descriptions)
        {
            Actors = actors;
            Assets = assets;

            _actorFactory = actorFactory;
            _converters   = converters;
            _descriptions = descriptions;
        }
        public ComponentsConverterShould()
        {
            var provider = new DependencyCollection()
                           .AddECS()
                           .BuildProvider();

            var components = new IComponent[] { Fixture.Create <TestComponent1>(), Fixture.Create <TestComponent2>() };

            _asset = new TestAsset(1, components)
            {
                Reference = CreateAsset(2)
            };

            var converters = provider.GetRequired <IConvertersCollection>();

            _converter = provider.Activate <ComponentsConverter>();

            _assetData = (JsonObject)converters.Write(_asset);

            _component1Name = SourceDescriptions.BuildTypeName(typeof(TestComponent1));
            _component2Name = SourceDescriptions.BuildTypeName(typeof(TestComponent2));
        }
Exemple #13
0
 public JsonStreamSource(IConvertersCollection converters, SourceDescriptions descriptions, Stream stream)
     : base(converters, descriptions)
 {
     _stream = stream;
 }
Exemple #14
0
 public IdConverter(IConvertersCollection converters, SourceDescriptions descriptions)
 {
     _descriptions    = descriptions;
     _intConverter    = converters.Get <int>();
     _stringConverter = converters.Get <string>();
 }
 public void NotReplaceWordsInEntityTypeName(Type type)
 {
     SourceDescriptions
     .BuildTypeName(type)
     .Should().Be(type.Name);
 }
 public void ReplaceComponentWord()
 {
     SourceDescriptions
     .BuildTypeName(typeof(TestComponent1))
     .Should().Be(nameof(TestComponent1).Cut("Component"));
 }
Exemple #17
0
 protected JsonSource(IConvertersCollection converters, SourceDescriptions descriptions)
 {
     _converters   = converters;
     _descriptions = descriptions;
 }
Exemple #18
0
        public static ReferenceResolver <TOwner, TEntity> Build(PropertyInfo property, SourceDescriptions descriptions, Func <int, TEntity> resolver)
        {
            var propertyType = property.PropertyType;

            if (ReflectionUtils.IsListLikeGenericType(propertyType, out _))
            {
                return(new ListReferenceResolver <TOwner, TEntity>(property, descriptions, resolver));
            }

            if (ReflectionUtils.IsArrayLikeGenericType(propertyType, out _))
            {
                return(new ArrayReferenceResolver <TOwner, TEntity>(property, descriptions, resolver));
            }

            return(new EntityReferenceResolver <TOwner, TEntity>(property, descriptions, resolver));
        }
Exemple #19
0
 protected ReferenceResolver(SourceDescriptions descriptions, Func <int, TEntity> resolver)
 {
     _descriptions = descriptions;
     _resolver     = resolver;
 }
 public SourceDescriptionsShould()
 {
     _sourceDescriptions = new SourceDescriptions();
 }