私はVisual Studioで単純なAzure関数アプリケーションを使用しています。私は、データをローカルに保存するゲーム作成機能を単体テストしようとしています。Azure関数ユニットテスト資格証明
私は、Visual Studioのテストとして機能CreateGameTest
を実行しようとしていると私は、このことから次のように出力
[31/10/2017 10:36:46 Informational] ------ Run test started ------
[31/10/2017 10:36:47 Informational] [xUnit.net 00:00:00.2509695] Starting: LemonadeGame.Test
[31/10/2017 10:36:47 Error] [xUnit.net 00:00:00.7378276] LemonadeGame.Test.CreateGameTest.TestDoesCreateGame [FAIL]
[31/10/2017 10:36:47 Informational] [xUnit.net 00:00:00.7392995] System.InvalidOperationException : Cannot find account information inside Uri 'http://127.0.0.1:10002/devstoreaccount1'
[31/10/2017 10:36:47 Informational] [xUnit.net 00:00:00.7403799] Stack Trace:
[31/10/2017 10:36:47 Informational] [xUnit.net 00:00:00.7408970] at Microsoft.WindowsAzure.Storage.Core.Util.NavigationHelper.GetContainerNameFromContainerAddress(Uri uri, Nullable`1 usePathStyleUris)
[31/10/2017 10:36:47 Informational] [xUnit.net 00:00:00.7413043] at Microsoft.WindowsAzure.Storage.Table.CloudTable.ParseQueryAndVerify(StorageUri address, StorageCredentials credentials)
[31/10/2017 10:36:47 Informational] [xUnit.net 00:00:00.7418036] at Microsoft.WindowsAzure.Storage.Table.CloudTable..ctor(StorageUri tableAddress, StorageCredentials credentials)
[31/10/2017 10:36:47 Informational] [xUnit.net 00:00:00.7421637] C:\Users\Ben Helstrip\Documents\Visual Studio 2017\azure-server-lemonade-game\LemonadeGame\LemonadeGame.Test\CreateGameTest.cs(46,0): at LemonadeGame.Test.CreateGameTest.TestDoesCreateGame()
[31/10/2017 10:36:47 Informational] [xUnit.net 00:00:00.7505642] Finished: LemonadeGame.Test
[31/10/2017 10:36:47 Informational] ========== Run test finished: 1 run (0:00:00.7973298) ==========
を受け取り、私が、私は、ローカルでこれを実行するために、いくつかのアカウント情報が欠落していますことが表示されますアカウントの名前はdevstoreaccount
、ローカルの開発にはEby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==
のアカウントキーを指定しています。
このテストを実行するために追加する必要があるものはありますか?
私のユニットテスト
using System;
using System.Net;
using System.Net.Http;
using System.Web.Http.Results;
using LemonadeGame.Models;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Auth;
using Microsoft.WindowsAzure.Storage.Table;
using Should.Fluent;
using Xunit;
namespace LemonadeGame.Test
{
public class CreateGameTest
{
static void Main(string[] args)
{
var game = new Game
{
GameName = "Ben.Helstrip",
NumberOfPlayers = 5,
AutoNextRound = false,
PartitionKey = "game",
Timestamp = DateTimeOffset.Now
};
}
[Fact]
public void TestDoesCreateGame()
{
var request = new HttpRequestMessage
{
Content = new StringContent("{'name': 'Bill'}", System.Text.Encoding.UTF8, "application/json"),
};
request.SetConfiguration(new System.Web.Http.HttpConfiguration());
var storageCredentials = new StorageCredentials("devstoreaccount1", "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==");
var storageUri = new StorageUri(new Uri("http://127.0.0.1:10002/devstoreaccount1"));
var game = new Game
{
GameName = "Ben",
NumberOfPlayers = 5,
AutoNextRound = false,
PartitionKey = "game",
Timestamp = DateTimeOffset.Now
};
var result = FunctionCreateGame.Run(game, new CloudTable(storageUri, storageCredentials), new FakeTraceWriter());
result.StatusCode.Should().Equal(HttpStatusCode.Accepted);
}
}
}
あなたはAzureストレージエミュレータで使用するために探している取り組みます。それが動作していることを確認しましたか?そして、このテストの外でこれらの設定で初期化を受け入れますか?エラーが発生した場所に表示されます – jeffhollan