Esempio n. 1
0
        public void FormLink_Direct_TryResolveContext_DeepRecord_NoLink(LinkCacheTestTypes cacheType, AContextRetriever contextRetriever)
        {
            var formLink = new FormLink <IPlacedNpcGetter>(UnusedFormKey);

            var(style, package) = GetLinkCache(new SkyrimMod(TestConstants.PluginModKey, SkyrimRelease.SkyrimLE), cacheType);
            WrapPotentialThrow(cacheType, style, () =>
            {
                Assert.False(contextRetriever.TryResolveContext <IPlacedNpc, IPlacedNpcGetter>(formLink, package, out var _));
            });
        }
Esempio n. 2
0
        public void FormLink_Direct_TryResolveContext_DeepRecord_Linked(LinkCacheTestTypes cacheType, AContextRetriever contextRetriever)
        {
            var mod        = new SkyrimMod(TestConstants.PluginModKey, SkyrimRelease.SkyrimLE);
            var worldspace = mod.Worldspaces.AddNew();
            var subBlock   = new WorldspaceSubBlock();
            var cell       = new Cell(mod.GetNextFormKey(), SkyrimRelease.SkyrimLE);

            subBlock.Items.Add(cell);
            var placedNpc = new PlacedNpc(mod.GetNextFormKey(), SkyrimRelease.SkyrimLE);

            cell.Temporary.Add(placedNpc);
            var block = new WorldspaceBlock();

            block.Items.Add(subBlock);
            worldspace.SubCells.Add(block);
            var(style, package) = GetLinkCache(mod, cacheType);
            var placedFormLink = new FormLink <IPlacedNpcGetter>(placedNpc.FormKey);

            WrapPotentialThrow(cacheType, style, () =>
            {
                Assert.True(contextRetriever.TryResolveContext <IPlacedNpc, IPlacedNpcGetter>(placedFormLink, package, out var linkedPlacedNpc));
                linkedPlacedNpc.Record.Should().BeSameAs(placedNpc);
                linkedPlacedNpc.ModKey.Should().Be(TestConstants.PluginModKey);
                linkedPlacedNpc.Parent.Record.Should().Be(cell);
                var cellFormLink = new FormLink <ICellGetter>(cell.FormKey);
                Assert.True(contextRetriever.TryResolveContext <ICell, ICellGetter>(cellFormLink, package, out var linkedCell));
                linkedCell.Record.Should().BeSameAs(cell);
                linkedCell.ModKey.Should().Be(TestConstants.PluginModKey);
                linkedCell.Parent.Record.Should().Be(subBlock);
                var worldspaceFormLink = new FormLink <IWorldspaceGetter>(worldspace.FormKey);
                Assert.True(contextRetriever.TryResolveContext <IWorldspace, IWorldspaceGetter>(worldspaceFormLink, package, out var linkedWorldspace));
                linkedWorldspace.Record.Should().BeSameAs(worldspace);
                linkedWorldspace.ModKey.Should().Be(TestConstants.PluginModKey);
                linkedWorldspace.Parent.Should().BeNull();
            });
        }
Esempio n. 3
0
        public void FormLink_Direct_TryResolveContext_Linked(LinkCacheTestTypes cacheType, AContextRetriever contextRetriever)
        {
            var mod = new SkyrimMod(TestConstants.PluginModKey, SkyrimRelease.SkyrimLE);
            var npc = mod.Npcs.AddNew();

            var(style, package) = GetLinkCache(mod, cacheType);
            var formLink = new FormLink <INpcGetter>(npc.FormKey);

            WrapPotentialThrow(cacheType, style, () =>
            {
                Assert.True(contextRetriever.TryResolveContext <INpc, INpcGetter>(formLink, package, out var linkedRec));
                linkedRec.Record.Should().BeSameAs(npc);
                linkedRec.ModKey.Should().Be(TestConstants.PluginModKey);
                linkedRec.Parent.Should().BeNull();
            });
        }
        public void PlacedInWorldspaceQuerySucceedsIfMajorRecordType(LinkCacheTestTypes cacheType, AContextRetriever contextRetriever)
        {
            var prototype = new SkyrimMod(TestConstants.PluginModKey, SkyrimRelease.SkyrimSE);
            var placed    = new PlacedObject(prototype);

            prototype.Worldspaces.Add(new Worldspace(prototype)
            {
                SubCells = new ExtendedList <WorldspaceBlock>()
                {
                    new WorldspaceBlock()
                    {
                        Items = new ExtendedList <WorldspaceSubBlock>()
                        {
                            new WorldspaceSubBlock()
                            {
                                Items = new ExtendedList <Cell>()
                                {
                                    new Cell(prototype)
                                    {
                                        Temporary = new ExtendedList <IPlaced>()
                                        {
                                            placed
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            });
            using var disp      = ConvertMod(prototype, out var mod);
            var(style, package) = GetLinkCache(mod, cacheType);
            WrapPotentialThrow(cacheType, style, () =>
            {
                package.TryResolve <ISkyrimMajorRecordGetter>(placed.FormKey, out var rec2)
                .Should().BeTrue();
                rec2.Should().Be(placed);
            });
            WrapPotentialThrow(cacheType, style, () =>
            {
                contextRetriever.TryResolveContext <ISkyrimMajorRecord, ISkyrimMajorRecordGetter>(placed.AsLink(), package, out var rec)
                .Should().BeTrue();
                rec.Record.Should().Be(placed);
            });
        }