|
This sounds suspiciously like a question you find on a certification test, for BI. You know, the very thing your company says you're supposed to be an expert in.
We're not here to do your homework for you.
|
|
|
|
|
Consensus view is that he/she is a spammer.
|
|
|
|
|
YASH PATEL 2023 wrote: How can Power BI development services assist businesses in transforming raw data into meaningful insights and visualizations?
Answer: It cannot.
But people can. They might or might not use that.
|
|
|
|
|
Here's my Program.cs file (I've actually simplified it to some extent).
using StudentsMinimalApi;
using StudentsMinimalApi.Validation;
using System.Collections.Concurrent;
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
builder.Services.AddProblemDetails();
WebApplication app = builder.Build();
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler();
}
app.UseStatusCodePages();
ConcurrentDictionary<string, Student> _students = new();
RouteGroupBuilder studentsApi = app.MapGroup("/student");
studentsApi.MapGet("/", () => _students);
RouteGroupBuilder studentsApiWithValidation = studentsApi
.MapGroup("/");
studentsApiWithValidation.MapGet("/{id}", (string id) =>
_students.TryGetValue(id, out var student)
? TypedResults.Ok(student)
: Results.Problem(statusCode: 404));
studentsApiWithValidation.MapPost("/{id}", (Student student, string id) =>
_students.TryAdd(id, student)
? TypedResults.Created($"/student/{id}", student)
: Results.ValidationProblem(new Dictionary<string, string[]>
{
{ "id", new[] { "A student with the given id already exists." } }
}));
app.Run();
public partial class Program { }
As you can see, I created an example minimal API that exposes endpoints that you can use to access or change data related to an example Student class using the HTTP protocol.
So now I'd like to test my minimal API using xUnit. That's how I decided to test if the post method successfully creates a new student.
[Fact]
public async Task MapPost_Should_Successfully_Create_A_New_Student()
{
await using var application = new WebApplicationFactory<Program>();
using HttpClient? client = application.CreateClient();
HttpResponseMessage? resultFromPost = await client.PostAsJsonAsync("/student/s1", new Student("X", "Y", "Z"));
HttpResponseMessage? resultFromGet = await client.GetAsync("/student/s1");
Assert.Equal(HttpStatusCode.Created, resultFromPost.StatusCode);
Assert.Equal(HttpStatusCode.OK, resultFromGet.StatusCode);
string? contentAsString = await resultFromGet.Content.ReadAsStringAsync();
var contentAsStudentObject =
JsonConvert.DeserializeObject<Student>(contentAsString);
Assert.Equal(HttpStatusCode.Created, resultFromPost.StatusCode);
Assert.Equal(HttpStatusCode.OK, resultFromGet.StatusCode);
Assert.NotNull(contentAsStudentObject);
Assert.Equal("X", contentAsStudentObject.FirstName);
Assert.Equal("Y", contentAsStudentObject.LastName);
Assert.Equal("Z", contentAsStudentObject.FavouriteSubject);
}
May I ask you if this way of testing is adequate? For the testing of the post method I've actually used the get method. This does not seem like a good approach, but I don't see how else I can handle the situation. So I can't compe up with another alternative that's maybe better than this. Is there a way for me to access the _students dictionary from the Program.cs file? How would you write your tests in this situation? Thank you in advance!
|
|
|
|
|
You might want to research 'code coverage' tools. Those collect stats during your test to make sure that you have tested all code paths.
Also note that you should not be actually testing the dictionary. But rather the usage of that. But perhaps that is what you mean.
Nikol Dimitrova 2023 wrote: Is there a way for me to access the _students dictionary from the Program.cs file?
Presumably to test that the state is as excepted. Yes there are several.
1. Just publicly expose the dictionary (getter)
2. You can use reflection to get to the internals of a class.
If you use the second then you should document with a comment that it only public for testing.
For a small case like this I would use the first (getter). For larger libraries I would use reflection because the idiom is clearer with more usage and because more chance of public methods getting misused over time.
|
|
|
|
|
Thank you for the response!
May I ask you how exactly can we access the dictionary after let's say we add a student with a POST request using reflection? We can also check if the count (the number of elements of the dictionary) is correct (if we add one student, it should be 1; if we add 2 students, then it should be 2, and so on).
I couldn't achieve that because we are actually using a WebApplicationBuilder<program>.
What is the approach?
Also, if I use the first method, how exactly do I expose it with a getter? I guess I cannot use the top-level statements syntax then, because we cannot define properties in namespaces.
Thanks!
|
|
|
|
|
I had one QA type tell us we "had to" test every "if" and "else". And this was a "budgeting" system.
There's a concept of "good enough" for the task (that QA can't deal with).
I just have a "feeling" you've gone too far when you start asserting strings beyond "required" / not required. Checking the contents of fields is the job of "edit / validation" programs.
(Which probably answers why we don't need to test "everything" as per QA).
A "good design" (IMO) just requires fewer unit tests.
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
This is my first time trying to to print directly to a printer using the PrintDialog and PrintDocument. I thought it would be like creating a PDF, where I just compose and create a file and print, but it looks like I'm forced to use an event handler to compose my print document using Drawing.
I was on the internet, and the examples where very simple and basic, but my document is going to be huge, and used many times in my c# winforms .Net Core 7 app. So I used ChatGPT to help me design a class, that I can call as my event handler, but I'm missing something in my class, or got it wrong on how all of this works.
On my Print Dialog Form, when I hit the print button, my code example ...
The printDefault.Question is what I'm trying to call, where Question is where I'm stumped ..
if (result == DialogResult.OK)
{
this.PrintObject.PrintSettings.DefaultPrinter = printDialog.PrinterSettings.PrinterName;
if (this.PrintObject.PrintSettings.DefaultDocument != null)
{
var printDefault = new PrintDefault
{
Bol = this.PrintBol
};
printDocument.PrintPage += new PrintPageEventHandler(printDefault.Question);
printDocument.Print();
this.PrintComplete = true;
}
}
And my class ....
I figured that my class is an extension of PrintDocument, but I'm not sure. One of the dumb requirements is that I need the MongoDb collection document to generate the BOL form to print, because that has all my data I need to populate the document I'm trying to create. I'm not really sure if my design is sound or not, and may have to think of an alternative. But I feel like I'm really close, just missing something that I didn't think of.
namespace SimpleBol.Classes.DirectPrint
{
public class PrintDefault : PrintDocument
{
public BILLOFLADINGS Bol { get; set; } = null!;
public void PrintDocument_PrintPage(object sender, PrintPageEventArgs e)
{
Font fontTitleBold = new Font("Arial", 16, FontStyle.Bold);
Font fontTitleRegular = new Font("Arial", 16, FontStyle.Regular);
Font fontLargeBold = new Font("Arial", 12, FontStyle.Bold);
Font fontLargeRegular = new Font("Arial", 12, FontStyle.Regular);
Font fontMedium = new Font("Arial", 10);
Font fontSmall = new Font("Arial", 8);
Font fontTiny = new Font("Arial", 6, FontStyle.Italic);
SolidBrush brush = new SolidBrush(System.Drawing.Color.Black);
RectangleF printArea = e.PageSettings.PrintableArea;
if (e.Graphics != null)
{
SizeF textSize = e.Graphics.MeasureString("BILL OF LADING", fontTitleBold);
float x = printArea.Left + (printArea.Width - textSize.Width) / 2;
float y = printArea.Top + (printArea.Height - textSize.Height) / 2;
e.Graphics.DrawString("Date: ", fontMedium, brush, x, y);
if (Bol != null)
{
string date = Bol.BolDate.ToString("dd-MM-yyyy");
e.Graphics.DrawString("Date: " + date, fontMedium, brush, x, y);
e.Graphics.DrawString("Shipper: " + Bol.ShipperName, fontMedium, brush, x, y + 20);
e.Graphics.DrawString("Vendor: " + Bol.ShipFromVendor, fontMedium, brush, x, y + 40);
}
}
}
protected override void OnPrintPage(PrintPageEventArgs e)
{
base.OnPrintPage(e);
PrintDocument_PrintPage(this, e);
}
}
}
On another note; since this is my first time, what's the best way to test during document composition. I threw out my cheap printer with cheap toner, and can't see having to print a sheet a paper on every test. Should I build a temp print preview first, and get it close enough there, and then use paper to fine tune?
Now I'm wondering if I should change my print dialog to show the preview first, and then hit the print button. The downside to being a rogue programmer is that I have no team to ask for help, and any help or opinions would be appreciated.
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
I can't help you with the print class, but I do have an idea about the testing.
Do you have MS Office installed on your development machine? If so, I believe that also installs a "Print to PDF" printer driver. You could use that to print to a PDF file instead of the printer.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
I didn't think of that! I have CutePDF that I print all my orders with, before I email them.
Thanks!
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
On top of that, ChatGPT should not be used to write code. It sucks at writing anything beyond "Hello World" and WILL lead you down incorrect paths.
|
|
|
|
|
I'm beginning to realize that now.
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
I'd like to put all of my custom classes into a .NET Framework DLL so that I can share them among many different executables.
If I install a NuGet package to the DLL, are the classes in that package supposed to be available to any EXE that holds a reference to the DLL?
Or NuGet packages can't be shared that way, meaning the package must be installed to the EXE, not the shared library?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
In my experience, NuGet packages are on a project basis (dll; exe), though you can manage them at the solution and project level.
You can "share" a dll's Nuget package via the dll as an "interface"; otherwise, I know of no way to surface "name spaces" from a dll other than the one it "owns".
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
Thanks for the response, Gerry. Can you elaborate on what you mean by sharing the package as an interface? Do you mean I'd have to write code (interfaces) that specifically expose the types in the NuGet package?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Yes. A proxy.
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
When you use or deploy the .DLL to another .EXE project, you have to ship the .DLL's in the NuGet package with your .DLL. Your .DLL won't work without them.
As for being available to the .EXE, yes, the NuGet .DLL's will also be available to the executable project, just like they were for your .DLL project.
|
|
|
|
|
OK, thanks Dave.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
The classes and functionality from the NuGet package won't be automatically available to the executables (EXE files) that reference this DLL. Each executable project that uses the DLL must also have its own references to the required NuGet packages.
|
|
|
|
|
I have a small game executable (not my game) that, when I close it down, opens my default browser with the game's maker's web site. Presumably it is just opening an http and Windows 11 handles it from there. Is there a way to prevent this from happening? —either to enclose the app's environment from the outside or to create an isolated environment that then executes the game (or some other way)? It would seem a little weird to me if I couldn't prevent that from happening to a specific Windows process. Windows provides a vast array of services to apps, but in terms of security, it might make sense to be able to prohibit certain operations for a process at the OS level. Does Windows provide any control for this?
|
|
|
|
|
Does Windows provide any control for this? No, not directly. I don't know of any O/S that does.
If the app is just shelling out to a URL, you really cannot stop an app from doing that. The shell will take commands from anything and there's nothing you can do to stop it.
Firewall rules will not help because the URL is being launched by the shell and the browser is the registered handler for HTTP/HTTPS. Your game isn't involved in handling the URL itself so there's no process-based firewall rule that will prevent the launch of it.
Writing up a rule to prevent access to the URL or IP will still bring up a browser window, but with a failure message.
|
|
|
|
|
|
I know the way I stopped it from happening with the game that I had.
I paid for the game, rather than just continuing to use the free demo.
|
|
|
|
|
Are there any .onnx Modules that are included already or plans to have them included?
The only ones I'm interested in are a .pt file format and the YOLOv5 6.2 doesn't work very well at all. (Probably because I don't have a GPU)
|
|
|
|
|
What does your question have to do with this forum? If you're asking about something you saw in an article, you should ask in the article itself.
|
|
|
|
|