コード例 #1
0
        public void InitilizeTests()
        {
            this.dbContext = MockDbContext.GetContext();
            var mapper = MockAutomapper.GetMapper();

            this.service = new AdminSectionsService(dbContext, mapper);
        }
コード例 #2
0
        public CategoriesControllerTests()
        {
            this.dbContext     = MockDbContext.GetContext();
            this.configuration = new ConfigurationBuilder()
                                 .AddJsonFile("settings.json")
                                 .Build();

            this.restaurantImagesRepository = new EfDeletableEntityRepository <RestaurantImage>(this.dbContext);
            this.categoryImageRepository    = new EfDeletableEntityRepository <CategoryImage>(this.dbContext);
            this.restaurantRepository       = new EfDeletableEntityRepository <Restaurant>(this.dbContext);
            this.categoryRepository         = new EfDeletableEntityRepository <Category>(this.dbContext);
            this.favouriteRepository        = new EfRepository <FavouriteRestaurant>(this.dbContext);
            this.voteRepository             = new EfRepository <Vote>(this.dbContext);
            this.commentRepository          = new EfDeletableEntityRepository <Comment>(this.dbContext);

            this.voteService             = new VoteService(this.voteRepository);
            this.commentService          = new CommentService(this.commentRepository, this.voteService);
            this.cloudinaryService       = new CloudinaryImageService(this.configuration);
            this.restaurantImagesService = new RestaurantImageService(this.restaurantImagesRepository, this.cloudinaryService);
            this.restaurantService       = new RestaurantService(this.restaurantRepository, this.restaurantImagesService, this.commentService);

            this.categoryImageService = new CategoryImageService(this.categoryImageRepository, this.cloudinaryService);
            this.categoryService      = new CategoryService(this.categoryRepository, this.categoryImageService, this.restaurantService);
            this.favouriteService     = new FavouriteService(this.favouriteRepository);

            var httpContext = new DefaultHttpContext();
            var tempData    = new TempDataDictionary(httpContext, Mock.Of <ITempDataProvider>());

            this.controller = new CategoriesController(this.categoryService, this.restaurantService, this.favouriteService)
            {
                TempData = tempData,
            };

            AutoMapperConfig.RegisterMappings(typeof(ErrorViewModel).Assembly);
        }
コード例 #3
0
 public void Initialize()
 {
     this.context        = MockDbContext.GetContext();
     this.scoreService   = new Mock <IScoreService>().Object;
     this.historyService = new Mock <IHistoryService>().Object;
     this.userService    = new UserService(context, scoreService, historyService);
 }
コード例 #4
0
        public RestaurantImagesControllerTests()
        {
            this.dbContext     = MockDbContext.GetContext();
            this.configuration = new ConfigurationBuilder()
                                 .AddJsonFile("settings.json")
                                 .Build();

            this.restaurantImagesRepository = new EfDeletableEntityRepository <RestaurantImage>(this.dbContext);
            this.restaurantRepository       = new EfDeletableEntityRepository <Restaurant>(this.dbContext);
            this.userRepository             = new EfDeletableEntityRepository <ApplicationUser>(this.dbContext);
            this.voteRepository             = new EfRepository <Vote>(this.dbContext);
            this.commentRepository          = new EfDeletableEntityRepository <Comment>(this.dbContext);

            this.voteService             = new VoteService(this.voteRepository);
            this.commentService          = new CommentService(this.commentRepository, this.voteService);
            this.userImageService        = new UserImageService(this.userRepository, this.cloudinaryService);
            this.cloudinaryService       = new CloudinaryImageService(this.configuration);
            this.restaurantImagesService = new RestaurantImageService(this.restaurantImagesRepository, this.cloudinaryService);
            this.restaurantService       = new RestaurantService(this.restaurantRepository, this.restaurantImagesService, this.commentService);
            this.userService             = new UserService(this.restaurantService, this.userImageService, this.userRepository);

            var httpContext = new DefaultHttpContext();
            var tempData    = new TempDataDictionary(httpContext, Mock.Of <ITempDataProvider>());

            this.controller = new RestaurantImagesController(this.restaurantImagesService, this.userService, this.restaurantService)
            {
                TempData = tempData,
            };
        }
コード例 #5
0
 public void InitializeTests()
 {
     this.dbContext      = MockDbContext.GetContext();
     this.mapper         = MockAutoMapper.GetAutoMapper();
     this.postService    = new PostService(dbContext, mapper);
     this.postController = new PostsController(postService, mapper);
 }
コード例 #6
0
        public void InitilizeTests() // runs befor every test
        {
            this.dbContext = MockDbContext.GetContext();
            var mapper = MockAutomapper.GetMapper();

            this.service = new AdminCoursesService(dbContext, mapper);
        }
コード例 #7
0
 public void InitializeTests()
 {
     this.dbContext  = MockDbContext.GetContext();
     this.interviews = new AdminInterviewService(dbContext, MockAutoMapper.GetAutoMapper());
     this.applicants = new AdminApplicantService(dbContext, MockAutoMapper.GetAutoMapper());
     this.tests      = new InterviewerTestsService(dbContext, MockAutoMapper.GetAutoMapper());
 }
コード例 #8
0
        public void InitializeTests()
        {
            this.context = MockDbContext.GetContext();
            this.service = new AdminRewardsService(context, MockAutoMapper.GetMapper());

            CreateInitialEvents();
        }
コード例 #9
0
        public void Initialize()
        {
            this.dbContext = MockDbContext.GetContext();
            var mapper = MockAutoMapper.GetMapper();

            this.categories = new CategoryService(this.dbContext, mapper);
        }
コード例 #10
0
 public AdminProductServiceTest()
 {
     this.context             = MockDbContext.GetContext();
     this.mapper              = MockAutoMapper.GetAutoMapper();
     this.dropDownService     = new DropDownListService(this.context, this.mapper);
     this.productService      = new ProductService(this.context, this.mapper);
     this.adminProductService = new AdminProductService(this.context, this.mapper, this.productService, this.dropDownService);
 }
コード例 #11
0
 public void InitializeTests()
 {
     this.dbContext            = MockDbContext.GetContext();
     this.mapper               = MockAutoMapper.GetAutoMapper();
     this.propertyService      = new PropertyService(dbContext, mapper);
     this.mockedConfig         = new Mock <IConfiguration>();
     this.propertiesController = new PropertiesController(propertyService, mapper);
 }
コード例 #12
0
 public void InitializeTests()
 {
     this.dbContext       = MockDbContext.GetContext();
     this.mapper          = MockAutoMapper.GetAutoMapper();
     this.userManager     = this.TestUserManager <User>();
     this.userService     = new UserService(dbContext, mapper, userManager);
     this.mockedConfig    = new Mock <IConfiguration>();
     this.usersController = new UsersController(userService, mapper, userManager, dbContext);
 }
コード例 #13
0
        public virtual void InitializeTests()
        {
            this.dbContext = MockDbContext.GetContext();
            var userManager = MockUserManager.GetUserManager(dbContext);

            this.service = new UserProgramsService(
                dbContext,
                MockAutoMapper.GetAutoMapper(),
                userManager);
        }
コード例 #14
0
        public FavouriteRestaurantsControllerTests()
        {
            this.dbContext = MockDbContext.GetContext();

            this.restaurantRepository = new EfDeletableEntityRepository <Restaurant>(this.dbContext);
            this.favouriteRepository  = new EfRepository <FavouriteRestaurant>(this.dbContext);

            this.favouriteService = new FavouriteService(this.favouriteRepository);

            this.controller = new FavouriteRestaurantsController(this.favouriteService);
        }
コード例 #15
0
        public virtual void InitializeTests()
        {
            this.dbContext = MockDbContext.GetContext();
            var userManager = MockUserManager.GetUserManager(dbContext);

            var mockUserProgramService = new Mock <IUserProgramsService>();

            mockUserProgramService.Setup(opt => opt.GetDefaulttUserProgram(MockUserManager.testUserId))
            .ReturnsAsync(this.GetOrCreateTestProgram);

            var mockTrainerProgramService = new Mock <ITrainersProgramsService>();
            var mockTraininService        = new Mock <ITrainingsService>();

            mockTraininService
            .Setup(opt => opt.GetTrainingAsync(testTrainingId, MockUserManager.testUsername))
            .ReturnsAsync(() =>
            {
                var training = this.dbContext.Trainings.FirstOrDefault();

                if (training == null)
                {
                    throw new Exception();
                }

                return(training);
            });

            var mockMealService = new Mock <IMealsService>();

            mockMealService
            .Setup(opt => opt.GetMealAsync(testMealId, MockUserManager.testUsername))
            .ReturnsAsync(() =>
            {
                var meal = this.dbContext.Meals.FirstOrDefault();

                if (meal == null)
                {
                    throw new Exception();
                }

                this.dbContext.SaveChanges();

                return(meal);
            });

            this.service = new DaysService(
                dbContext,
                MockAutoMapper.GetAutoMapper(),
                userManager,
                mockUserProgramService.Object,
                mockTrainerProgramService.Object,
                mockTraininService.Object,
                mockMealService.Object);
        }
コード例 #16
0
        public virtual void InitializeTests()
        {
            this.dbContext = MockDbContext.GetContext();
            var userManager      = MockUserManager.GetUserManager(dbContext);
            var exercisesService = new Mock <IExercisesService>();

            this.service = new TrainingsService(
                dbContext,
                MockAutoMapper.GetAutoMapper(),
                userManager,
                exercisesService.Object);
        }
コード例 #17
0
        public VotesControllerTests()
        {
            this.dbContext = MockDbContext.GetContext();

            this.restaurantRepository = new EfDeletableEntityRepository <Restaurant>(this.dbContext);
            this.votesRepository      = new EfRepository <Vote>(this.dbContext);
            this.commentsRepository   = new EfDeletableEntityRepository <Comment>(this.dbContext);

            this.votesService    = new VoteService(this.votesRepository);
            this.commentsService = new CommentService(this.commentsRepository, this.votesService);

            this.controller = new VotesController(this.votesService);
        }
コード例 #18
0
        public void InitializeTests()
        {
            this._dbContext = MockDbContext.GetContext();
            this._mapper    = MockAutoMapper.GetAutoMapper();
            this._service   = new AdminManufacturersService(this._dbContext, this._mapper);

            this._dbContext.Manufacturers.Add(new Manufacturer()
            {
                Id      = 1, Name = string.Format(TestsConstants.Manufacturer, 1),
                LogoUrl = string.Format(TestsConstants.Logo, 1)
            });
            this._dbContext.SaveChanges();
        }
コード例 #19
0
        public void InitializeTests()
        {
            this.dbContext = MockDbContext.GetContext();
            this.mapper    = MockAutoMapper.GetAutoMapper();
            this.service   = new AdminTeamsService(this.dbContext, this.mapper);

            this.dbContext.Teams.Add(new Team()
            {
                Id      = 1, Name = string.Format(TestsConstants.Team, 1),
                LogoUrl = string.Format(TestsConstants.Logo, 1)
            });
            this.dbContext.SaveChanges();
        }
コード例 #20
0
        public async Task Index_ShoudReturnAllUsersExceptCurrent() // !!!
        {
            var users = new[]
            {
                new User()
                {
                    Id = "111"
                },
                new User()
                {
                    Id = "222"
                },
                new User()
                {
                    Id = "333"
                },
                new User()
                {
                    Id = "444"
                },
            };

            var mockDbContext = MockDbContext.GetContext();

            mockDbContext.Users.AddRange(users);
            mockDbContext.SaveChanges();

            var mockUserStore = new Mock <IUserStore <User> >();

            //var mockUserManager = new Mock<UserManager<User>>();

            var mockUserManager = new Mock <UserManager <User> >(
                new Mock <IUserStore <User> >().Object, null, null, null, null, null, null, null, null);

            mockUserManager.Setup(um => um.GetUserAsync(null))
            .ReturnsAsync(users[1]);

            var controller = new UsersController(mockDbContext,
                                                 MockAutomapper.GetMapper(), mockUserManager.Object);

            //2. act:
            var result = await controller.Index() as ViewResult;

            //. assert:
            Assert.IsNotNull(result);
            var model = result.Model as IEnumerable <UserShortViewModel>;

            CollectionAssert.AreEqual(new[] { "111", "333", "444" },
                                      model.Select(u => u.Id).ToArray());
        }
コード例 #21
0
        public void InitializeTests()
        {
            this.mapper      = MockAutoMapper.GetAutoMapper();
            this.dbContext   = MockDbContext.GetContext();
            this.userManager = new UserManager <User>(new UserStore <User>(dbContext), null, null, null, null, null, null, null, null);
            this.controller  = new BuildsController(dbContext, mapper, userManager);

            var users = new[]
            {
                new User()
                {
                    Id = "111"
                },
                new User()
                {
                    Id = "222"
                },
                new User()
                {
                    Id = "333"
                },
                new User()
                {
                    Id = "444"
                }
            };

            var mockUserStore   = new Mock <IUserStore <User> >();
            var mockUserManager = new Mock <UserManager <User> >(
                mockUserStore.Object, null, null, null, null, null, null, null, null);

            mockUserManager.Setup(um => um.GetUserAsync(null))
            .ReturnsAsync(users[1]);

            controller.ControllerContext = new ControllerContext()
            {
                HttpContext = new DefaultHttpContext()
                {
                    User = new ClaimsPrincipal(new ClaimsIdentity(new[]
                    {
                        new Claim(ClaimTypes.Role, "User")
                    }))
                }
            };

            var tempData = new TempDataDictionary(controller.HttpContext, Mock.Of <ITempDataProvider>());

            controller.TempData = tempData;
        }
コード例 #22
0
        public void Index_ShoudReturnNotNull()
        {
            var users = new[]
            {
                new User()
                {
                    Id = "111"
                },
                new User()
                {
                    Id = "222"
                },
            };

            var mockDbContext = MockDbContext.GetContext();

            mockDbContext.Users.AddRange(users);
            mockDbContext.SaveChanges();

            var mockUserStore = new Mock <IUserStore <User> >();

            var mockUserManager = new Mock <UserManager <User> >(
                new Mock <IUserStore <User> >().Object, null, null, null, null, null, null, null, null);

            mockUserManager.Setup(um => um.GetUserAsync(null))
            .ReturnsAsync(users[1]);


            var mockService = new Mock <IAdminUsersService>();

            mockService
            .Setup(service => service.GetUsersWithourCurrentUser("111"))
            .Returns(new[] { new UserShortViewModel()
                             {
                                 Id       = "111",
                                 UserName = "******",
                                 Email    = "*****@*****.**"
                             } });

            var controller = new UsersController(mockUserManager.Object, mockService.Object);

            //2. act:
            var result = controller.Index() as ViewResult;

            //. assert:
            Assert.IsNotNull(result);
        }
コード例 #23
0
        public void Initialize()
        {
            this.context = MockDbContext.GetContext();
            var guidId = Guid.NewGuid().ToString();

            this.user = new User()
            {
                Id = guidId, FirstName = "test", LastName = "test", Email = "*****@*****.**", UserName = "******"
            };
            var guidId2 = Guid.NewGuid().ToString();

            this.user2 = new User()
            {
                Id = guidId2, FirstName = "test2", LastName = "test2", Email = "*****@*****.**", UserName = "******"
            };
            context.Users.Add(user);
            context.Users.Add(user2);
            context.SaveChanges();
        }
コード例 #24
0
        public void InitializeTests()
        {
            this.dbContext = MockDbContext.GetContext();
            this.mapper    = MockAutoMapper.GetAutoMapper();
            this.service   = new AdminProductsService(this.dbContext, this.mapper);

            this.dbContext.Teams.Add(new Team()
            {
                Id = 1, Name = string.Format(TestsConstants.Team, 1)
            });
            this.dbContext.SaveChanges();

            this.dbContext.Products.Add(new Product()
            {
                Id     = 1,
                Title  = string.Format(TestsConstants.Product, 1),
                Brand  = string.Format(TestsConstants.Brand, 1),
                TeamId = 1
            });
            this.dbContext.SaveChanges();
        }
コード例 #25
0
        public void InitializeTests()
        {
            this._dbContext = MockDbContext.GetContext();
            this._mapper    = MockAutoMapper.GetAutoMapper();
            this._service   = new AdminProductsService(this._dbContext, this._mapper);

            this._dbContext.Manufacturers.Add(new Manufacturer()
            {
                Id = 1, Name = string.Format(TestsConstants.Manufacturer, 1)
            });
            this._dbContext.SaveChanges();

            this._dbContext.Products.Add(new Product()
            {
                Id             = 1,
                Name           = string.Format(TestsConstants.Product, 1),
                Type           = string.Format(TestsConstants.Type, 1),
                ManufacturerId = 1
            });
            this._dbContext.SaveChanges();
        }
コード例 #26
0
        public void EditingRobot_ShouldEditRobotName()
        {
            var users = new[]
            {
                new User()
                {
                    Id = "111"
                },
                new User()
                {
                    Id = "222"
                },
                new User()
                {
                    Id = "333"
                },
                new User()
                {
                    Id = "444"
                }
            };
            var mockUserStore   = new Mock <IUserStore <User> >();
            var mockUserManager = new Mock <UserManager <User> >(
                mockUserStore.Object, null, null, null, null, null, null, null, null);

            mockUserManager.Setup(um => um.GetUserAsync(null))
            .ReturnsAsync(users[1]);


            this.dbContext     = MockDbContext.GetContext();
            this.service       = new RobotDataService(dbContext, MockAutoMapper.GetAutoMapper(), mockUserManager.Object);
            this.armorService  = new ArmorDataService(dbContext, this.service, MockAutoMapper.GetAutoMapper(), mockUserManager.Object);
            this.weaponService = new WeaponDataService(dbContext, this.service, MockAutoMapper.GetAutoMapper(), mockUserManager.Object);

            var controller = new RobotController(mockUserManager.Object, MockAutoMapper.GetAutoMapper(), this.service, this.weaponService, this.armorService);

            controller.ControllerContext = new ControllerContext()
            {
                HttpContext = new DefaultHttpContext()
                {
                    User = new ClaimsPrincipal(new ClaimsIdentity(new[]
                    {
                        new Claim(ClaimTypes.Role, "Admin")
                    }))
                }
            };
            var user2 = controller.ControllerContext.HttpContext.User;


            var robot = new Models.Robots.Robot()
            {
                Id            = 1,
                BaseHealth    = 1000,
                CurrentHealth = 1000,
                BaseDamage    = 100,
                Type          = "Fire",
                ImageUrl      = "https://i.ytimg.com/vi/Rrb4jW_uJxE/hqdefault.jpg"
            };

            this.dbContext.Robots.Add(robot);
            this.dbContext.SaveChanges();
            var updateNameBindingModel = new UpdateNameBindingModel()
            {
                Name = "Edited"
            };
            var result = controller.Edit(robot.Id, updateNameBindingModel);

            //service.CreateRobotAsync(user2, robot);
            Assert.AreEqual("Edited", dbContext.Robots.First().Name);
        }
コード例 #27
0
        public void UnequipArmor_ShouldRemoveArmorFromRobot()
        {
            var users = new[]
            {
                new User()
                {
                    Id = "111"
                },
                new User()
                {
                    Id = "222"
                },
                new User()
                {
                    Id = "333"
                },
                new User()
                {
                    Id = "444"
                }
            };
            var mockUserStore   = new Mock <IUserStore <User> >();
            var mockUserManager = new Mock <UserManager <User> >(
                mockUserStore.Object, null, null, null, null, null, null, null, null);

            mockUserManager.Setup(um => um.GetUserAsync(null))
            .ReturnsAsync(users[1]);


            this.dbContext = MockDbContext.GetContext();
            this.service   = new RobotDataService(dbContext, MockAutoMapper.GetAutoMapper(), mockUserManager.Object);

            this.armorService  = new ArmorDataService(dbContext, this.service, MockAutoMapper.GetAutoMapper(), mockUserManager.Object);
            this.weaponService = new WeaponDataService(dbContext, this.service, MockAutoMapper.GetAutoMapper(), mockUserManager.Object);

            var controller = new RobotController(mockUserManager.Object, MockAutoMapper.GetAutoMapper(), this.service, this.weaponService, this.armorService);

            controller.ControllerContext = new ControllerContext()
            {
                HttpContext = new DefaultHttpContext()
                {
                    User = new ClaimsPrincipal(new ClaimsIdentity(new[]
                    {
                        new Claim(ClaimTypes.Role, "Admin")
                    }))
                }
            };
            var user2 = controller.ControllerContext.HttpContext.User;


            var robot = new Models.Robots.Robot()
            {
                Id            = 1,
                BaseHealth    = 1000,
                CurrentHealth = 1000,
                BaseDamage    = 100,
                Type          = "Fire",
                ImageUrl      = "https://i.ytimg.com/vi/Rrb4jW_uJxE/hqdefault.jpg"
            };
            var armor = new Models.Items.Armor()
            {
                Name                 = "mechoo",
                ArmorPoints          = 101,
                DurabilityLossAmount = 15,
                ImageUrl             = "kk",
                Price                = 101
            };

            dbContext.Robots.Add(robot);
            dbContext.Armors.Add(armor);
            robot.Armors.Add(armor);
            this.dbContext.SaveChanges();
            var result = controller.UnequipArmor(robot.Id, armor.Id);

            this.dbContext.SaveChanges();
            Assert.AreEqual(0, robot.Armors.Count());
        }
コード例 #28
0
ファイル: LikesTests.cs プロジェクト: NASOKILA/FindMyPet
 public void BeforeEachTest()
 {
     this.DbContext = MockDbContext.GetContext();
 }
コード例 #29
0
 public void InitializeTests()
 {
     this.dbContext = MockDbContext.GetContext();
 }
コード例 #30
0
 public void InitializeTests()
 {
     this.dbContext = MockDbContext.GetContext();
     this.service   = new AdminCommentsService(this.dbContext, MockAutoMapper.GetAutoMapper());
 }