예제 #1
0
        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);
        }
예제 #2
0
 private string GetCompanySymbol(string companyName)
 {
     try
     {
         var sym = AllCompanies.FirstOrDefault(x => x.Name == companyName).Symbol;
         return(sym);
     }
     catch
     {
         return(null);
     }
 }
예제 #3
0
        //
        // 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();
        }
예제 #4
0
        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);
        }