public async Task AddGameAsyncTest() { //Arrange await CreateDb(); GameDto game = new GameDto() { Team1 = "Juve", Team2 = "Real", Date = DateTime.UtcNow }; //Act var id = await _gameService.AddGameAsync(game); var expected = await _gameService.GetGameAsync(id); //Assert Assert.AreEqual("Juve", expected.Team1); }
public async Task AddGameAsync_WhenNewGameIsPassed_ShouldAddGameToRepository() { // Arrange var gameRepository = A.Fake <IGameRepository>(); var sharedRepository = A.Fake <ISharedRepository>(); var processGameStrategyFactory = A.Fake <IProcessGameStrategyFactory>(); var strategy = A.Fake <ProcessGameStrategyBase>(); A.CallTo(() => processGameStrategyFactory.CreateStrategy(Direction.Up)).Returns(strategy); var service = new GameService(gameRepository, sharedRepository, processGameStrategyFactory); var newGame = new Game(); // Act await service.AddGameAsync(newGame); // Assert A.CallTo(() => gameRepository.AddAsync(newGame)).MustHaveHappened(); A.CallTo(() => processGameStrategyFactory.CreateStrategy(Direction.Up)).MustHaveHappened(); A.CallTo(() => strategy.ProcessGameAsync(A <IGameDecorator> .Ignored)).MustHaveHappenedOnceExactly(); A.CallTo(() => sharedRepository.SaveChangesAsync()).MustHaveHappenedOnceExactly(); }