Exemplo n.º 1
0
 public FixtureBusiness(IUnitOfWork _unitOfWork)
 {
     unitOfWork        = _unitOfWork;
     playerRepository  = new PlayerRepository(unitOfWork);
     teamRepository    = new TeamRepository(unitOfWork);
     fixtureRepository = new FixtureRepository(unitOfWork);
 }
Exemplo n.º 2
0
        protected override void FinalizeSetUp()
        {
            _fixture = FixtureRepository.Create <UserFixture>();

            RedisApiOutputCache = new RedisOutputCache(new JsonSerializer(), _connectionSettings);

            RedisApiOutputCache.Add(_fixture.Id.ToString(), _fixture, DateTime.Now.AddSeconds(60));
        }
Exemplo n.º 3
0
        public async void Post_test()
        {
            var product  = FixtureRepository.Build <Product>().Without(p => p.Id).Create();
            var response = await _client.PostAsync("api/products", product);

            response.Should().NotBeNull();
            response.StatusCode.Should().Be(HttpStatusCode.Created);
        }
Exemplo n.º 4
0
        public void PostSync_Test()
        {
            Product product = FixtureRepository.Build <Product>().Without(item => item.Id).Create();

            IHttwrapResponse result = _client.Post("api/products", product);

            result.StatusCode.ShouldBeEquivalentTo(HttpStatusCode.Created);
            result.Should().NotBeNull();
        }
Exemplo n.º 5
0
        public async void Get_ByIdWithRequestTimeout_Test()
        {
            var product = FixtureRepository.Build <Product>().Without(p => p.Id).Create();
            await _client.PostAsync("api/products", product, null, null, TimeSpan.FromSeconds(1));

            var response = await _client.GetAsync <Product>("api/products/1");

            response.Data.Should().NotBeNull();
        }
Exemplo n.º 6
0
        public async void Get_ById_test()
        {
            var product = FixtureRepository.Build <Product>().Without(p => p.Id).Create();
            await _client.PostAsync("api/products", product);

            var response = await _client.GetAsync <Product>("api/products/1");

            response.Data.Should().NotBeNull();
        }
Exemplo n.º 7
0
        public async void Get_All_test()
        {
            Product product = FixtureRepository.Build <Product>().Without(p => p.Id).Create();
            await _client.PostAsync("api/products", product);

            IHttwrapResponse <IEnumerable <Product> > response = await _client.GetAsync <IEnumerable <Product> >("api/products");

            response.Data.Should().NotBeNullOrEmpty();
            response.Data.Count().Should().Be(1);
        }
Exemplo n.º 8
0
    private void CalculateSingleBetPoints(Bet bet, Player player)
    {
        var fixture = FixtureRepository.GetFixtureById(bet.FixtureId.Value);

        if (!fixture.Ended)
        {
            return;
        }
        BetReposiory.CheckBet(bet.Id);
    }
Exemplo n.º 9
0
        public void GetAllSync_Test()
        {
            Product product = FixtureRepository.Build <Product>().Without(p => p.Id).Create();

            IHttwrapResponse savedProduct = _client.Post("api/products", product);

            IHttwrapResponse result = _client.Get("api/products", savedProduct);

            result.StatusCode.ShouldBeEquivalentTo(HttpStatusCode.OK);
        }
Exemplo n.º 10
0
        public async void Delete_test()
        {
            Product product = FixtureRepository.Build <Product>().Without(p => p.Id).Create();
            await _client.PostAsync("api/products", product);

            IHttwrapResponse response = await _client.DeleteAsync("api/products/1");

            response.Should().NotBeNull();
            response.StatusCode.Should().Be(HttpStatusCode.NoContent);
        }
Exemplo n.º 11
0
        public async void Get_ById_ReadAs_test()
        {
            Product product = FixtureRepository.Build <Product>().Without(p => p.Id).Create();
            await _client.PostAsync("api/products", product);

            IHttwrapResponse response = await _client.GetAsync("api/products/1");

            Product result = response.ReadAs <Product>();

            result.Should().NotBeNull();
        }
Exemplo n.º 12
0
        public void DeleteSync_Test()
        {
            Product product = FixtureRepository.Build <Product>().Without(p => p.Id).Create();

            _client.Post("api/products", product);

            IHttwrapResponse result = _client.Delete("api/products/1");

            result.Should().NotBeNull();
            result.StatusCode.ShouldBeEquivalentTo(HttpStatusCode.NoContent);
        }
Exemplo n.º 13
0
    private void CalculateQualifTeamPoints(Player player)
    {
        var fixtures = FixtureRepository.GetFixtureByRoundId(1);

        if (fixtures.Where(x => !x.Ended).Count() > 0)
        {
            return;
        }

        var qualifiedTeams = TeamRepository.GetAllTeams().Where(x => x.CurrentRoundId == 2);
        var betTeams       = BetReposiory.GetQualifTeams(player.Id, false);

        if (betTeams.Count() != 16)
        {
            return;                       //Reset to 16
        }
        BetReposiory.CheckQualifTeams(player.Id);

        var crossTeams = qualifiedTeams.Where(x => betTeams.Contains(x.Id));
        var c          = crossTeams.Count();

        if (c < 2)
        {
            PlayerRepository.SetScore(-10, player.Id);
            return;
        }

        if (c < 5)
        {
            PlayerRepository.SetScore(-5, player.Id);
            return;
        }

        if (c < 8)
        {
            return;
        }

        if (c < 13)
        {
            PlayerRepository.SetScore(5, player.Id);
            return;
        }

        if (c < 16)
        {
            PlayerRepository.SetScore(8, player.Id);
            return;
        }

        PlayerRepository.SetScore(10, player.Id);
        return;
    }
Exemplo n.º 14
0
        public async void Interceptor_test()
        {
            Product product = FixtureRepository.Build <Product>().Without(p => p.Id).Create();
            await _client.PostAsync("api/products", product);

            IHttwrapConfiguration configuration = new HttwrapConfiguration(BaseAddress);
            HttwrapClient         client        = new HttwrapClient(configuration);

            client.AddInterceptor(new DummyInterceptor());
            var response = await client.GetAsync("api/products/1");

            response.StatusCode.ShouldBeEquivalentTo(HttpStatusCode.Accepted);
        }
        public void adds_item_to_cache()
        {
            //ClearDb();
            var    fixture = FixtureRepository.Create <UserFixture>();
            string key     = fixture.Id.ToString();

            RedisApiOutputCache.Add(key, fixture, DateTime.Now.AddSeconds(60));
            var result = RedisApiOutputCache.Get <UserFixture>(key);

            result.Should().NotBeNull();
            result.Id.ShouldBeEquivalentTo(fixture.Id);
            result.Name.ShouldBeEquivalentTo(fixture.Name);
        }
        public void does_not_return_item_that_has_expired()
        {
            //TODO: FIX ME
            var fixture = FixtureRepository.Create <UserFixture>();

            RedisApiOutputCache.Add("expired-item", fixture, DateTime.Now.AddSeconds(3));

            Thread.Sleep(TimeSpan.FromSeconds(5));

            var result = RedisApiOutputCache.Get <UserFixture>("expired-item");

            result.Should().BeNull();
        }
Exemplo n.º 17
0
        public MainViewModel()
        {
            _repo = new FixtureRepository();

            _messenger = new Messenger(
                ConfigurationManager.ConnectionStrings["ServerConnection"].ConnectionString,
                _repo
                );

            SendMessageCommand     = new RelayCommand(SendMessage);
            StartPageLoadedCommand = new RelayCommand(StartPageLoaded);
            SignInCommand          = new RelayCommand <object>(SignIn);
            SignOutCommand         = new RelayCommand(SignOut);
            ExitCommand            = new RelayCommand(Exit);
            CurrentReceiver        = _repo.Contacts[0];
        }
        public async Task GetCountries_Should_Return_Value()
        {
            //Arrange
            var getCountriesResponse = FixtureRepository.Create <GetCountriesResponse>();

            addressServiceMock.Setup(x => x.GetCountriesAsync()).Returns(Task.FromResult <GetCountriesResponse>(getCountriesResponse));
            //Act
            var result = await addressInformationController.GetCountries();

            //Assert
            result.Should().NotBeNull();
            result.Should().BeOfType <ObjectResult>();
            var response = (ObjectResult)result;

            response.StatusCode.Should().Be((int)HttpStatusCode.OK);
        }
Exemplo n.º 19
0
        public async Task LoginAsync_Should_Return_NotFound_When_UserEntity_Is_Null()
        {
            //Arrange
            string accessToken  = Guid.NewGuid().ToString();
            var    loginRequest = FixtureRepository.Create <LoginRequest>();

            _userRepositoryMock
            .Setup(x => x.GetUserByCredentialsAsync(loginRequest.EmailAddress, loginRequest.Password))
            .Returns(Task.FromResult(default(UserEntity)));

            //Act
            var result = await _userService.LoginAsync(loginRequest);

            //Assert
            result.IsSuccess.Should().BeFalse();
            result.AccessToken.Should().BeNullOrEmpty();
        }
        public void retrieves_item_from_cache()
        {
            var fixture = FixtureRepository.Create <UserFixture>();

            RedisApiOutputCache.Add(fixture.Id.ToString(), fixture, DateTime.Now.AddSeconds(60));
            var result = RedisApiOutputCache.Get <UserFixture>(fixture.Id.ToString());

            result.Should().NotBeNull();
            result.Should().BeOfType <UserFixture>();

            result.Id.ShouldBeEquivalentTo(fixture.Id);
            result.Name.ShouldBeEquivalentTo(fixture.Name);

            result.DateOfBirth.Day.ShouldBeEquivalentTo(fixture.DateOfBirth.Day);
            result.DateOfBirth.Month.ShouldBeEquivalentTo(fixture.DateOfBirth.Month);
            result.DateOfBirth.Year.ShouldBeEquivalentTo(fixture.DateOfBirth.Year);
        }
Exemplo n.º 21
0
        public async Task Login_Should_Return_Success()
        {
            //Arrange
            var loginRequest  = FixtureRepository.Create <LoginRequest>();
            var loginResponse = FixtureRepository.Create <LoginResponse>();

            userServiceMock.Setup(x => x.LoginAsync(loginRequest)).Returns(Task.FromResult <LoginResponse>(loginResponse));

            //Act
            var result = await usersController.Login(loginRequest);

            //Assert
            result.Should().NotBeNull();
            result.Should().BeOfType <ObjectResult>();
            var response = (ObjectResult)result;

            response.StatusCode.Should().Be((int)HttpStatusCode.OK);
        }
        public void adding_item_with_duplicate_key_updates_original()
        {
            var fixture = FixtureRepository.Create <UserFixture>();

            var key = "user";

            RedisApiOutputCache.Add(key, fixture, DateTime.Now.AddSeconds(60));

            var differentUser = FixtureRepository.Create <UserFixture>();

            RedisApiOutputCache.Add(key, differentUser, DateTime.Now.AddSeconds(60));

            var result = RedisApiOutputCache.Get <UserFixture>(key);

            result.Should().NotBeNull();
            result.Id.ShouldBeEquivalentTo(differentUser.Id);
            result.Name.ShouldBeEquivalentTo(differentUser.Name);
        }
Exemplo n.º 23
0
        protected override void FinalizeSetUp()
        {
            _expected = new Todo
            {
                name     = "Do your homework!",
                priority = 1
            };

            _firebaseRequestManagerMock = MockFor <IFirebaseRequestManager>();

            _expectedResponse = FixtureRepository.Build <RestResponse>()
                                .With(response => response.Content, _expected.ToJson())
                                .With(response => response.StatusCode, HttpStatusCode.OK)
                                .Without(response => response.Request)
                                /*Ignore request field because it has no public constructor, is an abstract or non-public type*/
                                .Create();

            _firebaseClient = new FirebaseClient(_firebaseRequestManagerMock.Object);
        }
Exemplo n.º 24
0
        public async void Put_test()
        {
            const string PUT_TEST_PRODUCT_NAME = "Put Test Product";

            Product product = FixtureRepository.Build <Product>().Without(p => p.Id).Create();
            await _client.PostAsync("api/products", product);

            product.Name = PUT_TEST_PRODUCT_NAME;
            IHttwrapResponse putResponse = await _client.PutAsync("api/products/1", product);

            IHttwrapResponse <Product> getResponse = await _client.GetAsync <Product>("api/products/1");

            putResponse.Should().NotBeNull();
            putResponse.StatusCode.Should().Be(HttpStatusCode.NoContent);

            getResponse.Should().NotBeNull();
            getResponse.Data.Should().NotBeNull();
            getResponse.Data.Name.ShouldBeEquivalentTo(PUT_TEST_PRODUCT_NAME);
        }
Exemplo n.º 25
0
        private static void SimulateGameweek(Season season, int gameweekNumber)
        {
            var fixtures = FixtureRepository.GetAllFixtures(season, gameweekNumber);
            var teams    = TeamRepository.GetAllTeams(season);

            foreach (var predictionStrategy in PredictionStrategies.Where(ps => ps.CanPredict(season)))
            {
                Console.WriteLine(predictionStrategy.Name);

                foreach (var fixture in fixtures)
                {
                    var homeTeam = teams[fixture.HomeTeamId];
                    var awayTeam = teams[fixture.AwayTeamId];

                    var predicted = predictionStrategy.PredictScore(fixture, season);

                    Console.WriteLine($"{homeTeam.ShortName} {Display.Score(predicted)} {awayTeam.ShortName}");
                }

                Console.WriteLine();
            }
        }
Exemplo n.º 26
0
        public async void Put_test()
        {
            var name = "Put Test Product";

            var product = FixtureRepository.Build <Product>()
                          .With(p => p.Name, name)
                          .Without(p => p.Id)
                          .Create();

            await _client.PostAsync("api/products", product);

            var putResponse = await _client.PutAsync("api/products/1", product);

            var getResponse = await _client.GetAsync <Product>("api/products/1");

            putResponse.Should().NotBeNull();
            putResponse.StatusCode.Should().Be(HttpStatusCode.NoContent);

            getResponse.Should().NotBeNull();
            getResponse.Data.Should().NotBeNull();
            getResponse.Data.Name.ShouldBeEquivalentTo(name);
        }
Exemplo n.º 27
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="Model"></param>
        /// <returns></returns>
        public IEnumerable <SelectListItem> GetFixture(Fixture_VM Model)
        {
            IEnumerable <Fixture_VM> query = new FixtureRepository().GetData(Model);

            IEnumerable <SelectListItem> list;

            if (Model.FixtureID != null)
            {
                list = query.Select(x => new SelectListItem()
                {
                    Text = x.FixtureName + " (" + x.FixtureCost + ")", Value = x.FixtureID.ToString(), Selected = (x.FixtureID == Model.FixtureID ? true : false)
                }).ToList();
            }
            else
            {
                list = query.Select(x => new SelectListItem()
                {
                    Text = x.FixtureName + " (" + x.FixtureCost + ")", Value = x.FixtureID.ToString()
                }).ToList();
            }

            return(list.OrderBy(x => x.Text));
        }
Exemplo n.º 28
0
        public async Task LoginAsync_Should_Return_Result()
        {
            //Arrange
            string accessToken  = Guid.NewGuid().ToString();
            var    loginRequest = FixtureRepository.Create <LoginRequest>();
            var    userEntity   = FixtureRepository.Build <UserEntity>().Without(x => x.Patients).Without(x => x.UserGroup)
                                  .Create();

            _userRepositoryMock
            .Setup(x => x.GetUserByCredentialsAsync(loginRequest.EmailAddress, loginRequest.Password))
            .Returns(Task.FromResult(userEntity));
            _tokenProviderMock
            .Setup(x => x.GenerateTokenAsync(userEntity.Id, userEntity.EmailAddress, userEntity.UserGroupId))
            .Returns(Task.FromResult(accessToken));

            //Act
            var result = await _userService.LoginAsync(loginRequest);

            //Assert
            result.IsSuccess.Should().BeTrue();
            result.AccessToken.Should().NotBeNullOrEmpty();
            result.AccessToken.Should().Be(accessToken);
        }
Exemplo n.º 29
0
        private static void RunSeasonPredictions()
        {
            var seasons = new[]
            {
                Season.Season1819,
                Season.Season1920,
                Season.Season2021,
            };

            foreach (var season in seasons)
            {
                Console.WriteLine(Display.Season(season));

                var fixtures = FixtureRepository.GetAllCompletedFixtures(season);

                foreach (var predictionStrategy in PredictionStrategies)
                {
                    if (predictionStrategy.CanPredict(season))
                    {
                        var totalPoints = 0;

                        foreach (var fixture in fixtures)
                        {
                            var predicted = predictionStrategy.PredictScore(fixture, season);

                            var points = PointsCalculator.CalculatePoints(predicted, fixture.FinalScore);

                            totalPoints += points;
                        }

                        Console.WriteLine($"{predictionStrategy.Name}: {totalPoints}");
                    }
                }

                Console.WriteLine();
            }
        }
        public void added_item_stored_with_expiry()
        {
            var fixture = FixtureRepository.Create <UserFixture>();

            var key = fixture.Id.ToString();

            var expiration = DateTime.Now.AddSeconds(60);

            fixture.ExpireAt = expiration;

            RedisApiOutputCache.Add(fixture.Id.ToString(), fixture, expiration);

            var result = RedisApiOutputCache.Get <UserFixture>(key);

            //todo: would be good to check they are the same value.. without this rubbish!
            //TODO: Jil seralize date as UTC by default, here is more detail https://github.com/kevin-montrose/Jil/issues/129
            expiration.Day.ShouldBeEquivalentTo(result.ExpireAt.Day);
            expiration.Month.ShouldBeEquivalentTo(result.ExpireAt.Month);
            expiration.Year.ShouldBeEquivalentTo(result.ExpireAt.Year);
            expiration.Hour.ShouldBeEquivalentTo(result.ExpireAt.Hour);
            expiration.Minute.ShouldBeEquivalentTo(result.ExpireAt.Minute);
            expiration.Second.ShouldBeEquivalentTo(result.ExpireAt.Second);
            expiration.Millisecond.ShouldBeEquivalentTo(result.ExpireAt.Millisecond);
        }