public async Task <IActionResult> Index(CancellationToken cancellationToken) { List <Pet> pets = await _petsManagementService.GetAllPets(CurrentCookiesToken, cancellationToken); List <PetViewModel> viewModel = new List <PetViewModel>(); if (pets == null) { return(View()); } foreach (var pet in pets) { viewModel.Add(new PetViewModel { ThePet = pet, ThePetStatus = string.IsNullOrEmpty(pet.PetsStatus) ? new PetsStatus { Name = StringLocalizer["Lack"] } : await _petsStatusManagementService.GetStatus(pet.PetsStatus, CurrentCookiesToken, cancellationToken), TheHelper = string.IsNullOrEmpty(pet.HelperId) ? new Helper { Address = "TOZ" } : await _helpersManagementService.GetHelper(pet.HelperId, AuthService.ReadCookie(HttpContext, AppSettings.CookieTokenName, true), cancellationToken) }); if (!string.IsNullOrEmpty(pet.ImageUrl)) { try { var downloadedImg = _filesManagementService.DownloadImage(_appSettings.Value.BaseUrl + pet.ImageUrl); if (downloadedImg != null) { var thumbnail = _filesManagementService.GetThumbnail(downloadedImg); pet.Photo = _filesManagementService.ImageToByteArray(thumbnail); } } catch (HttpRequestException) { pet.Photo = null; } catch (AggregateException) { pet.Photo = null; } } } return(View(viewModel.OrderByDescending(x => x.ThePet.Created).ThenByDescending(x => x.ThePet.LastModified))); }
public async void PetsFunctionalityTest() { _token = await _accountManagementService.SignIn(TestingObjectProvider.Instance.Login); Assert.NotNull(_token); var pet = TestingObjectProvider.Instance.Pet; Assert.NotNull(await _petsManagementService.GetAllPets(_token.Jwt)); Assert.NotNull(await _petsManagementService.GetPet(pet.Id, _token.Jwt)); Assert.True(await _petsManagementService.CreatePet(pet, _token.Jwt)); Assert.True(await _petsManagementService.UpdatePet(pet, _token.Jwt)); var exception = Record.Exception(() => _petsManagementService.UpdatePet(null, _token.Jwt).Result); Assert.IsType(typeof(NullReferenceException), exception?.InnerException); Assert.False(await _petsManagementService.CreatePet(null, _token.Jwt)); }
public void TestOfGettingAllPets() { Assert.NotNull(_petsManagementService.GetAllPets(_token.Jwt).Result); }