8.7 C
New York
Sunday, March 16, 2025
Home Blog Page 3777

Updating to .NET 8, updating to IHostBuilder, and operating Playwright Exams inside NUnit headless or headed on any OS



All the Unit Tests passI have been doing not simply Unit Testing for my websites however full on Integration Testing and Browser Automation Testing as early as 2007 with Selenium. These days, nonetheless, I have been utilizing the sooner and customarily extra appropriate Playwright. It has one API and may check on Home windows, Linux, Mac, regionally, in a container (headless), in my CI/CD pipeline, on Azure DevOps, or in GitHub Actions.

For me, it is that final second of fact to be sure that the positioning runs fully from finish to finish.

I can write these Playwright assessments in one thing like TypeScript, and I might launch them with node, however I like operating finish unit assessments and utilizing that check runner and check harness as my leaping off level for my .NET purposes. I am used to proper clicking and “run unit assessments” and even higher, proper click on and “debug unit assessments” in Visible Studio or VS Code. This will get me the advantage of all the assertions of a full unit testing framework, and all the advantages of utilizing one thing like Playwright to automate my browser.

In 2018 I used to be utilizing WebApplicationFactory and a few difficult hacks to principally spin up ASP.NET inside .NET (on the time) Core 2.1 inside the unit assessments after which launching Selenium. This was type of janky and would require to manually begin a separate course of and handle its life cycle. Nevertheless, I stored on with this hack for a variety of years principally making an attempt to get the Kestrel Internet Server to spin up inside my unit assessments.

I’ve lately upgraded my most important website and podcast website to .NET 8. Needless to say I have been transferring my web sites ahead from early early variations of .NET to the newest variations. The weblog is fortunately operating on Linux in a container on .NET 8, however its unique code began in 2002 on .NET 1.1.

Now that I am on .NET 8, I scandalously found (as my unit assessments stopped working) that the remainder of the world had moved from IWebHostBuilder to IHostBuilder 5 model of .NET in the past. Gulp. Say what you’ll, however the backward compatibility is spectacular.

As such my code for Program.cs modified from this

public static void Most important(string[] args)
{
CreateWebHostBuilder(args).Construct().Run();
}

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup();

to this:

public static void Most important(string[] args)
{
CreateHostBuilder(args).Construct().Run();
}

public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args).
ConfigureWebHostDefaults(WebHostBuilder => WebHostBuilder.UseStartup());

Not a significant change on the surface however tidies issues up on the within and units me up with a extra versatile generic host for my net app.

My unit assessments stopped working as a result of my Kestral Internet Server hack was not firing up my server.

Right here is an instance of my aim from a Playwright perspective inside a .NET NUnit check.

[Test]
public async Process DoesSearchWork()
{
await Web page.GotoAsync(Url);

await Web page.Locator("#topbar").GetByRole(AriaRole.Hyperlink, new() { Identify = "episodes" }).ClickAsync();

await Web page.GetByPlaceholder("search and filter").ClickAsync();

await Web page.GetByPlaceholder("search and filter").TypeAsync("spouse");

const string visibleCards = ".showCard:seen";

var ready = await Web page.WaitForSelectorAsync(visibleCards, new PageWaitForSelectorOptions() { Timeout = 500 });

await Anticipate(Web page.Locator(visibleCards).First).ToBeVisibleAsync();

await Anticipate(Web page.Locator(visibleCards)).ToHaveCountAsync(5);
}

I like this. Good and clear. Definitely right here we’re assuming that we’ve got a URL in that first line, which might be localhost one thing, after which we assume that our net software has began up by itself.

Right here is the setup code that begins my new “net software check builder manufacturing facility,” yeah, the title is silly nevertheless it’s descriptive. Notice the OneTimeSetUp and the OneTimeTearDown. This begins my net app inside the context of my TestHost. Notice the :0 makes the app discover a port which I then, sadly, need to dig out and put into the Url personal to be used inside my Unit Exams. Notice that the is actually my Startup class inside Startup.cs which hosts my app’s pipeline and Configure and ConfigureServices get setup right here so routing all works.

personal string Url;
personal WebApplication? _app = null;

[OneTimeSetUp]
public void Setup()
{
var builder = WebApplicationTestBuilderFactory.CreateBuilder();

var startup = new Startup(builder.Atmosphere);
builder.WebHost.ConfigureKestrel(o => o.Pay attention(IPAddress.Loopback, 0));
startup.ConfigureServices(builder.Providers);
_app = builder.Construct();

// pay attention on any native port (therefore the 0)
startup.Configure(_app, _app.Configuration);
_app.Begin();

//you're kidding me
Url = _app.Providers.GetRequiredService().Options.GetRequiredFeature().Addresses.Final();
}

[OneTimeTearDown]
public async Process TearDown()
{
await _app.DisposeAsync();
}

So what horrors are buried in WebApplicationTestBuilderFactory? The primary bit is unhealthy and we should always repair it for .NET 9. The remaining is definitely each good, with a hat tip to David Fowler for his assist and steerage! That is the magic and the ick in a single small helper class.

public class WebApplicationTestBuilderFactory 
{
public static WebApplicationBuilder CreateBuilder() the place T : class
{
//This ungodly code requires an unused reference to the MvcTesting bundle that hooks up
// MSBuild to create the manifest file that's learn right here.
var testLocation = Path.Mix(AppContext.BaseDirectory, "MvcTestingAppManifest.json");
var json = JsonObject.Parse(File.ReadAllText(testLocation));
var asmFullName = typeof(T).Meeting.FullName ?? throw new InvalidOperationException("Meeting Full Identify is null");
var contentRootPath = json?[asmFullName]?.GetValue();

//spin up an actual dwell net software inside TestHost.exe
var builder = WebApplication.CreateBuilder(
new WebApplicationOptions()
{
ContentRootPath = contentRootPath,
ApplicationName = asmFullName
});
return builder;
}
}

The primary 4 traces are nasty. As a result of the check runs within the context of a unique listing and my web site must run inside the context of its personal content material root path, I’ve to power the content material root path to be appropriate and the one approach to try this is by getting the apps base listing from a file generated inside MSBuild from the (growing older) MvcTesting bundle. The bundle isn’t used, however by referencing it it will get into the construct and makes that file that I then use to drag out the listing.

If we are able to do away with that “hack” and pull the listing from context elsewhere, then this helper operate turns right into a single line and .NET 9 will get WAY WAY extra testable!

Now I can run my Unit Exams AND Playwright Browser Integration Exams throughout all OS’s, headed or headless, in docker or on the metallic. The location is up to date to .NET 8 and all is correct with my code. Properly, it runs a minimum of. 😉




About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, advisor, father, diabetic, and Microsoft worker. He’s a failed stand-up comedian, a cornrower, and a guide creator.

facebook
twitter
subscribe
About   Publication

Internet hosting By
Hosted in an Azure App Service










Create a Higher Journey Expertise for Passengers


From tech developments to the financial potential of generative AI, synthetic intelligence is shaping the way forward for the airline business. These cutting-edge applied sciences promise to boost passenger experiences, streamline operations, and create new alternatives for development and effectivity. Many main airways are already deploying generative AI-based chatbots. Right here’s how airways harness the facility of AI to profit their passengers and operations.

This Week’s Superior Tech Tales From Across the Net (By means of August 17)

0


ALS Stole His Voice. AI Retrieved It.
Benjamin Mueller | The New York Occasions
“Midway by attempting to talk his first immediate aloud—’What good is that?’—a shaking, smiling Mr. Harrell crumpled into tears. …By day two, the machine was ranging throughout an out there vocabulary of 125,000 phrases with 90 p.c accuracy and, for the primary time, producing sentences of Mr. Harrell’s personal making. The system spoke them in a voice remarkably like his personal, too: Utilizing podcast interviews and different outdated recordings, the researchers had created a deep faux of Mr. Harrell’s pre-ALS voice.”

This Researcher Needs to Change Your Mind, Little by Little
Antonio Regalado | MIT Know-how Assessment
“A US company pursuing moonshot well being breakthroughs has employed a researcher advocating an especially radical plan for defeating demise. His concept? Change your physique components. All of them. Even your mind. Jean Hébert, a brand new rent with the US Superior Initiatives Company for Well being (ARPA-H), is predicted to steer a significant new initiative round ‘useful mind tissue substitute,’ the thought of including youthful tissue to individuals’s brains.”

Glad Birthday, Child! What the Future Holds for These Born At present
Kara Platoni | MIT Know-how Assessment
“Your arrival coincided with the a hundred and twenty fifth anniversary of this journal. Confidently and the precise genes, you would possibly see the following 125 years. How will you and the following era of machines develop up collectively? We requested greater than a dozen consultants to think about your joint future. We defined that this may be a thought experiment. What I imply is: We requested them to get bizarre.”

Research Suggests That Even the Greatest AI Fashions Hallucinate a Bunch
Kyle Wiggers | TechCrunch
“A current research from researchers at Cornell, the schools of Washington and Waterloo and the nonprofit analysis institute AI2 sought to benchmark hallucinations by fact-checking fashions like GPT-4o towards authoritative sources on matters starting from regulation and well being to historical past and geography. …’An important takeaway from our work is that we can’t but totally belief the outputs of mannequin generations,’ Wenting Zhao, a doctorate pupil at Cornell and a co-author on the analysis, advised TechCrunch. ‘At current, even the perfect fashions can generate hallucination-free textual content solely about 35% of the time.’”

Why Alaska Airways Is Investing in a Jet That’s Like Nothing You’ve Seen Earlier than
Patrick Sisson | Quick Firm
“[JetZero’s blended-wing-body (BWB) aircraft] idea boasts a extra triangular, stretch design—the place the cabin and wing mix collectively—creating extra aerodynamic effectivity and carry. This permits the airplane to fly increased, at round ​​45,000 toes, which additional cuts wind resistance. Issue within the change in supplies and development, with bolted steel and composites swapped out for lighter, stitched carbon fiber, and a BWB jet can carry tons of of passengers with half the gas, an enormous price financial savings and environmental profit.”

NASA and Rocket Lab Intention to Show We Can Go to Mars for 1/10 the Value
Aria Alamalhodaei | TechCrunch
“As an alternative of spending $550 million on a mission into deep house, NASA set a objective to spend simply one-tenth of that and gave every SIMPLEx mission a $55 million worth cap, excluding launch. ESCAPADE is one in all three missions the company chosen below the SIMPLEx program, and in all probability, the primary that can really launch.”

Inside a Inexperienced-Hydrogen Pilot Plant
Jesse Orrall | CNET
“We bought a glance inside Verdagy’s pilot plant, the place the corporate is testing its multimillion-dollar electrolyzer designed to show renewable power like wind and photo voltaic into hydrogen. …All collectively, Neese says, it’s ‘tens of millions of {dollars} for an electrolyzer,’ however the estimated ‘tens of 1000’s of gallons of diesel equal produced per day’ of hydrogen will make inexperienced hydrogen aggressive in price with fossil fuels globally by 2030.”

LLMs Are a Lifeless Finish to AGI, Says François Chollet
Kristin Houser | Massive Assume
“Synthetic basic intelligence (AGI) may change the world, however nobody appears to know the way shut we’re to constructing it. At present’s generative AIs rating effectively on benchmarks, however such benchmarks will be solved by memorization and don’t essentially sign basic intelligence. To speed up progress in AI, François Chollet launched ARC Prize, a contest to see which AIs can rating highest on a set of abstraction and reasoning duties.”

Ikea’s Inventory-Counting Warehouse Drones Will Fly Alongside Staff within the US
Emma Roth | The Verge
“The Swedish furnishings chain introduced that the autonomous drones will quickly function alongside employees in its Perryville, Maryland, distribution heart, the place Ikea began set up this summer season. The Verity-branded drones additionally include a brand new AI-powered system that permits them to fly round warehouses 24/7. Meaning they’ll now function alongside human employees, serving to to rely stock in addition to determine if one thing’s within the incorrect spot. Beforehand, the drones solely flew throughout nonoperational hours.”

Picture Credit score: JetZero

Preparation of silver-containing starch nanocomposite ready from inexperienced synthesis with inexperienced tea plant extract and investigation of dye degradation and antibacterial exercise


Doc Kind : Authentic Analysis Article

Authors

1
Division of Nanochemistry, College of Pharmaceutical Chemistry, Tehran Medical Sciences, Islamic Azad College, Tehran, Iran

2
Division of Medical Nanotechnology, College of Superior Sciences and Know-how, Tehran Medical Sciences, Islamic Azad College, Tehran, Iran

3
College of New Applied sciences Engineering, Shahid Beheshti College, Zirab Campus, Mazandaran, Iran

10.22034/nmrj.2024.01.007

Summary

Goal(s): On this work, silver nanoparticles (Ag NPs) have been synthesized by inexperienced tea plant extract as a simple, cost-effective, environmentally pleasant, and dependable synthesis. The silver nanocomposite with totally different quantities of starch (0.5, 1, 1.5 g) have been ready. Then, the methylene blue (MB) dye degradation and the antibacterial exercise of the nanocomposite have been evaluated as an environmental problem.
Strategies: The samples have been characterised utilizing scanning electron microscope (SEM) for remark measurement and morphology, vitality dispersive X-ray evaluation (EDX) for dedication elemental evaluation, Fourier rework infrared spectroscopy (FTIR) for investigation purposeful teams, and X-ray diffraction evaluation (XRD) for affirmation crystalline construction.  The catalytic properties of the synthesized samples have been studied in MB degradation. 
Outcomes: The utmost degradation (greater than 90%) was associated to Ag NP with 0.5 g of starch. The antibacterial exercise of Ag NPs and nanocomposites was investigated in opposition to Staphylococcus aureus (S. aureus) as Gram-positive and Pseudomonas aeruginosa (P. aeruginosa) as Gram-negative micro organism. The samples indicated inhibitory exercise with appropriate inhibition zone and have been more practical in opposition to S. aureus as in comparison with P. aeruginosa. 
Conclusions: Basically, the inexperienced synthesis of Ag NP-starch has good catalytic potential in MB degradation in an aqueous medium in a short while with excessive effectivity.

Graphical Summary

Preparation of silver-containing starch nanocomposite ready from inexperienced synthesis with inexperienced tea plant extract and investigation of dye degradation and antibacterial exercise

Key phrases

Principal Topics

Aptera Expands its Horizons by Licensing Photo voltaic Expertise Throughout Mobility Industries


Aptera Expands its Horizons by Licensing Photo voltaic Expertise Throughout Mobility Industries

Cleantech San Diego member Aptera Motors, the producer of the world’s best photo voltaic electrical automobile, introduced its strategic enlargement into new mobility industries by way of the licensing of its breakthrough photo voltaic expertise. This transfer aligns with Aptera’s mission to create a future the place each journey is powered by the solar, extending their progressive impression into new markets. 

 

Aptera’s cutting-edge photo voltaic expertise considerably enhances the vary and grid independence of its flagship photo voltaic electrical automobile (sEV), whereas additionally considerably lessening the environmental impression. In sunny climates, solar energy can add greater than 11,000 miles (17,700 km) of vary per 12 months to Aptera’s photo voltaic electrical automobile, and over 8,000 miles (12,800 km) in much less sunny areas. This development in automotive photo voltaic expertise implies that most drivers could by no means must cost their Aptera, eradicating the EV recharge barrier for a lot of the US and European inhabitants whereas lowering stress on the grid. 

 

With its $130M patent portfolio, together with over 34 patents in course of, Aptera is now leveraging its photo voltaic expertise to revolutionize a number of mobility industries and develop new income streams for the corporate, which is able to assist fund the mass manufacturing of its photo voltaic electrical automobile. Aptera’s progressive photo voltaic expertise is at the moment being deployed within the floor assist gear and leisure automobile industries, with plans to broaden into aerospace, logistics, marine, and extra. 

 

One important software of Aptera’s photo voltaic expertise at the moment underway is a pilot program for retrofitting floor assist gear (GSE) for one of many largest airways on this planet. Aptera, in collaboration with Averest, is specializing in making use of this expertise to a Trepel 280 E pushback tractor together with varied different electrical utility autos similar to baggage carts. The purpose of the pilot program for GSE, which is ready to be accomplished by the top of Q3 2024, is to doubtlessly get rid of the necessity for typical charging fully, considerably boosting operational readiness whereas minimizing upkeep wants and downtime dangers. 

 

 

This initiative goals to cut back the key airways’ operational prices and environmental footprint, supporting the airline business’s targets for electrifying their fleets and lowering their carbon footprint. 

 

Moreover, Polydrops, recognized for its progressive EV trailers designed for environment friendly and sustainable journey, has additionally begun a pilot program to combine Aptera’s photo voltaic expertise onto its trailers. Using Aptera’s custom-fit panels ensures most vitality seize and delivers a high-power output of 1300 W, offering substantial vitality for prolonged journeys and off-grid purposes. These custom-fit panels are considerably lighter than conventional glass panels, keep a low profile for enhanced aesthetics and performance, and provide excessive sturdiness with automotive-grade requirements, making them excellent for the rugged situations typically encountered by trailers. The combination of Aptera’s photo voltaic expertise will improve the self-sufficiency and sustainability of Polydrops’ EV trailers, completely complementing Aptera’s imaginative and prescient of off-grid, solar-powered adventures and supporting a life-style of eco-friendly, energy-independent journey. 

 

“Aptera’s mission has at all times been to push the boundaries of what photo voltaic mobility can obtain,” stated Steve Fambro, Co-Founding father of Aptera Motors. “Our collaboration with business leaders like Averest and Polydrops is only the start. By leveraging our wealthy mental property portfolio, we’re driving improvements that place solar energy on the forefront of transportation, not just for private autos however throughout varied sectors, together with fleet purposes and past. This pilot program is a big step towards a future the place vitality independence and sustainability are the norms, not the exceptions.” 

 

Trying forward, Aptera plans to discover additional purposes of its photo voltaic expertise throughout totally different automobile varieties and industries. By leveraging its superior photo voltaic expertise and with plans to broaden its sEV product pipeline, Aptera goals to make an enduring impression on world mobility and environmental conservation. 

 

Share this….