Example #1
0
 public TestBase()
 {
     dbContext     = MockDbContext.GetObject();
     userManager   = MockUserManager.GetObject();
     roleManager   = MockRoleManager.GetObject();
     signInManager = MockSignInManager.GetObject();
 }
Example #2
0
        public async Task SetInitialDataTest()
        {
            //Arrange
            List <ApplicationRole> roles = new List <ApplicationRole>
            {
                new ApplicationRole {
                    Id = 1, Name = "user"
                },
                new ApplicationRole {
                    Id = 2, Name = "admin"
                }
            };

            var newUser = new Mock <ApplicationUser>();

            newUser.Setup(m => m.Email).Returns(ServiceDataToUse.User.Email);
            newUser.Setup(m => m.Id).Returns(ServiceDataToUse.User.Id);
            newUser.Setup(m => m.Roles).Returns(new List <UserRole> {
                new UserRole {
                    RoleId = 1, UserId = ServiceDataToUse.User.Id
                }
            });

            ServiceDataToUse.User = newUser.Object;

            var userDTO = new UserDTO {
                Id = ServiceDataToUse.User.Id, Email = ServiceDataToUse.User.Email
            };

            userManager = new MockUserManager(new MockUserStore().Object)
                          .MockFindByEmailAsync()
                          .MockAddToRoleAsync();

            roleManager = new MockRoleManager(new RoleStore(new ApplicationContext("some")))
                          .MockCreateAsync()
                          .MockFindByNameAsync()
                          .MockRoles(roles);

            Work.SetManagers(userManager, null, null, null, roleManager);

            UserService service = new UserService(Work.Object);

            try
            {
                //Act
                await service.SetInitialData(userDTO, (from r in roles
                                                       select r.Name).ToList());
            }
            catch
            {
                //Assert
                Assert.Fail("Error while setting data.");
            }
        }
Example #3
0
        public UserServiceTests()
        {
            _fixture = new Fixture();

            // create a user by setting creating
            _testUser = new User
            {
                UserName = _fixture.Create("Username"),
                Email    = DataUtils.RandEmail()
            };

            _mockUserManager = MockUserManager.GetMockUserManager();
            _mockRoleManager = MockRoleManager.GetMockRoleManager();


            var testGroupListName = _fixture.Create("Group");

            _groupListNames = new List <string> {
                testGroupListName
            };
        }