2016-06-13 35 views
1

我不得不跳入一个复杂的项目,并在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线,没有编译错误,但我得到一个运行时错误说,对象名称是无效的:

enter image description here

做一些研究之后错误似乎是因为数据库/表不存在,但我可以看到它确实存在:

enter image description here

我在做什么错,我该如何解决?

+0

你是否检查过该表是否在实体模型中正确映射? – derloopkat

回答

1

InnerException将表名称显示为DocumentStore.Documents,但您的SSMS屏幕截图显示的是dbo.Documents

这可能是原因吗?

相关问题