public GameScreen(ContentManager content, GraphicsDeviceManager graphics, Camera camera, InputManager input) { GameState.Current = new GameState(camera, GridSize, content); mGroundPlaneRenderer = new PlaneRenderer(graphics, camera, new BasicEffect(graphics.GraphicsDevice) { TextureEnabled = true, Texture = content.Load <Texture2D>("textures/ground_sand") }); mHeroEffect = content.Load <Effect>("effects/HeroEffect").Clone(); mHeroEffectPlaneRenderer = new PlaneRenderer(graphics, camera, mHeroEffect); LoadAndSaveManager.Current = new LoadAndSaveManager(GridSize, camera, this, content); mWhitePixel = new Texture2D(graphics.GraphicsDevice, 1, 1); mWhitePixel.SetData(new[] { Color.White }); mGraphics = graphics; mCamera = camera; mInput = input; BuildManager = new BuildManager(input); BuildManagerWrapper.Init(BuildManager); BuildManagerWrapper.LoadInputManager(input); GameStateWrapper.LoadInputManager(input); input.SetSelectAction(SelectUnits); mFontMenu = content.Load <SpriteFont>("fonts/Menu"); mFontSmall = content.Load <SpriteFont>("fonts/Small"); LoadAndSaveManager.Current.LoadMap("map01", true); mStatusBarRenderer = new StatusBarRenderer(graphics.GraphicsDevice, content, camera); camera.Position = new Vector3(GridSize / -2f, GridSize * GridSize, 4 * GridSize); GameStateWrapper.StartGame(); }
public void ExistsInPrecompiledReturnsFalseIfExtensionIsUnsupported() { // Arrange var virtualPath = "~/ExistsInPrecompiledReturnsFalseIfExtensionIsUnsupported.jpeg"; var fileContent = @"<precompiledApp version=""2"" updatable=""false""/>"; var vpp = new Mock <VirtualPathProvider>(); vpp.Setup(c => c.FileExists(It.Is <string>(p => p.Equals(_precompileConfigFileName)))) .Returns(true) .Verifiable(); vpp.Setup(c => c.GetFile(It.Is <string>(p => p.Equals(_precompileConfigFileName)))) .Returns(GetFile(fileContent)) .Verifiable(); var buildManagerWrapper = new BuildManagerWrapper(vpp.Object, GetVirtualPathUtility()); // Act var exists = buildManagerWrapper.Exists(virtualPath); // Assert vpp.Verify(); Assert.False(exists); object cachedValue = HttpRuntime.Cache.Get( BuildManagerWrapper.KeyGuid + "_" + virtualPath ); Assert.NotNull(cachedValue); Assert.False( (bool)cachedValue.GetType().GetProperty("Exists").GetValue(cachedValue, null) ); }
public void IsNonPrecompiledAppReturnsTrue_VPPRegistrationChanging() { // Arrange string fileContent = @"<precompiledApp version=""2"" updatable=""false""/>"; IVirtualPathUtility pathUtility = GetVirtualPathUtility(); Mock <VirtualPathProvider> mockProvider1 = new Mock <VirtualPathProvider>(); mockProvider1.Setup(c => c.FileExists(It.Is <string>(p => p.Equals(_precompileConfigFileName)))).Returns(true).Verifiable(); mockProvider1.Setup(c => c.GetFile(It.Is <string>(p => p.Equals(_precompileConfigFileName)))).Returns(GetFile(fileContent)).Verifiable(); Mock <VirtualPathProvider> mockProvider2 = new Mock <VirtualPathProvider>(); mockProvider2.Setup(c => c.FileExists(It.Is <string>(p => p.Equals(_precompileConfigFileName)))).Returns(true).Verifiable(); mockProvider2.Setup(c => c.GetFile(It.Is <string>(p => p.Equals(_precompileConfigFileName)))).Returns(GetFile(fileContent)).Verifiable(); VirtualPathProvider provider = mockProvider1.Object; // Act; uses one VirtualPathProvider in constructor and the other when IsNonUpdatablePrecompiledApp() is called directly BuildManagerWrapper buildManagerWrapper = new BuildManagerWrapper(() => provider, pathUtility); // The moral equivalent of HostingEnvironment.RegisterVirtualPathProvider(provider2.Object) provider = mockProvider2.Object; bool isPrecompiled = buildManagerWrapper.IsNonUpdatablePrecompiledApp(); // Assert Assert.True(isPrecompiled); mockProvider1.Verify(); mockProvider1.Verify(vpp => vpp.FileExists(It.IsAny <string>()), Times.Once()); mockProvider1.Verify(vpp => vpp.GetFile(It.IsAny <string>()), Times.Once()); mockProvider2.Verify(); mockProvider2.Verify(vpp => vpp.FileExists(It.IsAny <string>()), Times.Once()); mockProvider2.Verify(vpp => vpp.GetFile(It.IsAny <string>()), Times.Once()); }
public void ExistsUsesVppIfSiteIfSiteIsPrecompiledButUpdateable() { // Arrange var virtualPath = "~/default.cshtml"; var fileContent = @"<precompiledApp version=""2"" updatable=""true""/>"; var vpp = new Mock <VirtualPathProvider>(); vpp.Setup(c => c.FileExists(It.Is <string>(p => p.Equals(_precompileConfigFileName)))) .Returns(true) .Verifiable(); vpp.Setup(c => c.GetFile(It.Is <string>(p => p.Equals(_precompileConfigFileName)))) .Returns(GetFile(fileContent)) .Verifiable(); vpp.Setup(c => c.FileExists(It.Is <string>(p => p.Equals(virtualPath)))) .Returns(true) .Verifiable(); var buildManagerWrapper = new BuildManagerWrapper(vpp.Object, GetVirtualPathUtility()); // Act var exists = buildManagerWrapper.Exists(virtualPath); // Assert vpp.Verify(); Assert.True(exists); }
public void IsNonPrecompiledAppReturnsFalseIfPrecompiledConfigFileDoesNotExist() { // Arrange var vpp = new Mock <VirtualPathProvider>(); vpp.Setup(c => c.FileExists(It.IsAny <string>())).Returns(false); var buildManagerWrapper = new BuildManagerWrapper(vpp.Object, GetVirtualPathUtility()); // Act var isPrecompiled = buildManagerWrapper.IsNonUpdatablePrecompiledApp(); // Assert Assert.False(isPrecompiled); vpp.Verify(); }
/// <summary> /// Force the BuildManager into a state where it thinks we are on a WebHost and already precompiled /// </summary> private void ConfigureBuildManager() { var fld = typeof(BuildManager).GetProperty("PreStartInitStage", BindingFlags.Static | BindingFlags.NonPublic); var psiEnumValues = typeof(BuildManager).Assembly.GetType("System.Web.Compilation.PreStartInitStage").GetEnumValues(); fld.SetValue(null, psiEnumValues.GetValue(2), null); // Skip Top Level Exceptions, just like we would in precompilation var skip = typeof(BuildManager).GetProperty("SkipTopLevelCompilationExceptions", BindingFlags.Static | BindingFlags.NonPublic); skip.SetValue(null, true, null); // RegularAppRuntimeModeInitialize BuildManagerWrapper.RegularAppRuntimeModeInitialize(); }
public void ExistsUsesVppIfSiteIfNotPrecompiled() { // Arrange var virtualPath = "~/default.cshtml"; var vpp = new Mock <VirtualPathProvider>(); vpp.Setup(c => c.FileExists(It.Is <string>(p => p.Equals(_precompileConfigFileName)))).Returns(false).Verifiable(); vpp.Setup(c => c.FileExists(It.Is <string>(p => p.Equals(virtualPath)))).Returns(true).Verifiable(); var buildManagerWrapper = new BuildManagerWrapper(vpp.Object, GetVirtualPathUtility()); // Act var exists = buildManagerWrapper.Exists(virtualPath); // Assert vpp.Verify(); Assert.True(exists); }
public void IsNonPrecompiledAppReturnsTrueIfConfigFileIsValidAndIsAppIsNotUpdatable() { // Arrange var fileContent = @"<precompiledApp version=""2"" updatable=""false""/>"; var vpp = new Mock <VirtualPathProvider>(); vpp.Setup(c => c.FileExists(It.Is <string>(p => p.Equals(_precompileConfigFileName)))).Returns(true).Verifiable(); vpp.Setup(c => c.GetFile(It.Is <string>(p => p.Equals(_precompileConfigFileName)))).Returns(GetFile(fileContent)).Verifiable(); var buildManagerWrapper = new BuildManagerWrapper(vpp.Object, GetVirtualPathUtility()); // Act var isPrecompiled = buildManagerWrapper.IsNonUpdatablePrecompiledApp(); // Assert Assert.True(isPrecompiled); vpp.Verify(); }
public void IsNonPrecompiledAppReturnsFalseIfConfigFileDoesNotContainExpectedElements() { // Arrange var fileContent = @"<?xml version=""1.0""?><configuration><appSettings></appSettings></configuration>"; var vpp = new Mock <VirtualPathProvider>(); vpp.Setup(c => c.FileExists(It.Is <string>(p => p.Equals(_precompileConfigFileName)))).Returns(true).Verifiable(); vpp.Setup(c => c.GetFile(It.Is <string>(p => p.Equals(_precompileConfigFileName)))).Returns(GetFile(fileContent)).Verifiable(); var buildManagerWrapper = new BuildManagerWrapper(vpp.Object, GetVirtualPathUtility()); // Act var isPrecompiled = buildManagerWrapper.IsNonUpdatablePrecompiledApp(); // Assert Assert.False(isPrecompiled); vpp.Verify(); }
public void IsNonPrecompiledAppReturnsFalseIfPrecompiledConfigFileIsNotValidXml() { // Arrange var vpp = new Mock <VirtualPathProvider>(); vpp.Setup(c => c.FileExists(It.Is <string>(p => p.Equals(_precompileConfigFileName)))).Returns(true).Verifiable(); var file = new Mock <VirtualFile>(); vpp.Setup(c => c.GetFile(It.Is <string>(p => p.Equals(_precompileConfigFileName)))).Returns(GetFile("some random text that is clearly not xml!")); var buildManagerWrapper = new BuildManagerWrapper(vpp.Object, GetVirtualPathUtility()); // Act var isPrecompiled = buildManagerWrapper.IsNonUpdatablePrecompiledApp(); // Assert Assert.False(isPrecompiled); vpp.Verify(); }
private static Dictionary <string, TenantData> RegisterAllSectionsEx() { Dictionary <string, TenantData> tenantDataCache = new Dictionary <string, TenantData>(StringComparer.OrdinalIgnoreCase); BuildManagerWrapper buildManager = new BuildManagerWrapper(); IEnumerable <Type> sectionTypes = TypeCache.GetFilteredTypesFromAssemblies("cportal_sections", t => typeof(SectionBase).IsAssignableFrom(t) && t.GetConstructor(new Type[0]) != null, buildManager); IEnumerable <Type> controllerTypes = TypeCache.GetFilteredTypesFromAssemblies("cportal_controllers", t => typeof(MvcController).IsAssignableFrom(t) && t.GetConstructor(new Type[0]) != null, buildManager); foreach (Type type in sectionTypes) { SectionBase sectionBase = (SectionBase)Activator.CreateInstance(type); SectionContext context = new SectionContext(); if (Compare.IsNullOrEmpty(sectionBase.Name)) { sectionBase.Name = type.Name.EndsWith("section", StringComparison.OrdinalIgnoreCase) ? type.Name.Substring(0, type.Name.Length - 7) : type.Name; } sectionBase.OnRegister(context); if (Compare.IsNullOrEmpty(sectionBase.Name)) { throw new PortalFatalException("The 'Name' property of the SectionContext has not been properly initialized or has an empty value."); } SectionData section = new SectionData(sectionBase.Name, type.Namespace); section.AddPrimaryRoute(sectionBase.DefaultRoute); foreach (Route route in context.Routes) { section.AddPrimaryRoute(route); } Match match = Expressions.TenantPathRegex.Match(type.FullName); string tenantName = match.Success ? match.Groups["TENANT"].Value : "DefaultTenant"; TenantData tenantData; if (tenantDataCache.ContainsKey(tenantName)) { tenantData = tenantDataCache[tenantName]; if (tenantData.Sections.ContainsKey(section.Name)) { throw new PortalFatalException(string.Format("A section named {0} has already been added.", section.Name)); } tenantData.Sections.Add(section.Name, section); } else { tenantData = new TenantData(); tenantData.Sections.Add(section.Name, section); tenantDataCache.Add(tenantName, tenantData); } if (match.Groups["NAMESPACE"].Length > 0) { tenantData.Namespace = match.Groups["NAMESPACE"].Value; } if (match.Groups["TENANT"].Length > 0) { tenantData.Name = match.Groups["TENANT"].Value; } foreach (string host in context.Hosts) { if (TenantHostCache.ContainsKey(host)) { throw new PortalFatalException(string.Format("The host {0} has already been added.", host)); } TenantHostCache.Add(host, tenantData.Name); } } foreach (TenantData tenantData in tenantDataCache.Values) { if (!tenantData.Sections.ContainsKey(DefaultSection.DefaultName)) { tenantData.DefaultSection = new DefaultSection(); tenantData.DefaultSection.AddPrimaryRoute(new Route("Default", "/{controller,0,1}/{action,0,1}/{arguments,*}/")); tenantData.Sections.Add(DefaultSection.DefaultName, tenantData.DefaultSection); } else { tenantData.DefaultSection = tenantData.Sections[DefaultSection.DefaultName]; } } // Register controllers with matching tenant. foreach (Type controllerType in controllerTypes) { string controllerNamespace = controllerType.Namespace; if (controllerNamespace == null) { throw new PortalFatalException("Controllers must have a namespace."); } TenantData foundTenant = controllerNamespace.Contains("Tenants") ? tenantDataCache.Values.FirstOrDefault(td => td.Namespace != null && td.Sections.Values.Any(sd => controllerNamespace.StartsWith(sd.Namespace))) : tenantDataCache["DefaultTenant"]; if (foundTenant == null) { throw new PortalFatalException("Cannot find a tenant."); } RegisterControllerEx(controllerType, foundTenant, null); } PortalSettingsSection config = (PortalSettingsSection)ConfigurationManager.GetSection(ConfigSectionName); if (config != null && config.Routes.AllowDatabaseRoutes) { InitializeDatabaseRoutes(tenantDataCache); } if (config != null && config.Setup) { RegisterControllerEx(typeof(SetupController), new TenantData(), null); } return(tenantDataCache); }
public void IsNonPrecompiledAppReturnsFalseIfPrecompiledConfigFileIsNotValidXml() { // Arrange var vpp = new Mock<VirtualPathProvider>(); vpp.Setup(c => c.FileExists(It.Is<string>(p => p.Equals(_precompileConfigFileName)))).Returns(true).Verifiable(); var file = new Mock<VirtualFile>(); vpp.Setup(c => c.GetFile(It.Is<string>(p => p.Equals(_precompileConfigFileName)))).Returns(GetFile("some random text that is clearly not xml!")); var buildManagerWrapper = new BuildManagerWrapper(vpp.Object, GetVirtualPathUtility()); // Act var isPrecompiled = buildManagerWrapper.IsNonUpdatablePrecompiledApp(); // Assert Assert.False(isPrecompiled); vpp.Verify(); }
public void IsNonPrecompiledAppReturnsFalseIfConfigFileDoesNotContainExpectedElements() { // Arrange var fileContent = @"<?xml version=""1.0""?><configuration><appSettings></appSettings></configuration>"; var vpp = new Mock<VirtualPathProvider>(); vpp.Setup(c => c.FileExists(It.Is<string>(p => p.Equals(_precompileConfigFileName)))).Returns(true).Verifiable(); vpp.Setup(c => c.GetFile(It.Is<string>(p => p.Equals(_precompileConfigFileName)))).Returns(GetFile(fileContent)).Verifiable(); var buildManagerWrapper = new BuildManagerWrapper(vpp.Object, GetVirtualPathUtility()); // Act var isPrecompiled = buildManagerWrapper.IsNonUpdatablePrecompiledApp(); // Assert Assert.False(isPrecompiled); vpp.Verify(); }
public void IsNonPrecompiledAppReturnsTrueIfConfigFileIsValidAndIsAppIsNotUpdatable() { // Arrange var fileContent = @"<precompiledApp version=""2"" updatable=""false""/>"; var vpp = new Mock<VirtualPathProvider>(); vpp.Setup(c => c.FileExists(It.Is<string>(p => p.Equals(_precompileConfigFileName)))).Returns(true).Verifiable(); vpp.Setup(c => c.GetFile(It.Is<string>(p => p.Equals(_precompileConfigFileName)))).Returns(GetFile(fileContent)).Verifiable(); var buildManagerWrapper = new BuildManagerWrapper(vpp.Object, GetVirtualPathUtility()); // Act var isPrecompiled = buildManagerWrapper.IsNonUpdatablePrecompiledApp(); // Assert Assert.True(isPrecompiled); vpp.Verify(); }
public BuildManagerWrapperTests() { buildManagerWrapper = new BuildManagerWrapper(); }
public void BuildManagerWrapperConstructorTest() { var target = new BuildManagerWrapper(); Assert.IsNotNull(target); }
public void IsNonPrecompiledAppReturnsFalseIfPrecompiledConfigFileDoesNotExist() { // Arrange var vpp = new Mock<VirtualPathProvider>(); vpp.Setup(c => c.FileExists(It.IsAny<string>())).Returns(false); var buildManagerWrapper = new BuildManagerWrapper(vpp.Object, GetVirtualPathUtility()); // Act var isPrecompiled = buildManagerWrapper.IsNonUpdatablePrecompiledApp(); // Assert Assert.False(isPrecompiled); vpp.Verify(); }
public void ExistsInPrecompiledReturnsFalseIfExtensionIsUnsupported() { // Arrange var virtualPath = "~/ExistsInPrecompiledReturnsFalseIfExtensionIsUnsupported.jpeg"; var fileContent = @"<precompiledApp version=""2"" updatable=""false""/>"; var vpp = new Mock<VirtualPathProvider>(); vpp.Setup(c => c.FileExists(It.Is<string>(p => p.Equals(_precompileConfigFileName)))).Returns(true).Verifiable(); vpp.Setup(c => c.GetFile(It.Is<string>(p => p.Equals(_precompileConfigFileName)))).Returns(GetFile(fileContent)).Verifiable(); var buildManagerWrapper = new BuildManagerWrapper(vpp.Object, GetVirtualPathUtility()); // Act var exists = buildManagerWrapper.Exists(virtualPath); // Assert vpp.Verify(); Assert.False(exists); object cachedValue = HttpRuntime.Cache.Get(BuildManagerWrapper.KeyGuid + "_" + virtualPath); Assert.NotNull(cachedValue); Assert.False((bool)cachedValue.GetType().GetProperty("Exists").GetValue(cachedValue, null)); }
public void ExistsUsesVppIfSiteIfSiteIsPrecompiledButUpdateable() { // Arrange var virtualPath = "~/default.cshtml"; var fileContent = @"<precompiledApp version=""2"" updatable=""true""/>"; var vpp = new Mock<VirtualPathProvider>(); vpp.Setup(c => c.FileExists(It.Is<string>(p => p.Equals(_precompileConfigFileName)))).Returns(true).Verifiable(); vpp.Setup(c => c.GetFile(It.Is<string>(p => p.Equals(_precompileConfigFileName)))).Returns(GetFile(fileContent)).Verifiable(); vpp.Setup(c => c.FileExists(It.Is<string>(p => p.Equals(virtualPath)))).Returns(true).Verifiable(); var buildManagerWrapper = new BuildManagerWrapper(vpp.Object, GetVirtualPathUtility()); // Act var exists = buildManagerWrapper.Exists(virtualPath); // Assert vpp.Verify(); Assert.True(exists); }
public void ExistsUsesVppIfSiteIfNotPrecompiled() { // Arrange var virtualPath = "~/default.cshtml"; var vpp = new Mock<VirtualPathProvider>(); vpp.Setup(c => c.FileExists(It.Is<string>(p => p.Equals(_precompileConfigFileName)))).Returns(false).Verifiable(); vpp.Setup(c => c.FileExists(It.Is<string>(p => p.Equals(virtualPath)))).Returns(true).Verifiable(); var buildManagerWrapper = new BuildManagerWrapper(vpp.Object, GetVirtualPathUtility()); // Act var exists = buildManagerWrapper.Exists(virtualPath); // Assert vpp.Verify(); Assert.True(exists); }
public void IsNonPrecompiledAppReturnsTrue_VPPRegistrationChanging() { // Arrange string fileContent = @"<precompiledApp version=""2"" updatable=""false""/>"; IVirtualPathUtility pathUtility = GetVirtualPathUtility(); Mock<VirtualPathProvider> mockProvider1 = new Mock<VirtualPathProvider>(); mockProvider1.Setup(c => c.FileExists(It.Is<string>(p => p.Equals(_precompileConfigFileName)))).Returns(true).Verifiable(); mockProvider1.Setup(c => c.GetFile(It.Is<string>(p => p.Equals(_precompileConfigFileName)))).Returns(GetFile(fileContent)).Verifiable(); Mock<VirtualPathProvider> mockProvider2 = new Mock<VirtualPathProvider>(); mockProvider2.Setup(c => c.FileExists(It.Is<string>(p => p.Equals(_precompileConfigFileName)))).Returns(true).Verifiable(); mockProvider2.Setup(c => c.GetFile(It.Is<string>(p => p.Equals(_precompileConfigFileName)))).Returns(GetFile(fileContent)).Verifiable(); VirtualPathProvider provider = mockProvider1.Object; // Act; uses one VirtualPathProvider in constructor and the other when IsNonUpdatablePrecompiledApp() is called directly BuildManagerWrapper buildManagerWrapper = new BuildManagerWrapper(() => provider, pathUtility); // The moral equivalent of HostingEnvironment.RegisterVirtualPathProvider(provider2.Object) provider = mockProvider2.Object; bool isPrecompiled = buildManagerWrapper.IsNonUpdatablePrecompiledApp(); // Assert Assert.True(isPrecompiled); mockProvider1.Verify(); mockProvider1.Verify(vpp => vpp.FileExists(It.IsAny<string>()), Times.Once()); mockProvider1.Verify(vpp => vpp.GetFile(It.IsAny<string>()), Times.Once()); mockProvider2.Verify(); mockProvider2.Verify(vpp => vpp.FileExists(It.IsAny<string>()), Times.Once()); mockProvider2.Verify(vpp => vpp.GetFile(It.IsAny<string>()), Times.Once()); }