2016-11-22 17 views
-1

を与えます。ユニットテストは、私は</p> <p>インタフェースを持って何IConvertible例外に

ユニットテスト:

static Guid docGuid = Guid.NewGuid(); 

[TestMethod] 
public async Task TestMethod2() 
{ 
    var jObject = new JObject { { "id", docGuid }, { "studentId", "1" }, { "courseId", "Ph" } }; 

    // Arrange 
    var docClient = new ShimDocumentClient(); 
    ShimDocumentClient.AllInstances.CreateDocumentAsyncUriObjectRequestOptionsBoolean = 
     (instance, uri, document, options, disableAutomaticGeneration) => Task.FromResult(new ResourceResponse<Document>(new Document() { Id = docGuid.ToString() })); 

    // Act 
    var documentRepository = new DocDbRepository(endPointUri, accountKey, dbName, collectionName); 
    try{ 
    var response = await documentRepository.UpdateDocumentAsync(jObject).ConfigureAwait(false); 
    } 
    catch(Exception ex){} 

    // Assert 
    Assert.AreEqual(response.Count, 1); 
} 

はテストがこのメッセージにUpdateDocumentAsync部分と終了を超えない:

at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider) 
at Newtonsoft.Json.Linq.Extensions.Convert[T,U](T token) 
at Newtonsoft.Json.Linq.Extensions.Value[T,U](IEnumerable`1 value) 
at Newtonsoft.Json.Linq.Extensions.Value[U](IEnumerable`1 value) 
at Common.DataAccess.DocumentDb.DocDbRepository.<UpdateDocumentAsync>d__12.MoveNext() in C:\Common\Common.DataAccess.DocumentDb\DocDbRepository.cs:line 196 
--- End of stack trace from previous location where exception was thrown --- 
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) 
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) 
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult() 
at Common.DataAccess.DocumentDb.Tests.DocDbUtilityTests.<TestMethod2>d__9.MoveNext() in C:\Common\Common.DataAccess.DocumentDb.Tests\DocDbUtilityTests.cs:line 113 

これは偽物のフレームワークと私の最初の時間です。 何か助けていただければ幸いです。

ありがとうございます。よろしくです。 よろしくお願いします。

+0

例外はどの行で発生しましたか?完全な例外の詳細を含めると便利です。 –

+0

更新された例外の詳細と行が表示されます。 – Codehelp

答えて

0

これは、シリアライズコードに問題があるようです。具体的には、この文は:

updatedDocument["id"].Value<string>() 

Value拡張メソッドは、ソースがGuidによって実装されていないIConvertibleインタフェースを実装することを必要とするように思われます。

関連する問題