HTML Comments Tag | Docs With Examples
Source link
بلاگ
-
HTML Comments Tag | Docs With Examples
-
HTML Background Color | Docs With Examples
HTML Background Color | Docs With Examples
Source link -
Updating to .NET 8, updating to IHostBuilder, and running Playwright Tests within NUnit headless or headed on any OS
I’ve been doing not just Unit Testing for my sites but full on Integration Testing and Browser Automation Testing as early as 2007 with Selenium. Lately, however, I’ve been using the faster and generally more compatible Playwright. It has one API and can test on Windows, Linux, Mac, locally, in a container (headless), in my CI/CD pipeline, on Azure DevOps, or in GitHub Actions.
For me, it’s that last moment of truth to make sure that the site runs completely from end to end.
I can write those Playwright tests in something like TypeScript, and I could launch them with node, but I like running end unit tests and using that test runner and test harness as my jumping off point for my .NET applications. I’m used to right clicking and “run unit tests” or even better, right click and “debug unit tests” in Visual Studio or VS Code. This gets me the benefit of all of the assertions of a full unit testing framework, and all the benefits of using something like Playwright to automate my browser.
In 2018 I was using WebApplicationFactory and some tricky hacks to basically spin up ASP.NET within .NET (at the time) Core 2.1 within the unit tests and then launching Selenium. This was kind of janky and would require to manually start a separate process and manage its life cycle. However, I kept on with this hack for a number of years basically trying to get the Kestrel Web Server to spin up inside of my unit tests.
I’ve recently upgraded my main site and podcast site to .NET 8. Keep in mind that I’ve been moving my websites forward from early early versions of .NET to the most recent versions. The blog is happily running on Linux in a container on .NET 8, but its original code started in 2002 on .NET 1.1.
Now that I’m on .NET 8, I scandalously discovered (as my unit tests stopped working) that the rest of the world had moved from IWebHostBuilder to IHostBuilder five version of .NET ago. Gulp. Say what you will, but the backward compatibility is impressive.
As such my code for Program.cs changed from this
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>();to this:
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args).
ConfigureWebHostDefaults(WebHostBuilder => WebHostBuilder.UseStartup<Startup>());Not a major change on the outside but tidies things up on the inside and sets me up with a more flexible generic host for my web app.
My unit tests stopped working because my Kestral Web Server hack was no longer firing up my server.
Here is an example of my goal from a Playwright perspective within a .NET NUnit test.
[Test]
public async Task DoesSearchWork()
{
await Page.GotoAsync(Url);await Page.Locator("#topbar").GetByRole(AriaRole.Link, new() { Name = "episodes" }).ClickAsync();
await Page.GetByPlaceholder("search and filter").ClickAsync();
await Page.GetByPlaceholder("search and filter").TypeAsync("wife");
const string visibleCards = ".showCard:visible";
var waiting = await Page.WaitForSelectorAsync(visibleCards, new PageWaitForSelectorOptions() { Timeout = 500 });
await Expect(Page.Locator(visibleCards).First).ToBeVisibleAsync();
await Expect(Page.Locator(visibleCards)).ToHaveCountAsync(5);
}I love this. Nice and clean. Certainly here we are assuming that we have a URL in that first line, which will be localhost something, and then we assume that our web application has started up on its own.
Here is the setup code that starts my new “web application test builder factory,” yeah, the name is stupid but it’s descriptive. Note the OneTimeSetUp and the OneTimeTearDown. This starts my web app within the context of my TestHost. Note the :0 makes the app find a port which I then, sadly, have to dig out and put into the Url private for use within my Unit Tests. Note that the <Startup> is in fact my Startup class within Startup.cs which hosts my app’s pipeline and Configure and ConfigureServices get setup here so routing all works.
private string Url;
private WebApplication? _app = null;[OneTimeSetUp]
public void Setup()
{
var builder = WebApplicationTestBuilderFactory.CreateBuilder<Startup>();var startup = new Startup(builder.Environment);
builder.WebHost.ConfigureKestrel(o => o.Listen(IPAddress.Loopback, 0));
startup.ConfigureServices(builder.Services);
_app = builder.Build();// listen on any local port (hence the 0)
startup.Configure(_app, _app.Configuration);
_app.Start();//you are kidding me
Url = _app.Services.GetRequiredService<IServer>().Features.GetRequiredFeature<IServerAddressesFeature>().Addresses.Last();
}[OneTimeTearDown]
public async Task TearDown()
{
await _app.DisposeAsync();
}So what horrors are buried in WebApplicationTestBuilderFactory? The first bit is bad and we should fix it for .NET 9. The rest is actually every nice, with a hat tip to David Fowler for his help and guidance! This is the magic and the ick in one small helper class.
public class WebApplicationTestBuilderFactory
{
public static WebApplicationBuilder CreateBuilder<T>() where T : class
{
//This ungodly code requires an unused reference to the MvcTesting package that hooks up
// MSBuild to create the manifest file that is read here.
var testLocation = Path.Combine(AppContext.BaseDirectory, "MvcTestingAppManifest.json");
var json = JsonObject.Parse(File.ReadAllText(testLocation));
var asmFullName = typeof(T).Assembly.FullName ?? throw new InvalidOperationException("Assembly Full Name is null");
var contentRootPath = json?[asmFullName]?.GetValue<string>();//spin up a real live web application inside TestHost.exe
var builder = WebApplication.CreateBuilder(
new WebApplicationOptions()
{
ContentRootPath = contentRootPath,
ApplicationName = asmFullName
});
return builder;
}
}The first 4 lines are nasty. Because the test runs in the context of a different directory and my website needs to run within the context of its own content root path, I have to force the content root path to be correct and the only way to do that is by getting the apps base directory from a file generated within MSBuild from the (aging) MvcTesting package. The package is not used, but by referencing it it gets into the build and makes that file that I then use to pull out the directory.
If we can get rid of that “hack” and pull the directory from context elsewhere, then this helper function turns into a single line and .NET 9 gets WAY WAY more testable!
Now I can run my Unit Tests AND Playwright Browser Integration Tests across all OS’s, headed or headless, in docker or on the metal. The site is updated to .NET 8 and all is right with my code. Well, it runs at least. 😉
About Scott
Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.
-
HTML Image <img> Tag | Docs With Examples
HTML Image <img> Tag | Docs With Examples
Source link -
It’s Might Be Worth to Move Your Unique Family Business to New York
New York City, often referred to as the business capital of the world, offers unique opportunities for family businesses. While the allure of this vibrant metropolis goes beyond sparkling skyscrapers and bustling streets, it plays host to a web of advantages that can serve as the perfect backdrop for your business. From the accessibility of diverse resources to a regulatory environment that promotes growth and innovation, New York is undoubtedly a compelling choice for relocating your family business. Here’s a deeper dive into why moving your unique family business to the Big Apple could be one of the best decisions you make.
You Can Make Connections With the Big Dogs
New York City is truly a networking powerhouse, with ample opportunities to rub shoulders with industry leaders and influencers. While vibrant networking events and conferences are regular affairs, they are just the beginning. The city’s reputation as a hub for top-tier professionals creates a unique atmosphere where collaborations are not only possible but often encouraged.
With 38% of moves undertaken by corporations, New York’s strategic importance cannot be overstated. The business landscape here is uniquely competitive yet collaborative, fostering an environment where innovation thrives. Family businesses in particular can find themselves in the advantageous position of being able to learn from and partner with some of the best in their industry.
The chance to form partnerships with high-level businesses is one of New York’s undeniable benefits. Whether it’s through formal business councils or casual networking gatherings, access to these connections is amplified exponentially. The shared experiences and insights gained can fuel growth and transformation for your family business, taking it to new heights.
You’re Near an Endless Supply of Materials
Being in New York means having access to a consistent and diverse supply chain, essential for any thriving business. The logistics network in this city is unparalleled, ensuring that businesses are never far from the vital resources they need. This logistical advantage gives family businesses easy access to both local and global markets.
With 20 million shipping containers crossing our oceans every year, the availability of materials is almost guaranteed. The city’s numerous ports and proximity to major trade routes simplify the importing and exporting processes. For businesses relying on unique materials or varying supplies, this constant flow is invaluable.
Additionally, being close to such a vast network of suppliers means having the flexibility to pivot as market demands change. Family businesses often benefit from this agility, allowing them to adapt and grow efficiently. The ease of sourcing helps in maintaining consistent production rates and meeting customer expectations, further cementing New York’s position as an ideal business locale.
You’re Protected Under Many Laws and Regulations
New York is known for its robust legal framework that supports and protects businesses, making it a safe haven for entrepreneurial ventures. With an array of state and federal laws in place, businesses can flourish in a well-regulated environment. This comprehensive legal protection fosters trust and security for both business owners and consumers.
There are about 1,050 federal laws involving benefits or status for married couples, underscoring the city’s commitment to inclusivity and diversity. For family-run businesses, such a legal ecosystem can be especially beneficial, providing the peace of mind needed to focus on growth and innovation. These laws also ensure fair practices, which can be vital in maintaining a business’s reputation.
The city’s legal environment is further supported by institutions dedicated to assisting businesses navigate regulations efficiently. This guidance is crucial for family businesses seeking to expand or enhance their operations. As New York continues to evolve, it remains a favorable place to operate a business with its commitment to equitable and sustainable business practices.
Relocating your family business to New York is an investment in its future. The city offers unparalleled networking opportunities, an endless logistical supply, and protective regulations that work together to create an environment conducive to success. Family businesses have much to gain by embracing the dynamic and resource-rich environment that New York provides, reinforcing the city’s reputation as a hub of opportunity and innovation.
-
HTML iframe Element | Docs With Examples
HTML iframe Element | Docs With Examples
Source link -
Open Sourcing DOS 4 – Scott Hanselman’s Blog
See the canonical version of this blog post at the Microsoft Open Source Blog!
Ten years ago, Microsoft released the source for MS-DOS 1.25 and 2.0 to the Computer History Museum, and then later republished them for reference purposes. This code holds an important place in history and is a fascinating read of an operating system that was written entirely in 8086 assembly code nearly 45 years ago.
Today, in partnership with IBM and in the spirit of open innovation, we’re releasing the source code to MS-DOS 4.00 under the MIT license. There’s a somewhat complex and fascinating history behind the 4.0 versions of DOS, as Microsoft partnered with IBM for portions of the code but also created a branch of DOS called Multitasking DOS that did not see a wide release.
https://github.com/microsoft/MS-DOS
A young English researcher named Connor “Starfrost” Hyde recently corresponded with former Microsoft Chief Technical Officer Ray Ozzie about some of the software in his collection. Amongst the floppies, Ray found unreleased beta binaries of DOS 4.0 that he was sent while he was at Lotus. Starfrost reached out to the Microsoft Open Source Programs Office (OSPO) to explore releasing DOS 4 source, as he is working on documenting the relationship between DOS 4, MT-DOS, and what would eventually become OS/2. Some later versions of these Multitasking DOS binaries can be found around the internet, but these new Ozzie beta binaries appear to be much earlier, unreleased, and also include the ibmbio.com source.
Scott Hanselman, with the help of internet archivist and enthusiast Jeff Sponaugle, has imaged these original disks and carefully scanned the original printed documents from this “Ozzie Drop”. Microsoft, along with our friends at IBM, think this is a fascinating piece of operating system history worth sharing.
Jeff Wilcox and OSPO went to the Microsoft Archives, and while they were unable to find the full source code for MT-DOS, they did find MS DOS 4.00, which we’re releasing today, alongside these additional beta binaries, PDFs of the documentation, and disk images. We will continue to explore the archives and may update this release if more is discovered.
Thank you to Ray Ozzie, Starfrost, Jeff Sponaugle, Larry Osterman, our friends at the IBM OSPO, as well as the makers of such digital archeology software including, but not limited to Greaseweazle, Fluxengine, Aaru Data Preservation Suite, and the HxC Floppy Emulator. Above all, thank you to the original authors of this code, some of whom still work at Microsoft and IBM today!
If you’d like to run this software yourself and explore, we have successfully run it directly on an original IBM PC XT, a newer Pentium, and within the open source PCem and 86box emulators.
About Scott
Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.
-
HTML Span Tag | Docs With Examples
HTML Span Tag | Docs With Examples
Source link