Ejemplo n.º 1
0
        public void UserHasJoined_ShouldWorkCorrectly_WhenUserIsJoined()
        {
            var mockFactory           = new Mock <IFactory>();
            var mockTourneyRepository = new Mock <IRepository <Tourney> >();
            var mockUserRepository    = new Mock <IRepository <User> >();
            var mockPlayerRepository  = new Mock <IRepository <Player> >();
            var mockUnitOfWork        = new Mock <IUnitOfWork>();

            var service = new TourneyService(
                mockFactory.Object,
                mockTourneyRepository.Object,
                mockUserRepository.Object,
                mockPlayerRepository.Object,
                mockUnitOfWork.Object
                );

            var mockTourney = new Mock <Tourney>();

            //TODO fix the search logic to be testable

            mockTourneyRepository.Setup(x => x.GetById(It.IsAny <int>())).Returns(mockTourney.Object);

            service.EditTourney(mockTourney.Object);

            mockUnitOfWork.Verify(x => x.Commit(), Times.Once);
        }
Ejemplo n.º 2
0
        public void CreateTourney_ShouldCallUnitOfWork(string name, string userId)
        {
            var mockFactory           = new Mock <IFactory>();
            var mockTourneyRepository = new Mock <IRepository <Tourney> >();
            var mockUserRepository    = new Mock <IRepository <User> >();
            var mockPlayerRepository  = new Mock <IRepository <Player> >();
            var mockUnitOfWork        = new Mock <IUnitOfWork>();

            var service = new TourneyService(
                mockFactory.Object,
                mockTourneyRepository.Object,
                mockUserRepository.Object,
                mockPlayerRepository.Object,
                mockUnitOfWork.Object
                );

            service.CreateTourney(name, userId);

            mockUnitOfWork.Verify(x => x.Commit(), Times.Once);
        }
Ejemplo n.º 3
0
        public void CreateTourney_ShouldCallFactoryCreateTourney(string name)
        {
            var mockFactory           = new Mock <IFactory>();
            var mockTourneyRepository = new Mock <IRepository <Tourney> >();
            var mockUserRepository    = new Mock <IRepository <User> >();
            var mockPlayerRepository  = new Mock <IRepository <Player> >();
            var mockUnitOfWork        = new Mock <IUnitOfWork>();

            var service = new TourneyService(
                mockFactory.Object,
                mockTourneyRepository.Object,
                mockUserRepository.Object,
                mockPlayerRepository.Object,
                mockUnitOfWork.Object
                );

            service.CreateTourney(name, "");

            mockFactory.Verify(x => x.CreateTourney(name, It.IsAny <User>()), Times.Once);
        }
Ejemplo n.º 4
0
        public void GetTourneys_ShouldCallRepositoryEntities()
        {
            var mockFactory           = new Mock <IFactory>();
            var mockTourneyRepository = new Mock <IRepository <Tourney> >();
            var mockUserRepository    = new Mock <IRepository <User> >();
            var mockPlayerRepository  = new Mock <IRepository <Player> >();
            var mockUnitOfWork        = new Mock <IUnitOfWork>();

            var service = new TourneyService(
                mockFactory.Object,
                mockTourneyRepository.Object,
                mockUserRepository.Object,
                mockPlayerRepository.Object,
                mockUnitOfWork.Object
                );

            service.GetTourneys();

            mockTourneyRepository.Verify(x => x.Entities, Times.Once);
        }
Ejemplo n.º 5
0
        public void EditProduct_ShouldCallUnitOfWork()
        {
            var mockFactory           = new Mock <IFactory>();
            var mockTourneyRepository = new Mock <IRepository <Tourney> >();
            var mockUserRepository    = new Mock <IRepository <User> >();
            var mockPlayerRepository  = new Mock <IRepository <Player> >();
            var mockUnitOfWork        = new Mock <IUnitOfWork>();

            var service = new TourneyService(
                mockFactory.Object,
                mockTourneyRepository.Object,
                mockUserRepository.Object,
                mockPlayerRepository.Object,
                mockUnitOfWork.Object
                );

            var mockTourney = new Mock <Tourney>();

            service.EditTourney(mockTourney.Object);

            mockUnitOfWork.Verify(x => x.Commit(), Times.Once);
        }
Ejemplo n.º 6
0
        public void GetById_ShouldCallRepositoryWithCorrectId(int id)
        {
            //Arrange
            var mockFactory           = new Mock <IFactory>();
            var mockTourneyRepository = new Mock <IRepository <Tourney> >();
            var mockUserRepository    = new Mock <IRepository <User> >();
            var mockPlayerRepository  = new Mock <IRepository <Player> >();
            var mockUnitOfWork        = new Mock <IUnitOfWork>();

            var service = new TourneyService(
                mockFactory.Object,
                mockTourneyRepository.Object,
                mockUserRepository.Object,
                mockPlayerRepository.Object,
                mockUnitOfWork.Object
                );

            //Act
            service.GetById(id);

            //Assert
            mockTourneyRepository.Verify(x => x.GetById(id), Times.Once);
        }