public void PatchFollow_SavesChangesInTrend() { TrendPatchFollowDto trendPatchFollowDto = new TrendPatchFollowDto { Id = Guid.Parse("3fa85f64-5717-4562-b3fc-2c963f66afa6"), CreatorId = Guid.Parse("2fa85f64-5717-4562-b3fc-2c963f66afa6"), Type = "Not Follow" }; TrendFollow trendFollow = new TrendFollow { TrendId = trendPatchFollowDto.Id, UserId = trendPatchFollowDto.CreatorId }; Trend trend = new Trend { FollowersCount = 10 }; trendFollowRepositoryMock.Setup(x => x.GetByFilter(tf => tf.UserId == trendPatchFollowDto.CreatorId && tf.TrendId == trendPatchFollowDto.Id)).Returns(trendFollow); trendRepositoryMock.Setup(x => x.GetById(trendPatchFollowDto.Id)).Returns(trend); systemUnderTest.PatchFollow(trendPatchFollowDto); trend.FollowersCount -= 1; trendRepositoryMock.Verify(m => m.SaveChanges(), Times.Once); }
void ITrendBusinessLogic.PatchFollow(TrendPatchFollowDto trendPatchFollowDto) { TrendFollow trendFollow = trendFollowRepository.GetByFilter( tf => tf.UserId == trendPatchFollowDto.CreatorId && tf.TrendId == trendPatchFollowDto.Id); bool doFollow = trendPatchFollowDto.Type == "Follow"; int followsDelta = 0; if (trendFollow == null && doFollow) { trendFollow = new TrendFollow { TrendId = trendPatchFollowDto.Id, UserId = trendPatchFollowDto.CreatorId }; trendFollowRepository.Insert(trendFollow); trendFollowRepository.SaveChanges(); ++followsDelta; } else if (trendFollow != null && !doFollow) { trendFollowRepository.Delete(trendFollow.Id); trendFollowRepository.SaveChanges(); --followsDelta; } if (followsDelta != 0) { Trend trend = trendRepository.GetById(trendPatchFollowDto.Id); trend.FollowersCount += followsDelta; trendRepository.Update(trend); trendRepository.SaveChanges(); } }
public void PatchFollow_TrendFollowCountIncreasesAfterInsert() { TrendPatchFollowDto trendPatchFollowDto = new TrendPatchFollowDto { Id = Guid.Parse("3fa85f64-5717-4562-b3fc-2c963f66afa6"), CreatorId = Guid.Parse("2fa85f64-5717-4562-b3fc-2c963f66afa6"), Type = "Follow" }; TrendFollow trendFollow = new TrendFollow { TrendId = trendPatchFollowDto.Id, UserId = trendPatchFollowDto.CreatorId }; Trend trend = new Trend { FollowersCount = 0 }; trendFollowRepositoryMock.Setup(x => x.GetByFilter(tf => tf.UserId == trendPatchFollowDto.CreatorId && tf.TrendId == trendPatchFollowDto.Id)).Returns(() => null); trendRepositoryMock.Setup(x => x.GetById(trendPatchFollowDto.Id)).Returns(trend); systemUnderTest.PatchFollow(trendPatchFollowDto); trend.FollowersCount += 1; trendRepositoryMock.Verify(m => m.Update(trend), Times.Once); }
ICollection <TrendGetAllDto> ITrendBusinessLogic.GetAll(UserInfoModel userInfo) { ICollection <Trend> trends = trendRepository.GetAll("Follows"); ICollection <TrendGetAllDto> returnedTrends = new List <TrendGetAllDto>(); foreach (Trend trend in trends) { TrendGetAllDto trendGetAllDto = mapper.Map <TrendGetAllDto>(trend); if (userInfo != null && trend.Follows != null) { TrendFollow follow = trend.Follows.FirstOrDefault(f => f.UserId == userInfo.CreatorId); if (follow != null) { trendGetAllDto.Followed = true; } } returnedTrends.Add(trendGetAllDto); } return(returnedTrends); }
// Start Strategy 2 async void Strategy2Start_Click(object sender, RoutedEventArgs e) { // Get data from textboxes / comboboxes GetStrategyData(out string strategyName, out MarketPeriod marketSeries, out CurrencyPair symbol, out double total, out bool?buy, out bool?sell, StrategyName2, MarketSeriesSelect2, Strategy2Symbol, Strategy2Buy, Strategy2Sell, Strategy2Total); // Save strategy settings to strategy class TrendFollow trendFollow = new TrendFollow(strategyName, marketSeries, symbol, buy, sell, total); // Create List runningStrategyList.Add(trendFollow); this.RunningStrategies.ItemsSource = runningStrategyList; // Show saved settings in textblock - TEMP TestConsoleStrat2.Text = trendFollow.StrategyName + "\n" + trendFollow.Symbol + " | " + trendFollow.Total + " | " + trendFollow.Buy + " | " + trendFollow.Sell + " | " + trendFollow.MarketSeries; //Show dialogue box to show strategy is running await DialogBoxStrategy(StrategyName2.Content.ToString(), "Started"); // Start Algo #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed trendFollow.Start(); }