private void SetupTestNationalSocieties() { var nationalSociety1 = new NationalSociety { Id = 1, Name = "Test national society 1" }; var nationalSociety2 = new NationalSociety { Id = 2, Name = "Test national society 2" }; var nationalSocieties = new List <NationalSociety> { nationalSociety1, nationalSociety2 }; var nationalSocietiesDbSet = nationalSocieties.AsQueryable().BuildMockDbSet(); _nyssContext.NationalSocieties.Returns(nationalSocietiesDbSet); var applicationLanguages = new List <ApplicationLanguage>(); var applicationLanguagesDbSet = applicationLanguages.AsQueryable().BuildMockDbSet(); _nyssContext.ApplicationLanguages.Returns(applicationLanguagesDbSet); _nyssContext.NationalSocieties.FindAsync(1).Returns(nationalSociety1); _nyssContext.NationalSocieties.FindAsync(2).Returns(nationalSociety2); }
public async Task <Result> Create(CreateNationalSocietyRequestDto dto) { if (_nyssContext.NationalSocieties.Any(ns => ns.Name.ToLower() == dto.Name.ToLower())) { return(Error <int>(ResultKey.NationalSociety.Creation.NameAlreadyExists)); } var nationalSociety = new NationalSociety { Name = dto.Name, ContentLanguage = await GetLanguageById(dto.ContentLanguageId), Country = await GetCountryById(dto.CountryId), IsArchived = false, StartDate = DateTime.UtcNow }; if (nationalSociety.ContentLanguage == null) { return(Error <int>(ResultKey.NationalSociety.Creation.LanguageNotFound)); } if (nationalSociety.Country == null) { return(Error <int>(ResultKey.NationalSociety.Creation.CountryNotFound)); } await _nyssContext.AddAsync(nationalSociety); await _nyssContext.SaveChangesAsync(); _loggerAdapter.Info($"A national society {nationalSociety} was created"); return(Success(nationalSociety.Id)); }
private void SetupTestNationalSociety() { var nationalSociety = new NationalSociety { Id = 1, Name = "Test national society" }; var nationalSocieties = new List <NationalSociety> { nationalSociety }; var nationalSocietiesDbSet = nationalSocieties.AsQueryable().BuildMockDbSet(); _nyssContext.NationalSocieties.Returns(nationalSocietiesDbSet); _nyssContext.NationalSocieties.FindAsync(1).Returns(nationalSociety); }
private UserNationalSociety CreateUserNationalSocietyReference(NationalSociety nationalSociety, User user) => new UserNationalSociety { NationalSociety = nationalSociety, User = user };