コード例 #1
0
        //public PredictionServiceTests()
        //{
        //    var predictionRepository = new Mock<IPredictionRepository>();
        //    predictionRepository.Setup(x => x.CheckTypeResult(It.IsAny<string>())).ReturnsAsync((string result) =>
        //   {
        //       if (Convert.ToInt32(result.Substring(0, 1)) > Convert.ToInt32(result.Substring(2, 1))) return TypeResult.WinTeam1;
        //       else if (Convert.ToInt32(result.Substring(0, 1)) < Convert.ToInt32(result.Substring(2, 1))) return TypeResult.WinTeam2;
        //       else if (Convert.ToInt32(result.Substring(0, 1)) == Convert.ToInt32(result.Substring(2, 1))) return TypeResult.Draw;
        //       else return TypeResult.NNB;
        //   });

        //    predictionRepository.Setup(x => x.CompareResultsAsync(It.IsAny<Game>(), It.IsAny<Prediction>())).ReturnsAsync((Game z, Prediction y) =>
        //   {
        //       if (y.PredictedResult == z.Result)
        //           return 3;
        //       else if (y.PredictedTypeResult == z.typeResult)
        //           return 1;
        //       else
        //           return 0;
        //   });
        //    _predictionService = new PredictionService(predictionRepository.Object);
        //}

        public async Task CreateDb()
        {
            var options = new DbContextOptionsBuilder <StrikeNetDbContext>()
                          .UseInMemoryDatabase(databaseName: "StrikeNetTestDb")
                          .EnableSensitiveDataLogging()
                          .UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking)
                          .Options;

            var dbContext = new StrikeNetDbContext(options);

            if (await dbContext.Predictions.CountAsync() <= 0)
            {
                Prediction p1 = new Prediction()
                {
                    Id                  = 1,
                    GameId              = 1,
                    UserId              = User1,
                    PredictedResult     = "3-0",
                    PredictedTypeResult = TypeResult.WinTeam1
                };
                Prediction p2 = new Prediction()
                {
                    Id                  = 2,
                    GameId              = 3,
                    UserId              = User2,
                    PredictedResult     = "2-0",
                    PredictedTypeResult = TypeResult.WinTeam1
                };
                Prediction p3 = new Prediction()
                {
                    Id                  = 3,
                    GameId              = 3,
                    UserId              = User3,
                    PredictedResult     = "0-1",
                    PredictedTypeResult = TypeResult.WinTeam2
                };
                Prediction p4 = new Prediction()
                {
                    Id                  = 4,
                    GameId              = 4,
                    UserId              = User4,
                    PredictedResult     = "1-1",
                    PredictedTypeResult = TypeResult.Draw
                };
                dbContext.Predictions.Add(p1);
                dbContext.Predictions.Add(p2);
                dbContext.Predictions.Add(p3);
                dbContext.Predictions.Add(p4);
                await dbContext.SaveChangesAsync();
            }

            var identityRepository   = new IdentityRepository(_userManager, _roleManager, _signInManager);
            var predictionRepository = new PredictionRepository(identityRepository, dbContext);

            _predictionService2 = new PredictionService(predictionRepository);
        }
コード例 #2
0
        public async Task CreateDb()
        {
            var options = new DbContextOptionsBuilder <StrikeNetDbContext>()
                          .UseInMemoryDatabase(databaseName: "StrikeNetTestDb")
                          .EnableSensitiveDataLogging()
                          .UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking)
                          .Options;

            var dbContext = new StrikeNetDbContext(options);

            if (await dbContext.Games.CountAsync() <= 0)
            {
                Game g1 = new Game()
                {
                    Id    = 1,
                    Team1 = "FCB",
                    Team2 = "BVB",
                    Date  = DateTime.UtcNow
                };
                Game g2 = new Game()
                {
                    Id    = 2,
                    Team1 = "PSG",
                    Team2 = "Manchester City",
                    Date  = DateTime.UtcNow
                };
                Game g3 = new Game()
                {
                    Id    = 3,
                    Team1 = "Ajax",
                    Team2 = "Feyenoord",
                    Date  = DateTime.UtcNow
                };
                Game g4 = new Game()
                {
                    Id    = 4,
                    Team1 = "Liverpool",
                    Team2 = "Real Madrid",
                    Date  = DateTime.UtcNow
                };
                dbContext.Games.Add(g1);
                dbContext.Games.Add(g2);
                dbContext.Games.Add(g3);
                dbContext.Games.Add(g4);
                await dbContext.SaveChangesAsync();
            }

            var gameRepository = new GameRepository(dbContext);

            _gameService = new GameService(gameRepository);
        }
コード例 #3
0
        public async Task CreateDbWithMockIdentity()
        {
            var options = new DbContextOptionsBuilder <StrikeNetDbContext>()
                          .UseInMemoryDatabase(databaseName: "StrikeNetTestDb")
                          .EnableSensitiveDataLogging()
                          .UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking)
                          .Options;

            var _dbContext = new StrikeNetDbContext(options);

            TestUser = new UserIdentity {
                Score = 0
            };
            var identityRepository = new Mock <IIdentityRepository>();

            identityRepository.Setup(x => x.GetUserAsync(It.IsAny <Guid?>())).ReturnsAsync(TestUser);
            var predictionRepository = new PredictionRepository(identityRepository.Object, _dbContext);

            _predictionService = new PredictionService(predictionRepository);
        }
コード例 #4
0
 public GameRepository(StrikeNetDbContext dbContext)
 {
     _dbContext = dbContext;
 }
コード例 #5
0
 public PredictionRepository(IIdentityRepository identityRepository, StrikeNetDbContext dbContext)
 {
     _identityRepository = identityRepository;
     _dbContext          = dbContext;
 }