public async Task SaveSelectedSectorsAsync_NoUserSectors_DontCallUserSectorsRepositoryDelete() { // arrange SaveSelectedSectorsDto dto = SaveSelectedSectorsDtoBuilder.Build(); dto.SelectedSectors = new List <int>() { 1, 2, 3 }; User user = new User() { Agreed = true, Name = "Name", UserId = 1 }; unitOfWork.Users.GetUserByName(dto.Name).Returns(user); List <Entities.UserSectors> userSectors = new List <Entities.UserSectors>(); unitOfWork.UserSectors.GetSectorByUserId(Arg.Any <int>()).Returns(userSectors); unitOfWork.Sectors.GetSectorByValue(Arg.Any <int>()).Returns(new Entities.Sector() { }); // act await sectorService.SaveSelectedSectorsAsync(dto); // assert unitOfWork.UserSectors.DidNotReceive().Delete(Arg.Any <Entities.UserSectors>()); }
public async Task SaveSelectedSectorsAsync_CallsService() { // arrange SaveSelectedSectorsDto dto = SaveSelectedSectorsDtoBuilder.Build(); // act await sectorController.SaveSelectedSectorsAsync(dto); // assert await sectorService.Received(1).SaveSelectedSectorsAsync(dto); }
public async Task SaveSelectedSectorsAsync_CallsApi() { // arrange SaveSelectedSectorsDto dto = SaveSelectedSectorsDtoBuilder.Build(); string endpoint = "endPoint"; configuration[EndPoints.Api.SaveSelectedSectors].Returns(endpoint); // act await sectorService.SaveSelectedSectorsAsync(dto); // assert await httpClient.PostAsync <SaveSelectedSectorsDto>(endpoint, dto); }
public async Task SaveSelectedSectorsAsync(SaveSelectedSectorsDto selectedSectorsDto) { if (selectedSectorsDto == null) { throw new ArgumentNullException(nameof(selectedSectorsDto)); } User user = unitOfWork.Users.GetUserByName(selectedSectorsDto.Name); if (user == null) { user = new User() { Agreed = selectedSectorsDto.Agreed, Name = selectedSectorsDto.Name }; await unitOfWork.Users.AddAsync(user); await unitOfWork.SaveAsync(); } IEnumerable <Entities.UserSectors> userSectors = unitOfWork.UserSectors.GetSectorByUserId(user.UserId); if (userSectors.Any()) { foreach (var userSector in userSectors) { unitOfWork.UserSectors.Delete(userSector); } } foreach (var item in selectedSectorsDto.SelectedSectors) { Entities.Sector sector = unitOfWork.Sectors.GetSectorByValue(item); await unitOfWork.UserSectors.AddAsync(new Entities.UserSectors() { SectorId = sector.SectorId, UserId = user.UserId }); } await unitOfWork.SaveAsync(); }
public async Task SaveSelectedSectorsAsync([FromBody] SaveSelectedSectorsDto selectedSectorsDto) { await sectorService.SaveSelectedSectorsAsync(selectedSectorsDto); }
public async Task SaveSelectedSectorsAsync(SaveSelectedSectorsDto selectedSectorDto) { string saveSelectedSectorsUrl = configuration[EndPoints.Api.SaveSelectedSectors]; await httpClient.PostAsync <SaveSelectedSectorsDto>(saveSelectedSectorsUrl, selectedSectorDto); }