public void DeleteCommentsToPost()
        {
            Mock <IUnitOfWork> uow = new Mock <IUnitOfWork>();

            uow.Setup(x => x.PostCommentRepository.GetByKey((long)10)).Returns(new PostComment()
            {
                Id = 1
            }
                                                                               );
            uow.Setup(x => x.PostCommentRepository.GetPostComments((long)10)).Returns(new List <PostComment>()
            {
                new PostComment()
                {
                    Id = 10
                }
            }
                                                                                      );

            UserManager <AppUser> um  = new FakeUserManager();
            UserBlogService       ubs = new UserBlogService(uow.Object, um);
            UserBlogApiController UBC = new UserBlogApiController(ubs);

            var result = UBC.DeleteCommentsToPost(10) as EmptyResult;

            uow.Verify(x => x.PostCommentRepository.Delete(It.IsAny <long>()));
        }
        public void AddCommentToPost()
        {
            Mock <IUnitOfWork> uow = new Mock <IUnitOfWork>();

            uow.Setup(x => x.PostCommentRepository.GetByKey(1)).Returns(fakePostComments.Where(x => x.Id == 1).FirstOrDefault());
            uow.Setup(x => x.PostCommentRepository.GetPostComments(1)).Returns(fakePostComments);

            UserManager <AppUser> um  = new FakeUserManager();
            UserBlogService       ubs = new UserBlogService(uow.Object, um);
            UserBlogApiController UBC = new UserBlogApiController(ubs);

            UBC.ControllerContext = new ControllerContext
            {
                HttpContext = new DefaultHttpContext
                {
                    User = new ClaimsPrincipal(new ClaimsIdentity(new Claim[]
                    {
                        new Claim(ClaimTypes.Name, "username")
                    }, "someAuthTypeName"))
                }
            };

            var result = UBC.AddCommentToPost(new UserBlogCommentModel()
            {
                BlogId = 1, ParentId = 1, Text = "text"
            }) as ObjectResult;

            result.Value.Should().NotBeNull();
            //uow.Verify(x => x.PostCommentRepository.Delete(It.IsAny<long>()));
        }
Пример #3
0
 public void Setup()
 {
     _userManager  = new FakeUserManager();
     _jwtGenerator = Substitute.For <IJwtGenerator>();
     _arpaContext  = Substitute.For <IArpaContext>();
     _handler      = new RefreshAccessToken.Handler(_userManager, _jwtGenerator, _arpaContext, new FakeDateTimeProvider());
 }
Пример #4
0
        public void IndexTest()
        {
            UserManager <AppUser>            um = new FakeUserManager();
            Mock <IUserValidator <AppUser> > uv = new Mock <IUserValidator <AppUser> >();
            var failed = Task.FromResult(IdentityResult.Failed());

            //Console.Write(failed.Errors);
            uv.Setup(x => x.ValidateAsync(um, It.IsAny <AppUser>())).Returns(failed);
            //uv.Setup(x => x.ValidateAsync(um, fakeUser)).Returns(Task.FromResult(IdentityResult.Success));
            uv.Setup(x => x.ValidateAsync(um, It.Is <AppUser>(a => a == fakeUser))).Returns(Task.FromResult(IdentityResult.Success));
            AccountController AC = new AccountController(um, uv.Object);

            var result = AC.Index();

            result.Should().NotBeNull();
            var result2 = AC.Index(new AppUserViewModel()
            {
                Name = "name", Surname = "surname"
            });

            result2 = AC.Index(new AppUserViewModel()
            {
                Name = "asd", Surname = "sde"
            });
            result2.Should().NotBeNull();
        }
Пример #5
0
        public void RegisterUser_FirstUser_LocalRedirect()
        {
            // Arrange
            FakeUserManager fakeUserManager = new FakeUserManager();

            fakeUserManager.SetUsers(new List <ApplicationUser>(new ApplicationUser[] {}).AsQueryable());

            FakeSignInManager fakeSignInManager = new FakeSignInManager();

            RegisterModel registerModel = new RegisterModel(fakeUserManager, fakeSignInManager, new FakeLogger <LoginModel>(), null);

            registerModel.PageContext = new PageContext();

            registerModel.Input = new RegisterModel.InputModel
            {
                Email    = "*****@*****.**",
                Password = "******",
            };

            // Act
            IActionResult result = registerModel.OnPostAsync().Result;

            // Assert
            Assert.IsType(typeof(LocalRedirectResult), result);
        }
 public void SetUp()
 {
     _factory         = new InMemorySqlLiteContextFactory();
     _mockSignManager = new FakeSignInManager();
     _mockUserManager = new FakeUserManager();
     _uut             = new IdentityUserRepository(_mockUserManager, _mockSignManager);
 }
Пример #7
0
        public void ShouldReturnNull_WhenNoUserAssociated()
        {
            var userManager = new FakeUserManager();

            var sut = new UserAuthorizationService(userManager, Mock.Of <AllReadyContext>());

            sut.AssociatedUserId.ShouldBeNull();
        }
Пример #8
0
        public void HasAssociatedUserShouldReturnFalse_WhenNoUserAssociated()
        {
            var userManager = new FakeUserManager();

            var sut = new UserAuthorizationService(userManager, Mock.Of <AllReadyContext>());

            sut.HasAssociatedUser.ShouldBeFalse();
        }
 public ManageControllerTests(ITestOutputHelper output)
 {
     _output            = output;
     _fakeUserManager   = new FakeUserManager();
     _fakeSignInManager = new FakeSignInManager();
     _mockSmsSender     = new Mock <ISmsSender>();
     _sut = new ManageController(_fakeUserManager, _fakeSignInManager, _mockSmsSender.Object);
 }
Пример #10
0
 public void Setup()
 {
     _userManager       = new FakeUserManager();
     _emailSender       = Substitute.For <IEmailSender>();
     _jwtConfiguration  = new JwtConfiguration();
     _clubConfiguration = new ClubConfiguration();
     _handler           = new ForgotPassword.Handler(_userManager, _clubConfiguration, _jwtConfiguration, _emailSender);
 }
Пример #11
0
 public void Setup()
 {
     _userManager       = new FakeUserManager();
     _emailSender       = Substitute.For <IEmailSender>();
     _jwtConfiguration  = new JwtConfiguration();
     _clubConfiguration = new ClubConfiguration();
     _handler           = new CreateEmailConfirmationToken.Handler(_userManager, _clubConfiguration, _jwtConfiguration, _emailSender);
 }
        public void DetailsTest()
        {
            int id = 1;
            var um = new FakeUserManager();
            Mock <IUnitOfWork> uow = new Mock <IUnitOfWork>();

            uow.Setup(x => x.PersonRepository.GetByKey((long)id)).Returns(_fakePersons.Where(x => x.Id == id).FirstOrDefault());
            uow.Setup(x => x.FileRepository.GetByKey((long)id)).Returns(new Models.File()
            {
                Path = (Directory.GetCurrentDirectory() + "\\FilmSearch.dll"), FileType = "dll"
            });
            uow.Setup(x => x.PersonRoleRepository.GetAll()).Returns(fakePersonRoles);
            uow.Setup(x => x.PersonPerformanceRepository.GetAll()).Returns(fakePersonPerfomances);
            uow.Setup(x => x.FilmRepository.GetByKey(It.IsAny <int>())).Returns(new Film()
            {
                Id      = 1,
                PhotoId = 1,
                Title   = "title"
            }
                                                                                );
            uow.Setup(x => x.FilmRoleRepository.GetByKey(It.IsAny <int>())).Returns(new FilmRole()
            {
                Id   = 1,
                Name = "name"
            }
                                                                                    );

            Mock <IHostingEnvironment> env = new Mock <IHostingEnvironment>();
            PersonService    ps            = new FakePersonService(uow.Object);
            PersonController PC            = new PersonController(uow.Object, env.Object, ps, um);

            /*
             * var username = "******";
             * var identity = new GenericIdentity(username);
             * //create claim and add it to indentity
             * var nameIdentifierClaim = new Claim(ClaimTypes.NameIdentifier, username);
             * identity.AddClaim(nameIdentifierClaim);
             *
             * var user = new Mock<IPrincipal>();
             * user.Setup(x => x.Identity).Returns(identity);
             * Thread.CurrentPrincipal = user.Object;
             */
            PC.ControllerContext = new ControllerContext
            {
                HttpContext = new DefaultHttpContext
                {
                    User = new ClaimsPrincipal(new ClaimsIdentity(new Claim[]
                    {
                        new Claim(ClaimTypes.Name, "username")
                    }, "someAuthTypeName"))
                }
            };

            var result = PC.Details(id) as ViewResult;

            result.Should().NotBeNull();
        }
Пример #13
0
 public ToDoListsControllerTests()
 {
     this.optionsBuilder = new DbContextOptionsBuilder <ApplicationDbContext>()
                           .UseInMemoryDatabase("toDoListsDatabase");
     this.db = new ApplicationDbContext(this.optionsBuilder.Options);
     this.toDoListsService = new ToDoListsService(this.db);
     this.userManager      = new FakeUserManager();
     this.controller       = new ToDoListsController(this.toDoListsService, this.userManager);
 }
Пример #14
0
        public async Task IsTeamLead_ReturnsFalse_WhenNoUserAssociated()
        {
            var userManager = new FakeUserManager();

            var sut = new UserAuthorizationService(userManager, Context);

            var isEventManager = await sut.IsTeamLead();

            isEventManager.ShouldBe(false);
        }
Пример #15
0
        public void BanTest()
        {
            UserManager <AppUser>            um = new FakeUserManager();
            Mock <IUserValidator <AppUser> > uv = new Mock <IUserValidator <AppUser> >();
            AccountController AC = new AccountController(um, uv.Object);

            var result = (AC.Ban() as ViewResult).Model as List <AppUser>;

            result.Should().NotBeNull();
        }
 public InvestmentsControllerTests()
 {
     this.optionsBuilder = new DbContextOptionsBuilder <ApplicationDbContext>()
                           .UseInMemoryDatabase("investmentWalletsDatabase");
     this.db = new ApplicationDbContext(this.optionsBuilder.Options);
     this.currenciesService         = new CurrenciesService(this.db);
     this.investmentsWalletsService = new InvestmentsWalletsService(this.db);
     this.userManager = new FakeUserManager();
     this.controller  = new InvestmentsController(this.currenciesService, this.investmentsWalletsService, this.userManager);
 }
Пример #17
0
        public async Task GetLedItineraryIds_ShouldReturnEmptyListWhenNoAssociatedUser()
        {
            var userManager = new FakeUserManager();

            var sut = new UserAuthorizationService(userManager, Context);

            var teamLeadIds = await sut.GetLedItineraryIds();

            teamLeadIds.ShouldBeEmpty();
        }
Пример #18
0
        public async Task GetUser()
        {
            var userName  = "******";
            var userStore = new Mock <IUserStore <ApplicationUser> >();

            var userManager  = new FakeUserManager(userStore.Object);
            var userToVerify = await userManager.FindByEmailAsync(userName);

            Assert.Equal("*****@*****.**", userToVerify.Email);
        }
Пример #19
0
        public async Task GetManagedCampaignIds_ShouldReturnEmptyListWhenNoAssociatedUser()
        {
            var userManager = new FakeUserManager();

            var sut = new UserAuthorizationService(userManager, Context);

            var managedCampaignIds = await sut.GetManagedCampaignIds();

            managedCampaignIds.ShouldBeEmpty();
        }
Пример #20
0
        public void GetAllTest()
        {
            UserManager <AppUser> um = new FakeUserManager();
            Mock <Microsoft.Extensions.Configuration.IConfiguration> conf = new Mock <Microsoft.Extensions.Configuration.IConfiguration>();
            NewsletterApiController NAC = new NewsletterApiController(new Services.UserService(um), new Services.MailService(), um, conf.Object);

            var result = NAC.GetAll("q", 1) as ViewResult;

            result.Should().BeNull();
        }
Пример #21
0
        public void PersonStatsTest()
        {
            UserManager <AppUser>            um = new FakeUserManager();
            Mock <IUserValidator <AppUser> > uv = new Mock <IUserValidator <AppUser> >();
            AccountController AC = new AccountController(um, uv.Object);

            var result = (AC.PersonStats() as ViewResult);

            result.Should().NotBeNull();
        }
Пример #22
0
        public void DisableUser()
        {
            UserManager <AppUser>            um = new FakeUserManager();
            Mock <IUserValidator <AppUser> > uv = new Mock <IUserValidator <AppUser> >();
            AccountController AC = new AccountController(um, uv.Object);

            string id     = "1";
            var    result = AC.DisableUser(id).Result;

            result.Should().NotBeNull();
        }
        public void CreateBlogTest()
        {
            Mock <IUnitOfWork>    uow = new Mock <IUnitOfWork>();
            UserManager <AppUser> um  = new FakeUserManager();
            UserBlogService       ubs = new UserBlogService(uow.Object, um);
            UserBlogController    ubc = new UserBlogController(ubs);

            var result = ubc.CreateBlog() as ViewResult;

            result.Should().NotBeNull();
        }
Пример #24
0
        public TokenControllerTests(ITestOutputHelper output)
        {
            _fakeSignInManager = new FakeSignInManager();
            _fakeUserManager   = new FakeUserManager();
            var config = new ConfigurationBuilder()
                         .SetBasePath(Path.GetFullPath(@"..\..\..\..\ContosoUniversity.Web"))
                         .AddJsonFile("appsettings.development.json")
                         .Build();

            _sut = new TokenController(_fakeSignInManager, _fakeUserManager, config);
        }
        public ActionResult Index(string question)
        {
            var vm   = new TeachingRoomViewModel();
            var uman = new FakeUserManager();

            vm.DisplayName     = User.Identity.Name;
            vm.UserId          = uman.GetUserId(User.Identity.Name);
            vm.DisplayQuestion = question ?? "";

            return(View(vm));
        }
 public TradesControllerTests()
 {
     this.optionsBuilder = new DbContextOptionsBuilder <ApplicationDbContext>()
                           .UseInMemoryDatabase("tradesDatabase");
     this.db               = new ApplicationDbContext(this.optionsBuilder.Options);
     this.repo             = new EfDeletableEntityRepository <Company>(this.db);
     this.companiesService = new CompaniesService(this.repo);
     this.tradesService    = new TradesService(this.db, this.companiesService);
     this.userManager      = new FakeUserManager();
     this.controller       = new TradesController(this.companiesService, this.tradesService, this.userManager);
 }
Пример #27
0
        public APITestBase() : base()
        {
            _userManager = new FakeUserManager(_context);

            _signInManager   = new FakeSignInManager(_userManager);
            _courseService   = new CourseService(_context);
            _studentService  = new StudentService(_context);
            _enrollService   = new EnrollService(_context);
            _facultyService  = new FacultyService(_context);
            _wishlistService = new WishlistService(_context);
        }
        public AccountControllerTests(ITestOutputHelper output)
        {
            _output               = output;
            _fakeUserManager      = new FakeUserManager();
            _fakeSignInManager    = new FakeSignInManager();
            _mockUrlHelperAdaptor = new Mock <IUrlHelperAdaptor>();
            _mockEmailSender      = new Mock <IEmailSender>();
            _mockSmsSender        = new Mock <ISmsSender>();

            _sut = new AccountController(_fakeUserManager, _fakeSignInManager, _mockEmailSender.Object, _mockSmsSender.Object, _mockUrlHelperAdaptor.Object);
        }
        public void SearchTest()
        {
            var um = new FakeUserManager();
            Mock <IUnitOfWork>         uow = new Mock <IUnitOfWork>();
            Mock <IHostingEnvironment> env = new Mock <IHostingEnvironment>();
            PersonService    ps            = new PersonService(uow.Object);
            PersonController PC            = new PersonController(uow.Object, env.Object, ps, um);

            var result = PC.Search() as ViewResult;

            result.Model.Should().BeNull();
        }
 public WalletsControllerTests()
 {
     this.optionsBuilder = new DbContextOptionsBuilder <ApplicationDbContext>()
                           .UseInMemoryDatabase("walletsDatabase");
     this.db                = new ApplicationDbContext(this.optionsBuilder.Options);
     this.recordsService    = new RecordsService(this.db);
     this.currenciesService = new CurrenciesService(this.db);
     this.categoriesService = new CategoriesService(this.db, this.recordsService);
     this.walletsService    = new WalletsService(this.db, this.recordsService, this.currenciesService, this.categoriesService);
     this.userManager       = new FakeUserManager();
     this.controller        = new WalletsController(this.walletsService, this.recordsService, this.currenciesService, this.userManager);
 }