Example #1
0
        public async Task When_deleting_a_game_related_with_a_venue_then_an_application_exception_should_be_thrown()
        {
            var gameId            = 5;
            var gamesRepository   = Substitute.For <IGamesRepository>();
            var venuesRepository  = Substitute.For <IVenuesRepository>();
            var deleteGameHandler = new DeleteGameHandler(gamesRepository, venuesRepository, Substitute.For <IUnitOfWork>());

            var game = Game.Create("Name").WithId(gameId);

            gamesRepository.Find(gameId, default).Returns(Task.FromResult(game));
            venuesRepository.AnyAsync(Arg.Any <Expression <Func <Venue, bool> > >(), default).Returns(Task.FromResult(true));

            Func <Task <Unit> > func = async() => await deleteGameHandler.Handle(new DeleteGame(game.Id), default);

            func.Should().Throw <ApplicationException>().WithMessage(DeleteGameHandler.IsInUse);
            await gamesRepository.ReceivedWithAnyArgs(0).Remove(default);
        public async Task When_deleting_a_game_unrelated_to_a_venue_then_the_game_should_be_deleted()
        {
            const int id = 10;

            var gamesRepository = Substitute.For <GamesRepository>();
            var unitOfWork      = Substitute.For <IUnitOfWork>();

            var game = Game.Create("Name").WithId(id);

            gamesRepository.Find(id, default).Returns(Task.FromResult(game));

            var deleteGameHandler = new DeleteGameHandler(gamesRepository, unitOfWork);

            await deleteGameHandler.Handle(new DeleteGame
            {
                Id = id
            }, default);

            await gamesRepository.ReceivedWithAnyArgs(1).Remove(default);