public void Init() { _efContext = EFContextFactory.CreateInMemoryEFContext(); _mapperMock = new Mock <IMapper>(); _regionsService = new RegionsService(_efContext, _mapperMock.Object); }
public void ReturnAnInstance_ParametersAreNotNull() { //Arrange var mockedData = new Mock <IShishaTimeData>(); //Act var service = new RegionsService(mockedData.Object); //Assert Assert.IsInstanceOf <RegionsService>(service); }
/// <summary>Initializes a new instance of the <see cref="FilterCarsForm"/> class.</summary> /// <param name="returnCriteria">The return criteria the parent form is currently set to.</param> /// <param name="con">The database connection.</param> /// <exception cref="ArgumentNullException">returnCriteria or con</exception> public FilterCarsForm(CarSearchCriteria returnCriteria, NpgsqlConnection con) { this.returnCriteria = returnCriteria ?? throw new ArgumentNullException(nameof(returnCriteria)); this.con = con ?? throw new ArgumentNullException(nameof(con)); manufacturersService = new ManufacturersService(con); countiresService = new CountriesService(con); regionsService = new RegionsService(con); InitializeComponent(); }
/// <summary>Initializes a new instance of the <see cref="CountriesForm"/> class.</summary> /// <param name="con">The connection to the postgreSQL database.</param> /// <exception cref="ArgumentNullException">con</exception> public CountriesForm(NpgsqlConnection con) { this.con = con ?? throw new ArgumentNullException(nameof(con)); countriesService = new CountriesService(con); regionsService = new RegionsService(con); // add test data. AddTestData(); InitializeComponent(); }
public async Task GetRegionsShouldReturnCollectionOfRegionsLolAppViewModel() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase("forumTest"); var db = new ApplicationDbContext(options.Options); var service = new RegionsService(db); var result = await service.GetRegions(); Assert.NotNull(result); Assert.IsType <RegionsLolAppViewModel>(result.First()); }
public static void TestFixtureSetup(TestContext context) { con = new NpgsqlConnection(cs); con.Open(); regionsService = new RegionsService(con); regionsRepository = new RegionsRepository(con); regionsRepository.Save(Region1); regionsRepository.Save(Region2); regionsRepository.Save(Region3); regionsRepository.Flush(); }
public JsonResult Get(int id, [FromServices] DapperService db) { if (id < 1) { return(Json(new { message = "не найден" })); } IEnumerable <RegionsModel> regionsModel = RegionsService.GetFull(db, id); if (regionsModel == null || regionsModel.Count() == 0) { return(Json(new { message = "не найден" }));; } return(Json(new { message = regionsModel }));; }
public async Task GetCollectionGamesShouldReturnCollectionPageGameViewModel() { var validGameId = 2660892488; int regionId = 1; var user = new ApplicationUser() { Email = "[email protected]", }; var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase("lolAddGameToUser"); var db = new ApplicationDbContext(options.Options); await db.Users.AddAsync(user); await db.SaveChangesAsync(); RegionsService regionsService = new RegionsService(db); await regionsService.UpdateRegions(); ChampionsService championsService = new ChampionsService(db); await championsService.UploadChamionsToDBAsync(); int expectedGameCount = 1; var userId = user.Id; var service = new GamesService(db, this.playersService, this.teamsService.Object); await service.AddGameToCollection(validGameId, regionId); var expectedGame = await db.Games.FirstOrDefaultAsync(g => g.RiotGameId == validGameId); await service.AddGameToUser(userId, validGameId); var result = (await service.GetCollectionGames(userId)).ToList(); var resultFirstGame = result.FirstOrDefault(); Assert.NotNull(result); Assert.NotNull(resultFirstGame); Assert.IsType <List <CollectionPageGameViewModel> >(result); Assert.IsType <CollectionPageGameViewModel>(resultFirstGame); Assert.Equal(expectedGameCount, result.Count()); Assert.Equal(expectedGame.RiotGameId, resultFirstGame.GameId); Assert.Equal(expectedGame.Teams.First().State, resultFirstGame.BlueTeam.State); Assert.Equal(expectedGame.Teams.Last().State, resultFirstGame.RedTeam.State); Assert.Equal(expectedGame.Teams[0].Players.First().Username, resultFirstGame.BlueTeam.Players.First().Username); Assert.Equal(expectedGame.Teams[1].Players.Last().Username, resultFirstGame.RedTeam.Players.Last().Username); }
public MainWindowViewModel( IApartmentsProvider apartmentsProvider, RegionsService regionsService, MapViewModel mapViewModel) { MapViewModel = mapViewModel ?? throw new ArgumentNullException(nameof(mapViewModel)); _apartmentsProvider = apartmentsProvider ?? throw new ArgumentNullException(nameof(apartmentsProvider)); _regionsService = regionsService ?? throw new ArgumentNullException(nameof(regionsService)); InitializeCommand = new RelayCommand(x => Initialize(), x => !_isInitialized); UpdateApartmentsListCommand = new RelayCommand(x => UpdateApartmentsList(), x => true); SaveSelectedRegionChangesCommand = new RelayCommand(SaveSelectedRegion, x => SelectedRegion != null); DeleteSelectedRegionCommand = new RelayCommand(DeleteSelectedRegion, x => SelectedRegion != null); CancelSelectedRegionCommand = new RelayCommand(CancelSelectedRegion, x => SelectedRegion != null); mapViewModel.RegionCreated += (sender, locations) => OnRegionCreated(locations); MaxApartmentPrice = 3000000; }
public async Task AddGameToCollectionShouldAddGameToDatabase() { var validGameId = 2657118595; int regionId = 1; var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase("lolAddGameToCollection"); var db = new ApplicationDbContext(options.Options); RegionsService regionsService = new RegionsService(db); await regionsService.UpdateRegions(); ChampionsService championsService = new ChampionsService(db); await championsService.UploadChamionsToDBAsync(); var expectedGame = await this.api.Match.GetMatchAsync(Region.Eune, validGameId); var expectedCollectionGameCount = 1; var service = new GamesService(db, this.playersService, this.teamsService.Object); await service.AddGameToCollection(validGameId, regionId); var resultGame = await db.Games.FirstOrDefaultAsync(); var firstPlayer = resultGame.Teams.First().Players.First(); var lastPlayer = resultGame.Teams.Last().Players.Last(); var firstPlayerChampion = await db.ChampionsStatic.FirstOrDefaultAsync(c => c.ChampionId == firstPlayer.PlayerChampions.First().ChampionId); var lastPlayerChampion = await db.ChampionsStatic.FirstOrDefaultAsync(c => c.ChampionId == lastPlayer.PlayerChampions.First().ChampionId); Assert.NotNull(resultGame); Assert.NotNull(resultGame.Teams); Assert.NotNull(resultGame.Teams[0].Players); Assert.NotNull(resultGame.Teams[1].Players); Assert.NotNull(resultGame.Teams[0]); Assert.NotNull(resultGame.Teams[1]); Assert.Equal(expectedCollectionGameCount, await db.Games.CountAsync()); Assert.Equal(expectedGame.GameId, resultGame.RiotGameId); Assert.Equal(expectedGame.Teams.First().Win, resultGame.Teams.First().State); Assert.Equal(expectedGame.Teams.Last().Win, resultGame.Teams.Last().State); Assert.Equal(expectedGame.ParticipantIdentities.First().Player.SummonerName, firstPlayer.Username); Assert.Equal(expectedGame.ParticipantIdentities.Last().Player.SummonerName, lastPlayer.Username); Assert.Equal(expectedGame.Participants.First().ChampionId, int.Parse(firstPlayerChampion.ChampionRiotId)); Assert.Equal(expectedGame.Participants.Last().ChampionId, int.Parse(lastPlayerChampion.ChampionRiotId)); }
public JsonResult Put(int id, [FromBody] OrdersViewModel model) { if (!ModelState.IsValid) { Response.StatusCode = (int)HttpStatusCode.BadRequest; return Json(new { message = Validation.getValidationErrors(model) }); } if (model.Items == null || model.Items.Count() == 0) { return Json(new { message = "Список товаров не может быть пустыми" }); } IEnumerable<int> validItems = ItemsService.getValidItemsList(dapperService, model.Items).Select(x => x.Id); if (validItems == null || validItems.Count() == 0) { return Json(new { message = "Следующие товары не существует в базе", model.Items }); } List<int> inValidItems = new List<int>(); foreach (var i in model.Items) { if (!validItems.Contains(i)) { inValidItems.Add(i); } } if (inValidItems != null && inValidItems.Count() > 0) { return Json(new { message = "Следующие товары не существует в базе", Items = inValidItems }); } if (!RegionsService.checkForExists(dapperService, model.RegionId)) { return Json(new { message = $"RegionId={model.RegionId} не существует в базе" }); } OrdersModel item = new OrdersModel() { Id = id, RegionId = model.RegionId, ItemsIds = model.Items }; bool isSaved = ordersService.Update(item, id); return Json(new { message = isSaved ? "Сохранено" : "Не cохранено" }); }
public JsonResult Post([FromBody] OrdersViewModel model) { if (!ModelState.IsValid) { Response.StatusCode = (int)HttpStatusCode.BadRequest; return Json(new { message = Validation.getValidationErrors(model) }); } if (model.Items == null || model.Items.Count() == 0) { return Json(new { message = "Список товаров не может быть пустыми" }); } if (!Int32.TryParse(User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier)?.Value, out int id)) { return Json(new { message = "Пользователь не существует" }); } IEnumerable<int> validItems = ItemsService.getValidItemsList(dapperService, model.Items).Select(x => x.Id); if (validItems == null || validItems.Count() == 0) { return Json(new { message = "Следующие товары не существует в базе", model.Items }); } List<int> inValidItems = new List<int>(); foreach(var i in model.Items) { if(!validItems.Contains(i)){ inValidItems.Add(i); } } if(inValidItems != null && inValidItems.Count() > 0) { return Json(new { message = "Следующие товары не существует в базе" , Items = inValidItems }); } if (!RegionsService.checkForExists(dapperService, model.RegionId)) { return Json(new { message = $"RegionId={model.RegionId} не существует в базе"}); } OrdersModel items = new OrdersModel(model){ UserId = id }; bool isSaved = ordersService.Save(items); return Json(new { message = isSaved ? "Сохранено" : "Не cохранено" }); }
public async Task AddGameToUserShouldThrowArgumentExceptionIfGivenInvalidUserId(string userId) { var validGameId = 2657118595; int regionId = 1; var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase("lolAddGameToUser"); var db = new ApplicationDbContext(options.Options); RegionsService regionsService = new RegionsService(db); await regionsService.UpdateRegions(); ChampionsService championsService = new ChampionsService(db); await championsService.UploadChamionsToDBAsync(); var service = new GamesService(db, this.playersService, this.teamsService.Object); await service.AddGameToCollection(validGameId, regionId); await Assert.ThrowsAsync <ArgumentException>(async() => await service.AddGameToUser(userId, validGameId)); }
public async Task GetGameCountShouldReturnCorrectNumberOfGamesInUsersCollection() { var validGameId = 2657118595; var secondGameId = 2652692459; int regionId = 1; var user = new ApplicationUser() { Email = "[email protected]", }; var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase("lolGameCount"); var db = new ApplicationDbContext(options.Options); await db.Users.AddAsync(user); await db.SaveChangesAsync(); var userId = user.Id; int expectedGameCount = 2; RegionsService regionsService = new RegionsService(db); await regionsService.UpdateRegions(); ChampionsService championsService = new ChampionsService(db); await championsService.UploadChamionsToDBAsync(); var service = new GamesService(db, this.playersService, this.teamsService.Object); await service.AddGameToCollection(validGameId, regionId); await service.AddGameToUser(userId, validGameId); await service.AddGameToCollection(secondGameId, regionId); await service.AddGameToUser(userId, secondGameId); var result = service.GetGameCount(userId); Assert.Equal(expectedGameCount, result); }
public async Task AddGameToUserShouldAddTheGameToGivenUserById() { var validGameId = 2657118595; int regionId = 1; var user = new ApplicationUser() { Email = "[email protected]", }; var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase("lolAddGameToUserLol"); var db = new ApplicationDbContext(options.Options); await db.Users.AddAsync(user); await db.SaveChangesAsync(); RegionsService regionsService = new RegionsService(db); await regionsService.UpdateRegions(); ChampionsService championsService = new ChampionsService(db); await championsService.UploadChamionsToDBAsync(); var userId = user.Id; var service = new GamesService(db, this.playersService, this.teamsService.Object); await service.AddGameToCollection(validGameId, regionId); var gameId = (await db.Games.FirstOrDefaultAsync(g => g.RiotGameId == validGameId)).GameId; await service.AddGameToUser(userId, validGameId); var userGames = await db.UserGames.FirstOrDefaultAsync(); Assert.NotNull(userGames); Assert.Equal(userId, userGames.UserId); Assert.Equal(gameId, userGames.GameId); }
public async Task RemoveGameFromCollectionShouldRemoveTheGameFromUsersCollection() { var validGameId = 2660892488; int regionId = 1; var user = new ApplicationUser() { Email = "[email protected]", }; var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase("lolRemoveGameToUser"); var db = new ApplicationDbContext(options.Options); await db.Users.AddAsync(user); await db.SaveChangesAsync(); RegionsService regionsService = new RegionsService(db); await regionsService.UpdateRegions(); ChampionsService championsService = new ChampionsService(db); await championsService.UploadChamionsToDBAsync(); int expectedGameCount = 0; var userId = user.Id; var service = new GamesService(db, this.playersService, this.teamsService.Object); await service.AddGameToCollection(validGameId, regionId); await service.AddGameToUser(userId, validGameId); await service.RemoveGameFromCollection(userId, validGameId); var tryGetGame = await db.Games.FirstOrDefaultAsync(g => g.RiotGameId == validGameId); Assert.Null(tryGetGame); Assert.Equal(expectedGameCount, db.Games.Count()); Assert.Equal(expectedGameCount, db.UserGames.Count()); }
public IActionResult GetResult(int id) { if (!RegionsService.checkForExists(dapperService, id)) { return(Content($"RegionId = {id} не существует в базе")); } IEnumerable <OrdersModel> orders = OrdersService.GetOrdersByRegionId(dapperService, id); using (var workbook = new XLWorkbook()) { var worksheet = workbook.Worksheets.Add("Orders"); var currentRow = 1; worksheet.Cell(currentRow, 1).Value = "Id"; worksheet.Cell(currentRow, 2).Value = "Сумма"; worksheet.Cell(currentRow, 3).Value = "Клиент"; worksheet.Cell(currentRow, 4).Value = "Дата создание"; worksheet.Cell(currentRow, 5).Value = "Регион"; foreach (var order in orders) { currentRow++; worksheet.Cell(currentRow, 1).Value = order.Id; worksheet.Cell(currentRow, 2).Value = order.User.FullName; worksheet.Cell(currentRow, 3).Value = order.Sum; worksheet.Cell(currentRow, 4).Value = order.CreatedTime; worksheet.Cell(currentRow, 5).Value = order.Region.Name.Trim(); } using (var stream = new MemoryStream()) { workbook.SaveAs(stream); var content = stream.ToArray(); return(File( content, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "ЗаказыПоРегиону.xlsx")); } } }
public void AddingRegion() { var list = new List <Region>(); var mockRepo = new Mock <IDeletableEntityRepository <Region> >(); mockRepo.Setup(x => x.AllAsNoTracking()).Returns(list.AsQueryable()); mockRepo.Setup(x => x.AddAsync(It.IsAny <Region>())); var service = new RegionsService(mockRepo.Object); var region = new Region { Id = 1, Name = "Sofia", }; list.Add(region); var expected = new List <KeyValuePair <string, string> >() { new KeyValuePair <string, string>("1", "Sofia"), }; Assert.Equal(expected, service.GetAllAsKeyValuePairs()); }
public void ReturnCorrectResult() { //Arrange var mockedRegion = new Mock <Region>(); var list = new List <Region> { mockedRegion.Object }; var regionsRepoMock = new Mock <IEntityFrameworkRepository <Region> >(); regionsRepoMock.Setup(x => x.All).Verifiable(); regionsRepoMock.Setup(x => x.All).Returns(list.AsQueryable()); var dataMock = new Mock <IShishaTimeData>(); dataMock.Setup(x => x.Regions).Verifiable(); dataMock.Setup(x => x.Regions).Returns(regionsRepoMock.Object); var regionsService = new RegionsService(dataMock.Object); //Act var regions = regionsService.GetAllRegions(); //Assert Assert.AreEqual(list, regions); }
public void CallRegionsRepository_AllProperty() { //Arrange var mockedRegion = new Mock <Region>(); var list = new List <Region> { mockedRegion.Object }; var regionsRepoMock = new Mock <IEntityFrameworkRepository <Region> >(); regionsRepoMock.Setup(x => x.All).Verifiable(); regionsRepoMock.Setup(x => x.All).Returns(list.AsQueryable()); var dataMock = new Mock <IShishaTimeData>(); dataMock.Setup(x => x.Regions).Verifiable(); dataMock.Setup(x => x.Regions).Returns(regionsRepoMock.Object); var regionsService = new RegionsService(dataMock.Object); //Act regionsService.GetAllRegions(); //Assert regionsRepoMock.Verify(x => x.All, Times.Once()); }
public void BeforeEach() { fixture = new Fixture().Customize(new AutoMoqCustomization()); fixture.Customize <Spot>(c => c .Without(x => x.Region)); fixture.Customize <Lodgment>(c => c .Without(x => x.Spot) .Without(y => y.Bookings) .Without(y => y.Reviews)); fixture.Customize <CategorySpot>(c => c .Without(x => x.Category) .Without(x => x.Spot)); moqRepository = new Mock <IRegionsRepository>(MockBehavior.Strict); moqSpotsService = new Mock <ISpotsService>(MockBehavior.Strict); expectedSpot = fixture.Create <Spot>(); expectedRegions = fixture.CreateMany <Region>(); spot = fixture.Create <Spot>(); expectedRegion = fixture.Create <Region>(); regionId = fixture.Create <int>(); expectedPaginatedSpots = fixture.Create <PaginatedModel <Spot> >(); expectedPaginatedRegions = fixture.Create <PaginatedModel <Region> >(); paging = fixture.Create <PagingModel>(); service = new RegionsService(moqRepository.Object, moqSpotsService.Object); }
public RegionsController(KWMContext context, RegionsService regionsService) { _context = context; _regionsService = regionsService; }