public CompanyServiceTest() { _companyRepositoryMock = new Mock <ICompanyRepository>(); _companyRepositoryMock .Setup(p => p.GetCompanies(It.IsAny <SearchCompanies>())) .Callback((SearchCompanies s) => { if (s.Ids != null && s.Ids.Any()) { AllCompanies = AllCompanies.Where(p => s.Ids.Contains(p.Id)); } if (s.IsActive != null) { AllCompanies = AllCompanies.Where(p => s.IsActive == p.IsActive); } }) .ReturnsAsync(AllCompanies); _companyRepositoryMock.Setup(p => p.GetCompany(It.IsAny <SearchCompany>())) .Callback((SearchCompany filter) => { }) .ReturnsAsync((SearchCompany s) => AllCompanies.FirstOrDefault(company => company.Id == s.Id)); _companyService = new CompanyService(_companyRepositoryMock.Object); }
private string GetCompanySymbol(string companyName) { try { var sym = AllCompanies.FirstOrDefault(x => x.Name == companyName).Symbol; return(sym); } catch { return(null); } }
// // Todo, should I reload instead? // private void DeleteSelectedCompany() { _repository.DeleteCompany(_writer, SelectedCompany); var companyToRemove = AllCompanies.FirstOrDefault(c => c.Id == SelectedCompany.Id); if (companyToRemove != null) { AllCompanies.Remove(companyToRemove); } SelectedCompany = null; SendCompanyCommand.Execute(null); FilterList(); }
private void DeleteCompany_E(object obj) { try { if (allCompanySelectedId == null || allCompanySelectedId < 0) { MessageBox.Show("Please select a company to delete"); return; } if (MessageBox.Show("Deleting a Company would also delete all data about the company , Including data of all clients " + "and suppliers, Click Okay to Proceed", "Permanent Delete Information", MessageBoxButton.OKCancel, MessageBoxImage.Information) == MessageBoxResult.Cancel) { return; } if (allCompanySelectedId == 1) { MessageBox.Show("Default Company Cannot be deleted", "Invalid Operation", MessageBoxButton.OK, MessageBoxImage.Information); return; } var company = db.Companies.Find(allCompanySelectedId); if (company == SelectedCompany) { MessageBox.Show("The Currently Selected Company Cannot be deleted", "Invalid Operation", MessageBoxButton.OK, MessageBoxImage.Error); return; } else if (MessageBox.Show("Are you sure you want to delete the selected Company", "Confirm Delete", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { db.Companies.Remove(company); currentContext.Post(_ => { AllCompanies.Remove(company); }, null); db.SaveChanges(); refreshCs_E(null); } } catch { } }
private void FilterList() { if (FilteredCompanies == null) { FilteredCompanies = new ObservableCollection <ICompany>(); } FilteredCompanies.Clear(); if (string.IsNullOrEmpty(FilterString)) { FilteredCompanies.AddRange(AllCompanies); } else { var query = AllCompanies.Where(c => c.Name.ToLower().Contains(FilterString.ToLower()) || c.City.ToLower().Contains(FilterString.ToLower())); FilteredCompanies.AddRange(query); } }
public async Task Should_Return_Company_When_UserId_Is_1() { // Arrange var userId = 1; var requestFilter = new SearchCompany() { Id = userId }; var expectedResult = AllCompanies.FirstOrDefault(p => p.Id == userId); // Act var result = await _companyService .GetCompany(requestFilter).ConfigureAwait(false); // Assert Assert.NotNull(expectedResult); Assert.Equal(expectedResult.Id, result.Id); Assert.Equal(expectedResult.Name, result.Name); Assert.Equal(expectedResult.IsActive, result.IsActive); }
private void MenuItem_DB_AllCompanies_OnClick(object sender, RoutedEventArgs e) { DataContext = new AllCompanies(); }