Posts

How to unit test a .NET Core project using xUnit

Image
Basically the same instructions as given in the Microsoft site , which I attempt to make yet simpler for the beginner to get started. Another useful link: https://xunit.net/docs/getting-started/netfx/visual-studio#write-first-tests Step 1: Create a directory for the test project Create a new directory for the test project. Navigate to that directory Create a new solution using the command: dotnet new sln Step 2: Create a new class library In the current directory create a new folder called Example. Navigate to the directory Example and run the command to create a new class library: dotnet new classlib. Step 3: Create an example test class Rename Class1.cs to Example.cs. Update the code in Example.cs to produce a function to test if an integer is even: [code language="csharp"] using System; namespace Example { public class ExampleService { public bool IsEven(int val) { return val % 2 == 0; } }...

How to use alternate portrait and landscape orientations in a Word document

Image
Some instructions on how to use alternate portrait and landscape orientations in a Word document. Just as a simple illustration: suppose we want to configure a 3-page Word document to have a first page with portrait-style orientation, followed by a second page with landscape orientation and then a third page that is in portrait mode once again. So our Word document is currently structured as follows: Page 1 Contains some text that is easily accommodated by the portrait page orientation: [caption id="attachment_8840" align="alignnone" width="713"] portrait and landscape[/caption] Page 2 Contains text plus a table that is too wide to fit on a page with portrait orientation. This page (and only this page) we wish to change to landscape orientation in order to fit the table: Page 3 And the third page that we wish to keep as portrait again: To change page 2 to landscape without impacting pages 1 and 3, go to page 2, and select the t...

Getting started with SQL Server Management Studio

Image
A few instructions on how to fire up SQL Server Management Studio (SSMS) in order to create a database, create a database table and perform various operations Creating a new database Open SSMS, right-click on Databases and select New Database... Give the database a name ('People' in this example) and select OK: Creating a new database table In the Object Explorer, select the database you created, right-click on Tables and select Table... (or New Table... in more recent versions of SSMS) You can fill in the column names and their data types like so Save the table by selecting Ctrl+S or via File > Save Table Making a column a primary key Select the column (in this case the column id) Right click and select Set Primary Key: So that the symbol for the primary key then appears in the column as shown: Also make sure the column property 'Is Identity' is set to Yes for id Unable to modify the database table? In some versions of SS...

How to hide the default context menu in the CefSharp Chromium browser in WPF

Image
https://www.technical-recipes.com/2016/using-the-cefsharp-chromium-web-browser-in-wpf-xaml/ An example of not only how to use  CefSharp.WinForms.ChromiumWebBrowser  version 67 in a Visual Studio WPF application, but to hide the default context menu that show up on right-clicking the browser area.  See the following post for a general description of how to use CefSharp in Visual Studio: Step 1: Create a new Visual Studio project To start with create a new Visual Studio WPF application: Step 2: Install the necessary libraries Obtain CefSharp Select Tool > NuGet Package manager > Package Manager Console. Use the command: PM> install-package CefSharp.Wpf Now add the dll references.    Right-click on References, select ‘Add reference’ When the dialog appears, select the Browse button. Navigate to the ‘packages’ folder that NuGet has installed to your Visual Studio project. For this project I’m choos...

How to dynamically resize WPF tab items to fit available width

Image
Useful StackOverflow link: https://stackoverflow.com/questions/28496809/wpf-flexible-tabcontrol-header Step 1: Create a new WPF application Step 2: Create an example adjustable window with tab items Update the MainWindow.xaml to create a grid with a column section containing the tab items and a grid splitter to adjust the width of the tab item area. MainWindow.xaml We will get on to the step of creating the tab control style in a minute... [code language="xml"] <Window x:Class="TabItemResize.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" Title="MainWindow" Height="450" Width="700...

How to wrap text around another control in WPF

Image
First things first, credit where it's due: the StackOverflow link I eventually found that enabled me to solve this problem: https://stackoverflow.com/questions/3339051/wrapping-text-around-an-image-or-linking-two-textblocks-in-c-sharp-wpf The trick is not use use a TextBlock as conventional wisdom would indicate, but to use a FlowDocument to achieve this kind of layout. For future reference (I am going to need something like this fairly soon), try the following XAML snippet and the resulting WPF app screenshot to demonstrate how to display a button in the top right hand corner with text wrapped around it. In my real-world apps I am using the MVVM pattern with all sorts of bindings and events etc, but this should hopefully enable me to get there: MainWindow.xaml [code language="xml"] <Window x:Class="WpfApp1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.mi...

Removing duplicate lines in a text file using notepad++

Image
First ensure the TextFx plugin has been installed in your version of notepad++. Some example text: I then copy and paste that block of text to ensure there are duplicate lines: Removing the duplicates involves THREE steps: 1. If you have not already done so, ensure the appropriate TextFX plugin is checked. Select TextFX > TextFX Tools > Sort outputs only UNIQUE at column lines: 2. Select ALL of your text (select Control + A) 3. Select TextFX > TextFX Tools > Sort lines case sensitive (at column): See that the duplicate lines have been identified and removed: