public void LogError_delegates_to_the_loader_session() { var mockLogger = new Mock <LoadMessageLogger>(null); mockLogger .Setup(m => m.CreateErrorMessageWithTypeSpecificLoadLogs(It.IsAny <string>(), It.IsAny <EdmType>())) .Returns("The Message"); var mockSession = new Mock <ObjectItemLoadingSessionData>(); mockSession.Setup(m => m.LoadMessageLogger).Returns(mockLogger.Object); var edmItemErrors = new List <EdmItemError>(); mockSession.Setup(m => m.EdmItemErrors).Returns(edmItemErrors); var loader = new ObjectItemConventionAssemblyLoader(typeof(object).Assembly, mockSession.Object); var factory = new ObjectItemConventionAssemblyLoader.ConventionOSpaceTypeFactory(loader); var entityType = new EntityType("E", "N", DataSpace.CSpace); factory.LogError("Cheese", entityType); mockLogger.Verify(m => m.CreateErrorMessageWithTypeSpecificLoadLogs("Cheese", entityType)); Assert.Equal("The Message", edmItemErrors.Select(e => e.Message).Single()); }
internal static ObjectItemAssemblyLoader CreateLoader(Assembly assembly, ObjectItemLoadingSessionData sessionData) { ImmutableAssemblyCacheEntry cacheEntry; // KnownAssembly -> NoOp // Inside the LockedAssemblyCache means it is an attribute based assembly -> Cachedassembly // Inside the OcCache on EdmItemCollection -> cachedassembly // If none of above, setup the LoaderFactory based on the current assembly and EdmItemCollection if (sessionData.KnownAssemblies.Contains(assembly, sessionData.ObjectItemAssemblyLoaderFactory, sessionData.EdmItemCollection)) { return(new ObjectItemNoOpAssemblyLoader(assembly, sessionData)); } else if (sessionData.LockedAssemblyCache.TryGetValue(assembly, out cacheEntry)) { if (sessionData.ObjectItemAssemblyLoaderFactory == null) { if (cacheEntry.TypesInAssembly.Count != 0) { // we are loading based on attributes now sessionData.ObjectItemAssemblyLoaderFactory = ObjectItemAttributeAssemblyLoader.Create; } // if types in assembly are 0, don't commit to any loader yet } else if (sessionData.ObjectItemAssemblyLoaderFactory != ObjectItemAttributeAssemblyLoader.Create) { // we were loading in convention mode, and ran into an assembly that can't be loaded by convention // we know this because all cached assemblies are attribute based at the moment. sessionData.EdmItemErrors.Add( new EdmItemError(Strings.Validator_OSpace_Convention_AttributeAssemblyReferenced(assembly.FullName))); } return(new ObjectItemCachedAssemblyLoader(assembly, cacheEntry, sessionData)); } else if (sessionData.EdmItemCollection != null && sessionData.EdmItemCollection.ConventionalOcCache.TryGetConventionalOcCacheFromAssemblyCache( assembly, out cacheEntry)) { sessionData.ObjectItemAssemblyLoaderFactory = ObjectItemConventionAssemblyLoader.Create; return(new ObjectItemCachedAssemblyLoader(assembly, cacheEntry, sessionData)); } else if (sessionData.ObjectItemAssemblyLoaderFactory == null) { if (ObjectItemAttributeAssemblyLoader.IsSchemaAttributePresent(assembly)) { sessionData.ObjectItemAssemblyLoaderFactory = ObjectItemAttributeAssemblyLoader.Create; } else if (ObjectItemConventionAssemblyLoader.SessionContainsConventionParameters(sessionData)) { sessionData.ObjectItemAssemblyLoaderFactory = ObjectItemConventionAssemblyLoader.Create; } } if (sessionData.ObjectItemAssemblyLoaderFactory != null) { return(sessionData.ObjectItemAssemblyLoaderFactory(assembly, sessionData)); } return(new ObjectItemNoOpAssemblyLoader(assembly, sessionData)); }
public void ReferenceResolutions_delegates_to_the_loader() { var loader = new ObjectItemConventionAssemblyLoader(typeof(object).Assembly, new ObjectItemLoadingSessionData()); var factory = new ObjectItemConventionAssemblyLoader.ConventionOSpaceTypeFactory(loader); Assert.NotNull(factory.ReferenceResolutions); Assert.Same(factory.ReferenceResolutions, factory.ReferenceResolutions); }
public void LoadedTypes_delegates_to_loader_session() { var mockSession = new Mock<ObjectItemLoadingSessionData>(); var dictionary = new Dictionary<string, EdmType>(); mockSession.Setup(m => m.TypesInLoading).Returns(dictionary); var loader = new ObjectItemConventionAssemblyLoader(typeof(object).Assembly(), mockSession.Object); var factory = new ObjectItemConventionAssemblyLoader.ConventionOSpaceTypeFactory(loader); Assert.Same(dictionary, factory.LoadedTypes); }
public void LoadedTypes_delegates_to_loader_session() { var mockSession = new Mock <ObjectItemLoadingSessionData>(); var dictionary = new Dictionary <string, EdmType>(); mockSession.Setup(m => m.TypesInLoading).Returns(dictionary); var loader = new ObjectItemConventionAssemblyLoader(typeof(object).Assembly, mockSession.Object); var factory = new ObjectItemConventionAssemblyLoader.ConventionOSpaceTypeFactory(loader); Assert.Same(dictionary, factory.LoadedTypes); }
public void LogLoadMessage_delegates_to_the_loader_session() { var mockLogger = new Mock<LoadMessageLogger>(null); var mockSession = new Mock<ObjectItemLoadingSessionData>(); mockSession.Setup(m => m.LoadMessageLogger).Returns(mockLogger.Object); var loader = new ObjectItemConventionAssemblyLoader(typeof(object).Assembly, mockSession.Object); var factory = new ObjectItemConventionAssemblyLoader.ConventionOSpaceTypeFactory(loader); var entityType = new EntityType("E", "N", DataSpace.CSpace); factory.LogLoadMessage("Cheese", entityType); mockLogger.Verify(m => m.LogLoadMessage("Cheese", entityType)); }
internal static ObjectItemAssemblyLoader CreateLoader( Assembly assembly, ObjectItemLoadingSessionData sessionData) { if (sessionData.KnownAssemblies.Contains(assembly, (object)sessionData.ObjectItemAssemblyLoaderFactory, sessionData.EdmItemCollection)) { return((ObjectItemAssemblyLoader) new ObjectItemNoOpAssemblyLoader(assembly, sessionData)); } ImmutableAssemblyCacheEntry cacheEntry; if (sessionData.LockedAssemblyCache.TryGetValue(assembly, out cacheEntry)) { if (sessionData.ObjectItemAssemblyLoaderFactory == null) { if (cacheEntry.TypesInAssembly.Count != 0) { sessionData.ObjectItemAssemblyLoaderFactory = new Func <Assembly, ObjectItemLoadingSessionData, ObjectItemAssemblyLoader>(ObjectItemAttributeAssemblyLoader.Create); } } else if (sessionData.ObjectItemAssemblyLoaderFactory != new Func <Assembly, ObjectItemLoadingSessionData, ObjectItemAssemblyLoader>(ObjectItemAttributeAssemblyLoader.Create)) { sessionData.EdmItemErrors.Add(new EdmItemError(Strings.Validator_OSpace_Convention_AttributeAssemblyReferenced((object)assembly.FullName))); } return((ObjectItemAssemblyLoader) new ObjectItemCachedAssemblyLoader(assembly, cacheEntry, sessionData)); } if (sessionData.EdmItemCollection != null && sessionData.EdmItemCollection.ConventionalOcCache.TryGetConventionalOcCacheFromAssemblyCache(assembly, out cacheEntry)) { sessionData.ObjectItemAssemblyLoaderFactory = new Func <Assembly, ObjectItemLoadingSessionData, ObjectItemAssemblyLoader>(ObjectItemConventionAssemblyLoader.Create); return((ObjectItemAssemblyLoader) new ObjectItemCachedAssemblyLoader(assembly, cacheEntry, sessionData)); } if (sessionData.ObjectItemAssemblyLoaderFactory == null) { if (ObjectItemAttributeAssemblyLoader.IsSchemaAttributePresent(assembly)) { sessionData.ObjectItemAssemblyLoaderFactory = new Func <Assembly, ObjectItemLoadingSessionData, ObjectItemAssemblyLoader>(ObjectItemAttributeAssemblyLoader.Create); } else if (ObjectItemConventionAssemblyLoader.SessionContainsConventionParameters(sessionData)) { sessionData.ObjectItemAssemblyLoaderFactory = new Func <Assembly, ObjectItemLoadingSessionData, ObjectItemAssemblyLoader>(ObjectItemConventionAssemblyLoader.Create); } } if (sessionData.ObjectItemAssemblyLoaderFactory != null) { return(sessionData.ObjectItemAssemblyLoaderFactory(assembly, sessionData)); } return((ObjectItemAssemblyLoader) new ObjectItemNoOpAssemblyLoader(assembly, sessionData)); }
public void LogLoadMessage_delegates_to_the_loader_session() { var mockLogger = new Mock <LoadMessageLogger>(null); var mockSession = new Mock <ObjectItemLoadingSessionData>(); mockSession.Setup(m => m.LoadMessageLogger).Returns(mockLogger.Object); var loader = new ObjectItemConventionAssemblyLoader(typeof(object).Assembly, mockSession.Object); var factory = new ObjectItemConventionAssemblyLoader.ConventionOSpaceTypeFactory(loader); var entityType = new EntityType("E", "N", DataSpace.CSpace); factory.LogLoadMessage("Cheese", entityType); mockLogger.Verify(m => m.LogLoadMessage("Cheese", entityType)); }
public void LogError_delegates_to_the_loader_session() { var mockLogger = new Mock<LoadMessageLogger>(null); mockLogger .Setup(m => m.CreateErrorMessageWithTypeSpecificLoadLogs(It.IsAny<string>(), It.IsAny<EdmType>())) .Returns("The Message"); var mockSession = new Mock<ObjectItemLoadingSessionData>(); mockSession.Setup(m => m.LoadMessageLogger).Returns(mockLogger.Object); var edmItemErrors = new List<EdmItemError>(); mockSession.Setup(m => m.EdmItemErrors).Returns(edmItemErrors); var loader = new ObjectItemConventionAssemblyLoader(typeof(object).Assembly(), mockSession.Object); var factory = new ObjectItemConventionAssemblyLoader.ConventionOSpaceTypeFactory(loader); var entityType = new EntityType("E", "N", DataSpace.CSpace); factory.LogError("Cheese", entityType); mockLogger.Verify(m => m.CreateErrorMessageWithTypeSpecificLoadLogs("Cheese", entityType)); Assert.Equal("The Message", edmItemErrors.Select(e => e.Message).Single()); }
public ConventionOSpaceTypeFactory(ObjectItemConventionAssemblyLoader loader) { DebugCheck.NotNull(loader); _loader = loader; }
public ConventionOSpaceTypeFactory(ObjectItemConventionAssemblyLoader loader) { this._loader = loader; }