friedice
friedice
CC#
Created by friedice on 8/6/2024 in #help
Integrate Blazor components inside MVC .NET Framework 4.8
No description
5 replies
CC#
Created by friedice on 4/12/2023 in #help
❔ Question about storing large amt of data for Unit Testing
This is my first time creating a unit test environment so I'm not sure about best practices. I created unit test project for my DAL. I want to mock the data from the repo call, so I store the raw data as a json format inside txt. It's not too big, but I don't want to clunk up the solution because am going to do the same for every repo call, which could be about ~100MB - 500MB of just raw txt data if I do 100% code coverage for all the services. Should I create a ZIP and compress all the files in there? Is there a better solution? Am I doing this all wrong?
10 replies
CC#
Created by friedice on 2/24/2023 in #help
❔ Issue with unit testing and projects not starting
I'm writing up tests for my controller, but I need to grab an access token for authorization to do anything. We're using OIDC and it's endpoint ishttps://localhost:5001
public async Task < string > GetAccessToken() {
var client = new HttpClient();

var request = new HttpRequestMessage(HttpMethod.Post, "https://localhost:5001/connect/token");
request.Content = new FormUrlEncodedContent(new Dictionary < string, string > {
///stuff here
});

var response = await client.SendAsync(request);

if (!response.IsSuccessStatusCode) {
throw new Exception("Failed to obtain token");
}

var responseContent = await response.Content.ReadAsStringAsync();
var tokenResponse = JsonConvert.DeserializeObject < TokenResponse > (responseContent);

return tokenResponse.AccessToken;
}
public async Task < string > GetAccessToken() {
var client = new HttpClient();

var request = new HttpRequestMessage(HttpMethod.Post, "https://localhost:5001/connect/token");
request.Content = new FormUrlEncodedContent(new Dictionary < string, string > {
///stuff here
});

var response = await client.SendAsync(request);

if (!response.IsSuccessStatusCode) {
throw new Exception("Failed to obtain token");
}

var responseContent = await response.Content.ReadAsStringAsync();
var tokenResponse = JsonConvert.DeserializeObject < TokenResponse > (responseContent);

return tokenResponse.AccessToken;
}
When I run this function in test explorer, I get a System.Net.Http.HttpRequestException : No connection could be made because the target machine actively refused it. (localhost:5001) However, when I open a separate instance of VS and run the application, then run test on the 1st VS, everything works fine. How do I make it so that I don't need to do all the shenanigans and just run the test from the test explorer?
6 replies
CC#
Created by friedice on 2/7/2023 in #help
❔ Data-binding multiple components Blazor
So let's say I have 3 components. Component C is a child of component B, and component B is a child of component A. Is it possible 2-way bind Component C and component A so that when a parameter value of Component C is updated, Component A's value will also get updated?
6 replies