第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何防止在單元測試中自動包含導(dǎo)航屬性

如何防止在單元測試中自動包含導(dǎo)航屬性

C#
慕蓋茨4494581 2023-08-20 10:21:40
我目前正在開發(fā)一個應(yīng)用程序商店風(fēng)格的 API,它具有以下實體(以及許多其他實體,但與問題無關(guān)):App(與 AppRevision 的一對多關(guān)系 - 包含 IEnumerable 屬性)應(yīng)用程序修訂版安裝我遇到了一個奇怪的問題,其中 EF 的行為在單元測試中與實際運行 API 時不同,因為在單元測試時會自動包含導(dǎo)航屬性。從我的命令處理程序中獲取以下代碼片段:// MyComp<div id=“@Id” @attributes=“InputAttributes”></div>@code {    [Parameter]     public string Id { get; set; }     [Parameter(CaptureUnmatchedValues = true)]    public Dictionary<string, object> InputAttributes { get; set; }}根據(jù)上面的示例定義參數(shù)將使其收集組件上定義的與任何現(xiàn)有聲明的參數(shù)不匹配的任何屬性。用法:<MyComp Id=“foo” class=“myclass” />將呈現(xiàn):<div id=“foo” class=“myclass”></div>
查看完整描述

1 回答

?
慕容3067478

TA貢獻1773條經(jīng)驗 獲得超3個贊

對于將來遇到這篇文章的任何人,解決方案是根據(jù)原始問題的評論,使用單獨的上下文來播種測試數(shù)據(jù)并稍后在測試中獲取數(shù)據(jù):


[Fact]

public async void Handle_ShouldAddInstallationRecord_WhenDataIsValid()

{

    Guid testGuid = Guid.NewGuid();


    CreateInstallationCommand command = new CreateInstallationCommand(testGuid, "ABC", "abc@abc.com", null);


    using (TestContextFactory contextFactory = new TestContextFactory())

    {

        using (TestContext seedContext = contextFactory.CreateTestContext())

        {

            seedContext.Apps.Add(new App() { Id = testGuid });

            seedContext.AppRevisions.Add(new AppRevision() { Id = Guid.NewGuid(), AppId = testGuid, Status = AppRevisionStatus.Approved, IsListed = true });

            await seedContext.SaveChangesAsync();

        }


        using (TestContext getContext = contextFactory.CreateTestContext())

        {

            CreateInstallationCommandHandler handler = new CreateInstallationCommandHandler(getContext);


            CommandResult result = await handler.Handle(command, new CancellationToken());


            Assert.True(result);

            Assert.Single(getContext.Installations);

        }

    }

}


查看完整回答
反對 回復(fù) 2023-08-20
  • 1 回答
  • 0 關(guān)注
  • 140 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號