public async void AddCountEntity_AddEnttiy_ReturnCountByBranch() { //Arrange StockRepository stubStockRepository = FakesFactory.CreateStockRepositoryFake(); IBranch <StockEntity> sectorBranch = new RedisBranch <StockEntity>(); sectorBranch.SetBranchId("BRANCH_SECTOR"); sectorBranch.FilterBy(i => i.IsActive).GroupBy("Sector"); stubStockRepository.AddBranch(sectorBranch); //Act StockEntity teslaEntity = new StockEntity("TESLA", StockSector.Technology, 229.00, 12.5); await stubStockRepository.AddAsync(teslaEntity); StockEntity microsoftEntity = new StockEntity("MICROSOFT", StockSector.Technology, 204.00, 9.5); await stubStockRepository.AddAsync(microsoftEntity); StockEntity appleEntity = new StockEntity("APPLE", StockSector.Technology, 294.21, 8.5); await stubStockRepository.AddAsync(appleEntity); long actualCount = await stubStockRepository.CountAsync("BRANCH_SECTOR", "Technology"); //Assert Assert.Equal(3, actualCount); }
public async void AddCountEntity_AddEnttiy_ReturnCountBySortedBranch() { //Arrange StockRepository stubStockRepository = FakesFactory.CreateStockRepositoryFake(); IBranch <StockEntity> sectorAndSortedCreatedDateTimeBranch = new RedisBranch <StockEntity>(); sectorAndSortedCreatedDateTimeBranch.SetBranchId("BRANCH_SECTOR_SORT_PRICE"); sectorAndSortedCreatedDateTimeBranch.FilterBy(i => i.IsActive).GroupBy("Sector").SortBy("Price"); stubStockRepository.AddBranch(sectorAndSortedCreatedDateTimeBranch); //Act StockEntity teslaEntity = new StockEntity("TESLA", StockSector.Technology, 229.00, 12.5); teslaEntity.CreatedDateTime = DateTimeOffset.UtcNow.AddSeconds(-15).DateTime; await stubStockRepository.AddAsync(teslaEntity); StockEntity microsoftEntity = new StockEntity("MICROSOFT", StockSector.Technology, 204.00, 9.5); await stubStockRepository.AddAsync(microsoftEntity); StockEntity appleEntity = new StockEntity("APPLE", StockSector.Technology, 294.21, 8.5); await stubStockRepository.AddAsync(appleEntity); long actualCount = await stubStockRepository.CountAsync("BRANCH_SECTOR_SORT_PRICE", 210, 250, "Technology"); //Assert Assert.Equal(1, actualCount); }
public async void AddCountEntity_AddEnttiy_ReturnCountBySortedBranch_ThrowsKeyNotFoundException() { //Arrange StockRepository stubStockRepository = FakesFactory.CreateStockRepositoryFake(); IBranch <StockEntity> sortByPriceChangeRateBranch = new RedisBranch <StockEntity>(); sortByPriceChangeRateBranch.SetBranchId("BRANCH_SORT_PRICE_CHANGE_RATE"); sortByPriceChangeRateBranch.FilterBy(i => i.IsActive).SortBy("PriceChangeRate"); stubStockRepository.AddBranch(sortByPriceChangeRateBranch); //Act StockEntity teslaEntity = new StockEntity("TESLA", StockSector.Technology, 229.00, 12.5); await stubStockRepository.AddAsync(teslaEntity); Func <Task> act = async() => await stubStockRepository.CountAsync("NotExist", ""); //Assert KeyNotFoundException exception = await Assert.ThrowsAsync <KeyNotFoundException>(act); Assert.StartsWith("branchId not found: NotExist.", exception.Message); }
public async Task Check_DataShouldBeAdded() { //Arrange and Act await fixture.ReloadTestDataAsync(); //Assert Assert.Equal(27, stockRepository.GetBranches().Count()); #region BRANCH_GROUPALL Assert.Equal(fixture.TestData.Count(i => i.IsActive), await stockRepository.CountAsync(StockRepository.BRANCH_GROUPALL, "All")); #endregion #region BRANCH_GROUPBY_SECTOR Assert.Equal(fixture.TestData.Count(i => i.IsActive && i.Sector == StockSector.CommunicationServices), await stockRepository.CountAsync(StockRepository.BRANCH_GROUPBY_SECTOR, StockSector.CommunicationServices.ToString())); Assert.Equal(fixture.TestData.Count(i => i.IsActive && i.Sector == StockSector.ConsumerDiscretionary), await stockRepository.CountAsync(StockRepository.BRANCH_GROUPBY_SECTOR, StockSector.ConsumerDiscretionary.ToString())); Assert.Equal(fixture.TestData.Count(i => i.IsActive && i.Sector == StockSector.ConsumerStaples), await stockRepository.CountAsync(StockRepository.BRANCH_GROUPBY_SECTOR, StockSector.ConsumerStaples.ToString())); Assert.Equal(fixture.TestData.Count(i => i.IsActive && i.Sector == StockSector.Energy), await stockRepository.CountAsync(StockRepository.BRANCH_GROUPBY_SECTOR, StockSector.Energy.ToString())); Assert.Equal(fixture.TestData.Count(i => i.IsActive && i.Sector == StockSector.Financials), await stockRepository.CountAsync(StockRepository.BRANCH_GROUPBY_SECTOR, StockSector.Financials.ToString())); Assert.Equal(fixture.TestData.Count(i => i.IsActive && i.Sector == StockSector.HealthCare), await stockRepository.CountAsync(StockRepository.BRANCH_GROUPBY_SECTOR, StockSector.HealthCare.ToString())); Assert.Equal(fixture.TestData.Count(i => i.IsActive && i.Sector == StockSector.Industrials), await stockRepository.CountAsync(StockRepository.BRANCH_GROUPBY_SECTOR, StockSector.Industrials.ToString())); Assert.Equal(fixture.TestData.Count(i => i.IsActive && i.Sector == StockSector.InformationTechnology), await stockRepository.CountAsync(StockRepository.BRANCH_GROUPBY_SECTOR, StockSector.InformationTechnology.ToString())); Assert.Equal(fixture.TestData.Count(i => i.IsActive && i.Sector == StockSector.Materials), await stockRepository.CountAsync(StockRepository.BRANCH_GROUPBY_SECTOR, StockSector.Materials.ToString())); Assert.Equal(fixture.TestData.Count(i => i.IsActive && i.Sector == StockSector.None), await stockRepository.CountAsync(StockRepository.BRANCH_GROUPBY_SECTOR, StockSector.None.ToString())); Assert.Equal(fixture.TestData.Count(i => i.IsActive && i.Sector == StockSector.RealEstate), await stockRepository.CountAsync(StockRepository.BRANCH_GROUPBY_SECTOR, StockSector.RealEstate.ToString())); Assert.Equal(fixture.TestData.Count(i => i.IsActive && i.Sector == StockSector.Utilities), await stockRepository.CountAsync(StockRepository.BRANCH_GROUPBY_SECTOR, StockSector.Utilities.ToString())); #endregion #region BRANCH_SORTBY_CREATEDDATETIME long fromCreateDateTimeTicks = DateTime.UtcNow.AddMinutes(-60).Ticks; long toCreateDateTimeTicks = DateTime.UtcNow.AddMinutes(60).Ticks; IEnumerable <StockEntity> BRANCH_SORTBY_CREATEDDATETIME = await stockRepository.GetAsync(StockRepository.BRANCH_SORTBY_CREATEDDATETIME, fromCreateDateTimeTicks, toCreateDateTimeTicks); Assert.Equal(fixture.TestData.Count(i => i.IsActive && i.CreatedDateTime.Ticks >= fromCreateDateTimeTicks && i.CreatedDateTime.Ticks <= toCreateDateTimeTicks), BRANCH_SORTBY_CREATEDDATETIME.Count()); foreach (StockEntity stockEntity in BRANCH_SORTBY_CREATEDDATETIME) { Assert.InRange(stockEntity.CreatedDateTime.Ticks, fromCreateDateTimeTicks, toCreateDateTimeTicks); } #endregion #region BRANCH_GROUPBY_SECTOR_SORTBY_PRICE IEnumerable <StockEntity> BRANCH_GROUPBY_SECTOR_SORTBY_PRICE = await stockRepository.GetAsync(StockRepository.BRANCH_GROUPBY_SECTOR_SORTBY_PRICE, 88.15, 136.8, StockSector.InformationTechnology.ToString()); Assert.Equal(fixture.TestData.Count(i => i.IsActive && i.Sector == StockSector.InformationTechnology && i.Price >= 88.15 && i.Price <= 136.8), BRANCH_GROUPBY_SECTOR_SORTBY_PRICE.Count()); foreach (StockEntity stockEntity in BRANCH_GROUPBY_SECTOR_SORTBY_PRICE) { Assert.InRange(stockEntity.Price, 88.15, 136.8); } #endregion #region BRANCH_GROUPBY_SECTOR_SORTBY_PRICECHANGERATE IEnumerable <StockEntity> BRANCH_GROUPBY_SECTOR_SORTBY_PRICECHANGERATE = await stockRepository.GetAsync(StockRepository.BRANCH_GROUPBY_SECTOR_SORTBY_PRICECHANGERATE, 0.10, StockSector.InformationTechnology.ToString()); Assert.Equal(fixture.TestData.Count(i => i.IsActive && i.Sector == StockSector.InformationTechnology && i.PriceChangeRate >= 0.10), BRANCH_GROUPBY_SECTOR_SORTBY_PRICECHANGERATE.Count()); foreach (StockEntity stockEntity in BRANCH_GROUPBY_SECTOR_SORTBY_PRICECHANGERATE) { Assert.True(stockEntity.PriceChangeRate >= 0.10); } #endregion #region BRANCH_GROUPBY_PROFITLEVEL_SORTBY_PRICECHANGERATE IEnumerable <StockEntity> BRANCH_GROUPBY_PROFITLEVEL_SORTBY_PRICECHANGERATE = await stockRepository.GetAsync(StockRepository.BRANCH_GROUPBY_PROFITLEVEL_SORTBY_PRICECHANGERATE, 0.10, 0.15, ProfitLevel.Great.ToString()); Assert.Equal(fixture.TestData.Count(i => i.IsActive && stockRepository.GetProfitLevel(i) == ProfitLevel.Great && i.PriceChangeRate >= 0.10 && i.PriceChangeRate <= 0.15), BRANCH_GROUPBY_PROFITLEVEL_SORTBY_PRICECHANGERATE.Count()); foreach (StockEntity stockEntity in BRANCH_GROUPBY_PROFITLEVEL_SORTBY_PRICECHANGERATE) { Assert.InRange(stockEntity.PriceChangeRate, 0.10, 0.15); } #endregion #region BRANCH_GROUPBY_SECTOR_GROUPBY_PROFITLEVEL_SORTBY_PRICECHANGERATE IEnumerable <StockEntity> BRANCH_GROUPBY_SECTOR_GROUPBY_PROFITLEVEL_SORTBY_PRICECHANGERATE = await stockRepository.GetAsync(StockRepository.BRANCH_GROUPBY_SECTOR_GROUPBY_PROFITLEVEL_SORTBY_PRICECHANGERATE, 0.10, 0.15, StockSector.InformationTechnology.ToString(), ProfitLevel.Great.ToString()); Assert.Equal(fixture.TestData.Count(i => i.IsActive && stockRepository.GetProfitLevel(i) == ProfitLevel.Great && i.Sector == StockSector.InformationTechnology && i.PriceChangeRate >= 0.10 && i.PriceChangeRate <= 0.15), BRANCH_GROUPBY_SECTOR_GROUPBY_PROFITLEVEL_SORTBY_PRICECHANGERATE.Count()); foreach (StockEntity stockEntity in BRANCH_GROUPBY_SECTOR_GROUPBY_PROFITLEVEL_SORTBY_PRICECHANGERATE) { Assert.InRange(stockEntity.PriceChangeRate, 0.10, 0.15); } #endregion #region BRANCH_GROUPBY_COUNTRY_SORTBY_PRICECHANGERATE IEnumerable <StockEntity> BRANCH_GROUPBY_COUNTRY_SORTBY_PRICECHANGERATE = await stockRepository.GetAsync(StockRepository.BRANCH_GROUPBY_COUNTRY_SORTBY_PRICECHANGERATE, 0.10, 0.15, "GERMANY"); Assert.Equal(fixture.TestData.Count(i => i.IsActive && i.MetaData.Country == "GERMANY" && i.PriceChangeRate >= 0.10 && i.PriceChangeRate <= 0.15), BRANCH_GROUPBY_COUNTRY_SORTBY_PRICECHANGERATE.Count()); foreach (StockEntity stockEntity in BRANCH_GROUPBY_COUNTRY_SORTBY_PRICECHANGERATE) { Assert.InRange(stockEntity.PriceChangeRate, 0.10, 0.15); } #endregion }