Пример #1
0
        public async Task TestAssetSynchronization()
        {
            var code = @"class Test { void Method() { } }";

            using var workspace = TestWorkspace.CreateCSharp(code);
            var solution = workspace.CurrentSolution;

            // build checksum
            await solution.State.GetChecksumAsync(CancellationToken.None);

            var map = await solution.GetAssetMapAsync(CancellationToken.None);

            var sessionId = 0;
            var storage   = new AssetStorage();

            storage.Initialize(new SimpleAssetSource(map));

            var service = new AssetProvider(sessionId, storage, new RemoteWorkspace().Services.GetService <ISerializerService>());
            await service.SynchronizeAssetsAsync(new HashSet <Checksum>(map.Keys), CancellationToken.None);

            foreach (var kv in map)
            {
                Assert.True(storage.TryGetAsset <object>(kv.Key, out _));
            }
        }
Пример #2
0
        public async Task TestAssets()
        {
            var sessionId = 0;
            var checksum  = Checksum.Create(WellKnownSynchronizationKind.Null, ImmutableArray.CreateRange(Guid.NewGuid().ToByteArray()));
            var data      = new object();

            var storage = new AssetStorage();

            storage.Initialize(new SimpleAssetSource(new Dictionary <Checksum, object>()
            {
                { checksum, data }
            }));

            var provider = new AssetProvider(sessionId, storage, new RemoteWorkspace().Services.GetService <ISerializerService>());
            var stored   = await provider.GetAssetAsync <object>(checksum, CancellationToken.None);

            Assert.Equal(data, stored);

            var stored2 = await provider.GetAssetsAsync <object>(new[] { checksum }, CancellationToken.None);

            Assert.Equal(1, stored2.Count);

            Assert.Equal(checksum, stored2[0].Item1);
            Assert.Equal(data, stored2[0].Item2);
        }
Пример #3
0
        public void TestCreation()
        {
            var storage = new AssetStorage();
            var source  = new SimpleAssetSource(new Dictionary <Checksum, object>());

            storage.Initialize(source);

            var stored = storage.GetAssetSource();

            Assert.Equal(source, stored);
        }
Пример #4
0
        public async Task TestSolutionSynchronization()
        {
            var code = @"class Test { void Method() { } }";

            using var workspace = TestWorkspace.CreateCSharp(code);
            var solution = workspace.CurrentSolution;

            // build checksum
            await solution.State.GetChecksumAsync(CancellationToken.None);

            var map = await solution.GetAssetMapAsync(CancellationToken.None);

            var sessionId = 0;
            var storage   = new AssetStorage();

            storage.Initialize(new SimpleAssetSource(map));

            var service = new AssetProvider(sessionId, storage, new RemoteWorkspace().Services.GetService <ISerializerService>());
            await service.SynchronizeSolutionAssetsAsync(await solution.State.GetChecksumAsync(CancellationToken.None), CancellationToken.None);

            TestUtils.VerifyAssetStorage(map, storage);
        }
Пример #5
0
        public async Task TestProjectSynchronization()
        {
            var code = @"class Test { void Method() { } }";

            using var workspace = TestWorkspace.CreateCSharp(code);
            var project = workspace.CurrentSolution.Projects.First();

            // build checksum
            await project.State.GetChecksumAsync(CancellationToken.None);

            var map = await project.GetAssetMapAsync(CancellationToken.None);

            var sessionId = 0;
            var storage   = new AssetStorage();

            storage.Initialize(new SimpleAssetSource(map));

            var service = new AssetProvider(sessionId, storage, new RemoteWorkspace().Services.GetService <ISerializerService>());
            await service.SynchronizeProjectAssetsAsync(SpecializedCollections.SingletonEnumerable(await project.State.GetChecksumAsync(CancellationToken.None)), CancellationToken.None);

            TestUtils.VerifyAssetStorage(map, storage);
        }