Example #1
0
        public JsonStreamSourceShould()
        {
            var provider = new DependencyCollection()
                           .AddECS()
                           .BuildProvider();

            _assets = Many(10, i => CreateAsset(i));

            var serialized   = provider.GetRequired <JConverter>().Serialize(_assets);
            var memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(serialized));

            _source        = provider.Activate <JsonStreamSource <Asset> >(new LocalList <object>(memoryStream));
            _sourceContext = Mock.Of <IEntitySourceContext <Asset> >();
        }
Example #2
0
        public JsonFileSourceShould()
        {
            var provider = new DependencyCollection()
                           .AddECS()
                           .BuildProvider();

            _assets = Many(10, i => CreateAsset(i));

            var serialized = provider.GetRequired <JConverter>().Serialize(_assets);

            var fileName = $"{nameof(JsonFileSourceShould)}.json";

            File.WriteAllText(fileName, serialized);

            _source        = provider.Activate <JsonFileSource <Asset> >(new LocalList <object>(fileName));
            _sourceContext = Mock.Of <IEntitySourceContext <Asset> >();
        }
Example #3
0
        public void DeserializeActors()
        {
            var provider = new DependencyCollection()
                           .AddECS()
                           .AddAssets(ctx => _assets)
                           .BuildProvider();

            var serialized = _jsonConverter.Serialize(_actors);

            using var memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(serialized));

            var actors       = provider.GetRequired <IActorContext>();
            var actorsSource = provider.Activate <JsonStreamSource <Actor> >(new LocalList <object>(memoryStream));

            actors.Load(actorsSource);

            actors.Should().Contain(_actors);
        }
Example #4
0
        public IdConverterShould()
        {
            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 <IdConverter>();

            _assetData = (JsonObject)converters.Write(_asset);
        }
Example #5
0
        public void Throw_Activate_NotRegistered()
        {
            var provider = new DependencyCollection().BuildProvider();

            Assert.Throws <KeyNotFoundException>(() => provider.Activate <FooRepository>());
        }
Example #6
0
        public void Throw_Activate_Interface()
        {
            var provider = new DependencyCollection().BuildProvider();

            Assert.Throws <InvalidOperationException>(() => provider.Activate <ISession>());
        }