public ActionResult _Difficulty(int difficulty) { List <Questions> questions = new List <Questions>(); if (Session["IDUser"] != null) { // GET QUESTIONS BY DIFFICULTY AND IDUSER AGAR USER YANG SEDANG LOGIN // TIDAK MENJAWAB PERTANYAAAN DARI DIA SENDIRI questions = new HomeService().getAllQuestionsByIDUserAndDifficulty((int)Session["IDUser"], difficulty); } else { // GET ALL QUESTIONS TANPA MELIHAT IDUSER KARENA BLM LOGIN questions = new HomeService().getAllQuestionsByDifficulty(difficulty); } switch (difficulty) { case 1: ViewBag.header = "Easy"; break; case 2: ViewBag.header = "Medium"; break; case 3: ViewBag.header = "Hard"; break; }// END OF SWITCH CASE return(PartialView(questions)); }
public void CreateShipmentAddNewShipmentToDataBase() { var optionsBuilder = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase("nameOfDatabase"); var db = new ApplicationDbContext(optionsBuilder.Options); var input = new OfferInputModel() { From = 1, To = 17, CountOfPallets = 3, Length = 1.74, Width = 2, Height = 2, Weight = 500, IsExpressDelivery = true, IsFragile = true }; var homeService = new HomeService(db); homeService.CreateShipment(input); int result = db.Shipments.Count(); Assert.Equal(1, result); }
public HomeController(ModelContext context, IHostingEnvironment hostingEnvironment) { _context = context; homeService = new HomeService(_context); buyerService = new BuyerService(_context); _hostingEnvironment = hostingEnvironment; }
public void CheckIpAddressValidIpTest(string ipAddressValue) { var mock = new Mock <INetworkAddressRepository>(); var serviceInstance = new HomeService(mock.Object); Assert.True(serviceInstance.CheckIpAddress(ipAddressValue)); }
public async Task <IActionResult> Create([Bind("Title,Upload,Photo,Id,Content")] HomeService homeService) { if (homeService.Upload == null) { ModelState.AddModelError("Upload", "Şəkil məcburidir"); } else { if (homeService.Upload.ContentType != "image/jpeg" && homeService.Upload.ContentType != "image/png" && homeService.Upload.ContentType != "image/gif") { ModelState.AddModelError("Upload", "Siz yalnız png,jpg və ya gif faylı yükləyə bilərsiniz"); } if (homeService.Upload.Length > 1048576) { ModelState.AddModelError("Upload", "Fayl ölcüsu maximum 1MB ola bilər"); } } if (ModelState.IsValid) { var fileName = _fileManager.Upload(homeService.Upload); homeService.Photo = fileName; _context.Add(homeService); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(homeService)); }
public JsonResult RestoreGrid(string TableName) { HomeService homeService = new HomeService(); ColumnGridDetailsDto gridInfo = homeService.GetDefaultGridInfo(TableName); return(Json(gridInfo, JsonRequestBehavior.AllowGet)); }
public async Task GetRandomCake_Home_Index_WhenFirstProductIsDeletedTrue_ShouldReturnProductId2() { var db = this.SetDb(); using (db) { //Arrange db.Products.Add(new Product { Name = "Chocolate Peanut Cake", Price = 35.50m, Description = "This Chocolate and Peanut Butter Drip Cake is completely sinful.", Image = "https://res.cloudinary.com/cakeit/image/upload/ar_1:1,c_fill,g_auto,e_art:hokusai/v1544136590/Chocolate_and_Peanut_cake.jpg", Category = new Category { Id = 1, Type = Models.Enums.CategoryType.Cake }, IsDeleted = true }); db.Products.Add(new Product { Name = "Chocolate Lovers Cake", Price = 30.00m, Description = "This Chocolate Lovers Cake is completely sinful.", Image = "https://res.cloudinary.com/cakeit/image/upload/ar_1:1,c_fill,g_auto,e_art:hokusai/v1544136590/Chocolate_and_Peanut_cake.jpg", Category = new Category { Id = 1, Type = Models.Enums.CategoryType.Cake } }); await db.SaveChangesAsync(); var repo = new Repository <Product>(db); var homeService = new HomeService(repo, this.Mapper); var actual = repo.All().SingleOrDefault(p => p.Id == 2).Name; //Act var result = await homeService.GetRandomCake(); //Assert Assert.Equal(actual, result.Name); } }
public ActionResult Index() { var service = new HomeService(); var menus = service.GetMenus("/Files/Menu/HomeMenu.xml"); return(View()); }
public void GetContactMessageByIdShouldReturnsMessageCorrect() { var options = new DbContextOptionsBuilder <WAGDbContext>() .UseInMemoryDatabase(databaseName: "Get_Message_ById_Db") .Options; var dbContext = new WAGDbContext(options); var service = new HomeService(dbContext, null); string userId = Guid.NewGuid().ToString(); var message = new ContactMessage() { Title = "Test title", TextBody = "Test textBody", WAGUserId = userId, }; dbContext.ContactMessages.Add(message); dbContext.SaveChanges(); var messageId = dbContext.ContactMessages.LastOrDefault().Id; var savedMessage = service.GetContactMessageById(messageId); Assert.Equal(message, savedMessage); }
public async Task GetRandomCake__Home_Index_ShouldReturnRandomPrduct() { var db = this.SetDb(); using (db) { //Arrange db.Products.Add(new Product { Name = "Chocolate Peanut Cake", Price = 35.50m, Description = "This Chocolate and Peanut Butter Drip Cake is completely sinful.", Image = "https://res.cloudinary.com/cakeit/image/upload/ar_1:1,c_fill,g_auto,e_art:hokusai/v1544136590/Chocolate_and_Peanut_cake.jpg", Category = new Category { Id = 1, Type = Models.Enums.CategoryType.Cake } }); db.Products.Add(new Product { Name = "Chocolate Lovers Cake", Price = 30.00m, Description = "This Chocolate Lovers Cake is completely sinful.", Image = "https://res.cloudinary.com/cakeit/image/upload/ar_1:1,c_fill,g_auto,e_art:hokusai/v1544136590/Chocolate_and_Peanut_cake.jpg", Category = new Category { Id = 1, Type = Models.Enums.CategoryType.Cake } }); await db.SaveChangesAsync(); var repo = new Repository <Product>(db); var homeService = new HomeService(repo, this.Mapper); //Act var result = await homeService.GetRandomCake(); //Assert result.ShouldNotBeNull(); } }
public void SaveContactMessageShouldSaveContactMsgCorrect() { var options = new DbContextOptionsBuilder <WAGDbContext>() .UseInMemoryDatabase(databaseName: "Save_ContactMessage_Db") .Options; var dbContext = new WAGDbContext(options); var service = new HomeService(dbContext, null); var contactMessageViewModel = new ContactMessageViewModel() { Title = "Test title", TextBody = "Test textBody", }; string userId = Guid.NewGuid().ToString(); service.SaveContactMessage(contactMessageViewModel, userId); var savedMessage = dbContext.ContactMessages.LastOrDefault(); Assert.NotNull(savedMessage); Assert.Equal(userId, savedMessage.WAGUserId); Assert.Equal(contactMessageViewModel.Title, savedMessage.Title); Assert.Equal(contactMessageViewModel.TextBody, savedMessage.TextBody); }
public void DeleteContactMessageShouldDeleteMessageCorrect() { var options = new DbContextOptionsBuilder <WAGDbContext>() .UseInMemoryDatabase(databaseName: "Delete_Message_Db") .Options; var dbContext = new WAGDbContext(options); var service = new HomeService(dbContext, null); string userId = Guid.NewGuid().ToString(); var message = new ContactMessage() { Title = "Test title", TextBody = "Test textBody", WAGUserId = userId, }; dbContext.ContactMessages.Add(message); dbContext.SaveChanges(); var messageId = dbContext.ContactMessages.LastOrDefault().Id; service.DeleteContactMessage(messageId); Assert.Null(dbContext.ContactMessages.FirstOrDefault(m => m.Id == messageId)); }
public override void OnPageHandlerExecuting(PageHandlerExecutingContext context) { if (User != null && User.Identity.IsAuthenticated) { var homeService = new HomeService(dbContext); GetHomesOfUserRequest request = new GetHomesOfUserRequest { RequestUserId = UserId }; var homesResponse = homeService.GetHomesOfUser(request); string homePath = "/Home/Create"; if (homesResponse.Homes.Count == 0 && context.ActionDescriptor.ViewEnginePath != homePath) { context.Result = RedirectToPage(homePath); } else { if (!context.HttpContext.Session.Keys.Contains(SessionKeys.ACTIVE_HOME_ID)) { //TODO: Find currently active home and write to session SelectedHomeId = homesResponse.Homes.FirstOrDefault()?.Id ?? 0; if (SelectedHomeId != 0) { context.HttpContext.Session.SetInt32(SessionKeys.ACTIVE_HOME_ID, SelectedHomeId); } } else { SelectedHomeId = HttpContext.Session.GetInt32(SessionKeys.ACTIVE_HOME_ID) ?? 0; } } } base.OnPageHandlerExecuting(context); }
public void RecentTattoosShouldReturnTwelveTattoosMaximum() { var tattoosService = new Mock <IRepository <Tattoo> >(); tattoosService.Setup(r => r.All()).Returns(new List <Tattoo>() { new Tattoo(), new Tattoo(), new Tattoo(), new Tattoo(), new Tattoo(), new Tattoo(), new Tattoo(), new Tattoo(), new Tattoo(), new Tattoo(), new Tattoo(), new Tattoo(), new Tattoo(), new Tattoo(), new Tattoo() }.AsQueryable()); var service = new HomeService(tattoosService.Object, null, null); Assert.Equal(12, service.RecentTattoos().Count()); }
private void SetPhoto() { LayoutInflater layoutInflater = LayoutInflater.From(context); View view = layoutInflater.Inflate(Resource.Layout.modal_photo, null); var img_get_photo = view.FindViewById <ImageView>(Resource.Id.img_get_photo); var src = Android.Net.Uri.Parse(URL + StaticOrder.File_Name); img_get_photo.SetImageURI(src); Bitmap imageBitmap = HomeService.GetImageBitmapFromUrl(URL + StaticOrder.File_Name); img_get_photo.SetImageBitmap(imageBitmap); Android.App.AlertDialog.Builder alert1 = new Android.App.AlertDialog.Builder(context); alert1.SetView(view); alert1.SetCancelable(false); alert1.SetPositiveButton("Скачать", (senderAlert1, args1) => { SaveImage(imageBitmap); }); alert1.SetNegativeButton("Закрыть", (senderAlert1, args1) => { }); Dialog dialog1 = alert1.Create(); dialog1.Show(); }
public void ReturnCorrectModel_WhenPassedParameterIsValid() { //Arrange var topics = new Mock <ITopicsService>(); var brands = new Mock <IBrandsService>(); var categories = new Mock <ICategoriesService>(); var supplements = new Mock <ISupplementsService>(); var numberOfTopics = 6; var topicsCollection = DataHelper.GetTopics(); topics.Setup(x => x.GetAll()).Returns(topicsCollection); var homeService = new HomeService(topics.Object, brands.Object, categories.Object, supplements.Object); var expectedResultWithDataModel = topicsCollection.OrderByDescending(t => t.Comments.Count()).Take(numberOfTopics) .ToList(); var expectedResult = Mapper.Map <IList <HomeTopicViewModel> >(expectedResultWithDataModel); //Act var result = homeService.GetTopicViewModel(numberOfTopics); //Assert Assert.IsNotNull(result); Assert.AreEqual(expectedResult.FirstOrDefault().Id, result.FirstOrDefault().Id); Assert.AreEqual(expectedResult.FirstOrDefault().Name, result.FirstOrDefault().Name); Assert.AreEqual(expectedResult.FirstOrDefault().Description, result.FirstOrDefault().Description); Assert.AreEqual(expectedResult.FirstOrDefault().NumberOfComments, result.FirstOrDefault().NumberOfComments); Assert.AreEqual(expectedResult.FirstOrDefault().NumberOfSupplements, result.FirstOrDefault().NumberOfSupplements); }
public HomeController() { UnitOfWork unitOfWork = new UnitOfWork(); this.userService = new UserService(new ModelStateWrapper(this.ModelState), unitOfWork.UserRepository, unitOfWork); this.homeService = new HomeService(new ModelStateWrapper(this.ModelState), unitOfWork); }
public HomepageController(IWebHostEnvironment env, sys_HomePageService syshomeService, sys_RoleService roleService, HomeService homeService) { _env = env; _syshomeService = syshomeService; this.roleService = roleService; this._homeService = homeService; }
public BotHost( BotCommander <T> botCommander, BotLogger botLogger, SettingsService settingsService, KahlaLocation kahlaLocation, FriendshipService friendshipService, HomeService homeService, VersionService versionService, AuthService authService, EventSyncer <T> eventSyncer, ProfileContainer profileContainer, BotFactory <T> botFactory) { _botCommander = botCommander.InjectHost(this); _botLogger = botLogger; _settingsService = settingsService; _kahlaLocation = kahlaLocation; _friendshipService = friendshipService; _homeService = homeService; _versionService = versionService; _authService = authService; _eventSyncer = eventSyncer; _profileContainer = profileContainer; _botFactory = botFactory; }
public void TestAddReturnsTrue() { HomeService service = new HomeService(_homeQueryMock.Object); Product p = service.Add(It.IsAny <Product>()); p.Status.Should().Be("Added"); }
public void GetIpAddressesTest() { IList <IpAddressModel> products = new List <IpAddressModel> { new IpAddressModel { Id = 1, IpAdderss = "1.1.1.1/1" }, new IpAddressModel { Id = 2, IpAdderss = "2.2.2.2/2" }, new IpAddressModel { Id = 3, IpAdderss = "3.3.3.3/3" } }; var mock = new Mock <INetworkAddressRepository>(); mock.Setup(a => a.GetAllIpAddressesFromDataBase()).Returns(products); var serviceInstance = new HomeService(mock.Object); var serviceMethodCallResult = serviceInstance.GetIpAddresses(); Assert.AreSame(products, serviceMethodCallResult); }
public JsonResult CheckColumnMandatory(int ColumnId, string TableName) { HomeService homeService = new HomeService(); bool checkColumnMandatory = homeService.checkColumnIsMandatory(ColumnId, TableName); return(Json(checkColumnMandatory, JsonRequestBehavior.AllowGet)); }
public async Task GetCitiesShouldReturnAllCitiesInDatabase() { var optionsBuilder = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase("nameOfDatabase"); var db = new ApplicationDbContext(optionsBuilder.Options); var homeService = new HomeService(db); var currCities = new List <City> { new City { Id = 1, Name = "Sofia" }, new City { Id = 2, Name = "Ruse" }, new City { Id = 3, Name = "Montana" } }; await db.Cities.AddRangeAsync(currCities); await db.SaveChangesAsync(); int result = homeService.GetCities().Count(); Assert.Equal(3, result); }
public MultiController(HomeService homeService, ImageService imageService, AccountService accountService, CountryService countryService) { this.homeService = homeService; this.imageService = imageService; this.accountService = accountService; this.countryService = countryService; }
public async Task TestMainSliderPicturesReturnCorrectResult() { // Arrange var context = PCHUBDbContextInMemoryInitializer.InitializeContext(); var picturesModel = new List <Picture>(); for (int i = 0; i < 5; i++) { picturesModel.Add(new Picture { Name = "TestPic" + i, Url = "TestPic" + 1, }); } var homeService = new HomeService(context); await context.MainSliders.AddAsync(new MainSlider { Name = "MainSlider", MainSliderPictures = picturesModel, }); await context.SaveChangesAsync(); var pictures = await homeService.GetMainSliderPicturesAsync(); Assert.Equal(5, pictures.Count); Assert.True(pictures.Exists(x => x.Name.Contains("TestPic"))); }
// GET: /Customer/ public CustProdController() { customerService = (CustomerService)Ioc.Get <CustomerService>(); productService = (ProductService)Ioc.Get <ProductService>(); applianceService = (ApplianceService)Ioc.Get <ApplianceService>(); customerProductService = (CustomerProductService)Ioc.Get <CustomerProductService>(); storeService = (StoreService)Ioc.Get <StoreService>(); HomeService = (HomeService)Ioc.Get <HomeService>(); var BusinessRules = HomeService.GetBusinessRuleList(storeService.StoreId); try { BookJobAllWarranty = BusinessRules.Where(x => x.Key == BusinessRuleKey.BookJobAllWarranty.ToString()).FirstOrDefault().Checked; } catch { BookJobAllWarranty = false; } try { StopBookingClientModelMissing = BusinessRules.Where(x => x.Key == BusinessRuleKey.StopBookingClientModelMissing.ToString()).FirstOrDefault().Checked; } catch { StopBookingClientModelMissing = false; } }
public ActionResult GetData(Data values) { HomeService service = new HomeService(); var model = service.GetApiData(values); return(PartialView("~/Views/Home/IndexData.cshtml", model)); }
public StartUp( ConversationService conversationService, FriendshipService friendshipService, AuthService authService, HomeService homeService, KahlaLocation kahlaLocation, BotLogger botLogger, IEnumerable <BotBase> bots, VersionService versionService, SettingsService settingsService, AES aes) { var bot = BotConfigurer.SelectBot(bots, settingsService, botLogger); bot.BotLogger = botLogger; bot.AES = aes; bot.ConversationService = conversationService; bot.FriendshipService = friendshipService; bot.HomeService = homeService; bot.KahlaLocation = kahlaLocation; bot.AuthService = authService; bot.VersionService = versionService; bot.SettingsService = settingsService; _bot = bot; }
public void TestAddIsCalledOnce() { HomeService service = new HomeService(_homeQueryMock.Object); List <Product> products = service.Add(It.IsAny <Product>()); _homeQueryMock.Verify(h => h.Add(It.IsAny <Product>()), Times.Once); }
public (IHomeService, Mock <IEmailSendingService>) CreateHomeService() { var mockEmailConfirmation = new Mock <IEmailSendingService>(); var homeService = new HomeService(mockEmailConfirmation.Object); return(homeService, mockEmailConfirmation); }
public override ActionResult Index() { var homeSvc = new HomeService(); var userId = int.Parse(Session["CurrentUserId"].ToString()); var currentUser = homeSvc.GetCurrentUser(userId); Session["CurrentUser"] = currentUser; ViewBag.CurrentUser = currentUser; return View(); }