我必须跳进一个复杂的项目,并在WEB API服务中为特定的存储库进行单元测试。数据库CRUD由实体框架处理。
private class IntegrationScope : AutoRollbackTransactionTestScope<DocumentRepository>
{
public IntegrationScope()
{
DependencyResolverMock = MockDependencyResolverFor<IResourceUrlBuilder, ResourceUrlBuilder>(new ResourceUrlBuilder());
LoggingProviderMock = new Mock<ILoggingProvider>();
// use real document micro service AutoMapper & Unity configuration
AutoMapperConfig.RegisterMaps(Mapper.Configuration, DependencyResolverMock);
UnityConfig.RegisterTypes(TestScopeContainer);
//Set the DomainId
TestId = Guid.NewGuid();
TestDocument = BuildDocument(TestId);
// get the real object
DocumentStoreDbContext = TestScopeContainer.Resolve<IDocumentDbContext>();
InstanceUnderTest = new DocumentRepository(DocumentStoreDbContext);
}
public static Web.Service.DocumentStore.Domain.Document BuildDocument(Guid documentId)
{
// Invoke GetBytes method.
byte[] array = Encoding.ASCII.GetBytes("Byte Repository Test");
return Builder<Web.Service.DocumentStore.Domain.Document>
.CreateNew()
.With(t => t.Id = documentId)
.With(t => t.Data = array)
.Build();
}
当它到达DocumentStoreDbContext行时,没有编译错误但是我得到一个运行时错误,说明对象名称无效:
在做了一些研究之后,这个错误似乎是因为数据库/表格不存在,但我可以看到它确实存在:
我做错了什么以及如何解决?
答案 0 :(得分:1)
InnerException将表格名称显示为DocumentStore.Documents
,但您的SSMS屏幕截图显示为dbo.Documents
。
这可能是原因吗?