public async void DeleteUser(long id) { if (!await JSRuntime.InvokeAsync <bool>("confirm", "Are you sure you want to delete this user")) { return; } await UserDataService.DeleteUser(id); Users = (await UserDataService.GetAllUsers()).ToList(); StateHasChanged(); ToastService.ShowSuccess("User Deleted Successfuly", "Confirm"); }
private async Task ApplyFilter() { if (!string.IsNullOrEmpty(SearchTerm)) { Users = Users.Where(v => v.UserName.ToLower().Contains(SearchTerm.Trim().ToLower())).ToList(); title = $"Users With {SearchTerm} Contained within the Username"; } else { Users = (await UserDataService.GetAllUsers()).ToList(); title = "All Users"; } }
protected override async Task OnInitializedAsync() { try { Users = (await UserDataService.GetAllUsers()).ToList(); } catch (Exception exception) { Logger.LogError("Exception occurred in on initialised async User Data Service", exception); ExceptionMessage = exception.Message; _loadFailed = true; } }
public async Task GetAllUsers_TestAsync() { // ARRANGE var handlerMock = new Mock <HttpMessageHandler>(MockBehavior.Strict); handlerMock .Protected() // Setup the PROTECTED method to mock .Setup <Task <HttpResponseMessage> >( "SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>() ) // prepare the expected response of the mocked http call .ReturnsAsync(new HttpResponseMessage() { StatusCode = HttpStatusCode.OK, Content = new StringContent(usersJson), }) .Verifiable(); // use real http client with mocked handler here var httpClient = new HttpClient(handlerMock.Object) { BaseAddress = new Uri("http://test.com/83"), }; UserDataService sut = new UserDataService(httpClient); var result = (await sut.GetAllUsers()).ToList(); Assert.NotNull(result); Assert.Equal("*****@*****.**", result[0].UserName); // also check the 'http' call was like we expected it var expectedUri = new Uri("http://test.com/api/user"); handlerMock.Protected().Verify( "SendAsync", Times.Exactly(1), // we expected a single external request ItExpr.Is <HttpRequestMessage>(req => req.Method == HttpMethod.Get && // we expected a GET request req.RequestUri == expectedUri // to this uri ), ItExpr.IsAny <CancellationToken>() ); }
public async void AddUserDialog_OnDialogClose() { Users = (await UserDataService.GetAllUsers()).ToList(); StateHasChanged(); }
protected async override Task OnInitializedAsync() { Users = (await UserDataService.GetAllUsers()).ToList(); User = Users.FirstOrDefault(); }
// GET: Users/GetAllUsers/ public ActionResult GetAllUsers() { var users = userDataService.GetAllUsers(); return(View(users)); }