单元测试提供了IConvertible例外

单元测试提供了IConvertible例外

问题描述:

我有什么单元测试提供了IConvertible例外

接口:

public interface IDocDbRepository 
{ 
    Task<JObject> UpdateDocumentAsync(JObject updatedDocument); 
} 

实施:

public async Task<JObject> UpdateDocumentAsync(JObject updatedDocument) 
{ 
    if (updatedDocument == null) 
    { 
     throw new ArgumentNullException(nameof(updatedDocument)); 
    } 

    var response = await this.documentDBClient.ReplaceDocumentAsync(UriFactory.CreateDocumentUri(this.dbName, this.collectionName, updatedDocument["id"].Value<string>()), updatedDocument).ConfigureAwait(false); 
    return JObject.Parse(response.Resource.ToString()); 
} 

例外在AWAIT线发生。

单元测试:

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

这似乎是您的序列化代码的问题。具体地,这种说法:

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

Value扩展方法似乎需要使源实现IConvertible接口,该接口不被Guid实现。