public void CanHandleInvalidKeysWithoutException() { var container = new GwnClassBase().GetContainer(); var appSettings = container.Resolve<IAppSettings>(); Assert.IsNull(appSettings.GetValue("InvalidKey")); }
public void CanResolveBaseClassProperties() { var container = new GwnClassBase().GetContainer(); var appSettings = container.Resolve<IAppSettings>(); Assert.AreEqual(0, appSettings.TraceLevel, "Was expecting default TraceLevel=0"); Assert.AreEqual("Dev", appSettings.Environment, "Was expecting default environment of Dev"); var logger = container.Resolve<IGwnLogger>(); Assert.IsNotNull(logger, "Was expecting a logger"); }
public void CanOverrideAppSettingValues() { var container = new GwnClassBase().GetContainer(); var appSettings = container.Resolve<IAppSettings>(); const string key = "Test1"; appSettings.SetValue(key, "Hello"); Assert.AreEqual("Hello", appSettings.GetValue(key)); appSettings.SetValue(key, "World"); Assert.AreEqual("World", appSettings.GetValue(key)); }
public void CanResolveIAppSettings() { var container = new GwnClassBase().GetContainer(); var appSettings = container.Resolve<IAppSettings>(); const string key1 = "Test1"; const string key2 = "Test2"; appSettings.SetValue(key1, "Hello"); appSettings.SetValue(key2, "World"); // Request singleton instance and assert values // properly saved var settings = container.Resolve<IAppSettings>(); Assert.AreEqual("Hello", settings.GetValue(key1)); Assert.AreEqual("World", settings.GetValue(key2)); }
/// <summary> /// Invoked when the application is launched normally by the end user. /// Other entry points will be used such as when the application is /// launched to open a specific file. /// <remarks> /// <para> /// To support the MVP-VM pattern an entry point to bootstrap the /// framework is required. We'll use the <b>Frame.Loaded</b> event (ref /// Figure 2) as it indicates "Occurs when a FrameworkElement has been /// constructed and added to the object tree, and is ready for /// interaction". /// </para><para> /// This provides our hook so that we can get an instance of the page /// which implements IShell. The IShell interface has a property /// <b>Bootstrapper</b> which is a local class, within the project, /// permitting you to set AppSettings and Modules in container. <br/> /// <br/><img src="{ImageFolder}/Images/010/010/020/SS010-010-020-030.png" /> /// <br/> Figure 1. MainPage IShell implementation of Bootstrapper /// </para> /// </remarks> /// <br/><img src="{ImageFolder}/Images/010/010/020/SD010-010-020-010.png" /> /// Figure 2. Sequence diagram for Bootstrapper /// <para> /// Reference the <see cref="Bootstrapper"/> for more information. /// </para> /// </summary> /// <param name="e">Details about the launch request and process.</param> protected override void OnLaunched(LaunchActivatedEventArgs e) { #if DEBUG if (System.Diagnostics.Debugger.IsAttached) { this.DebugSettings.EnableFrameRateCounter = true; } #endif Frame rootFrame = Window.Current.Content as Frame; // Do not repeat app initialization when the Window already has // content, just ensure that the window is active if (rootFrame == null) { // Create a Frame to act as the navigation context and // navigate to the first page rootFrame = new Frame(); // BillKrat.2016.02.12 - Code required to launch // bootstrapper configured in Shell // Step 1: apply the IShell interface to MainPage.cs and // implement Bootstrapper property // Step 2: subscribe to the rootFrame.Loaded event so that // we'll be notified when page instances is ready rootFrame.Loaded += (sender, args) => { // Step 3: get shell instance and cast to IShell var page = ((Frame)sender).Content as IShell; if (page != null) // We're done if not IShell { var errorGrid = page.FindName<Grid>("ErrorRegion"); var errorText = page.FindName<TextBlock>("ErrorTextBlock"); Guard.ArgumentNotNull(errorText, "OnLaunched.Loaded: ErrorTextBlock"); Guard.ArgumentNotNull(errorGrid, "OnLaunched.Loaded: ErrorRegion"); errorGrid.Visibility = Visibility.Collapsed; // Pass in page as argument (will be added to // container so it can be retrieved with IShell) var presenterArgs = new PresenterEventArgs {MainPage = page}; // Step 4: Get container instance // Step 5: Get Presenter instance // Step 6: Initialize Presenter passing in args var container = new GwnClassBase() .GetContainer(); // 4. // Subscribe to ErrorEvent and handle them by // displaying them in the bottom Grid within the // MainPage. container .Resolve<EventManager>() .GetEvent<ErrorEvent>() .Subscribe(err => { errorGrid.Visibility = Visibility.Visible; errorText.Text = err.ToString(); }); // Resolve presenter and initialize container .Resolve<MainPresenter>() // 5. .Initialize(this, presenterArgs); // 6. } }; // BillKrat.2016.02.12 - End of code segment ------------------------- rootFrame.NavigationFailed += OnNavigationFailed; if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) { //TODO: Load state from previously suspended application } // Place the frame in the current Window Window.Current.Content = rootFrame; } if (rootFrame.Content == null) { // When the navigation stack isn't restored navigate to the first page, // configuring the new page by passing required information as a navigation // parameter rootFrame.Navigate(typeof(MainPage), e.Arguments); } // Ensure the current window is active Window.Current.Activate(); }