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線,沒有編譯錯誤,但我得到一個運行時錯誤說,對象名稱是無效的:
做一些研究之後錯誤似乎是因爲數據庫/表不存在,但我可以看到它確實存在:
我在做什麼錯,我該如何解決?
你是否檢查過該表是否在實體模型中正確映射? – derloopkat