diff --git a/LuckySpin.Test/SpinServiceTest.cs b/LuckySpin.Test/SpinServiceTest.cs index a5441c7..500fd5a 100644 --- a/LuckySpin.Test/SpinServiceTest.cs +++ b/LuckySpin.Test/SpinServiceTest.cs @@ -17,15 +17,17 @@ public void SpinService_CalculateAvgWins_WinningSpin() var mockRepo = new Mock(); //TODO: Use the Setup() and Returns() methods of mockRepo // to arrange for a consistent, expected output based on TestData + mockRepo.Setup(r => r.GetSpins()).Returns(SpinListData.GetSpins() ); + mockRepo.Setup(r => r.GetCount()).Returns(SpinListData.GetCount() ); var service = new SpinService(mockRepo.Object); //Act - run the method that you are testing and get a result - double result = service.CalculateAvgWins(); + double result = service.CalculateAvgWins(true); //Assert - compare the expected output from TestData to the method result // TODO: check the repo data for the number of previous spins and wins, add one winning spin - double wins = 1/*???*/, count=1/*???*/; + double wins = 5, count=11/*???*/; double expected = wins / count; Assert.Equal(expected, result); } diff --git a/LuckySpin/Controllers/SpinnerController.cs b/LuckySpin/Controllers/SpinnerController.cs index 92234c6..42a04d4 100644 --- a/LuckySpin/Controllers/SpinnerController.cs +++ b/LuckySpin/Controllers/SpinnerController.cs @@ -62,7 +62,7 @@ public IActionResult SpinIt(int luck) Spin spin = spinService.SpinIt(Luck); //Compute the average wins - spin.AverageWins = spinService.CalculateAvgWins(); + spin.AverageWins = spinService.CalculateAvgWins(spin.IsWinning); //Add to Spin Repository spinRepository.AddSpin(spin); diff --git a/LuckySpin/Services/ISpinService.cs b/LuckySpin/Services/ISpinService.cs index 8b577ae..655c8e7 100644 --- a/LuckySpin/Services/ISpinService.cs +++ b/LuckySpin/Services/ISpinService.cs @@ -4,7 +4,7 @@ namespace LuckySpin.Services { public interface ISpinService { - public Double CalculateAvgWins(); + public Double CalculateAvgWins(bool IsWinning); public Spin SpinIt(int Lucky); } } diff --git a/LuckySpin/Services/SpinService.cs b/LuckySpin/Services/SpinService.cs index 9ad3c3d..b0fd255 100644 --- a/LuckySpin/Services/SpinService.cs +++ b/LuckySpin/Services/SpinService.cs @@ -15,11 +15,18 @@ public SpinService(ISpinRepository sr) } - - public double CalculateAvgWins() + public double CalculateAvgWins(bool winning) { - //TODO: Write logic to use the "real" spinRepository NOT the test data - return .1; + //TODO: Write logic to use the "real" spinRepository NOT the test data' + double wins = 0; + if (winning) + wins = 1; + foreach (Spin s in spinRepository.GetSpins()) + { + if (s.IsWinning == true) + wins++; + } + return wins / (spinRepository.GetCount() + 1); } public Spin SpinIt(int luck)