Beispiel #1
0
        public async Task All_One_AllDataMapped()
        {
            string USER_ID          = Guid.NewGuid().ToString();
            string QUALIFICATION_ID = Guid.NewGuid().ToString();

            await dbContext.Qualification.AddAsync(new Qualification("TestQualification") { Id = QUALIFICATION_ID });

            await dbContext.Users.AddAsync(new User("TestName1", "TestUserName1", "*****@*****.**", DateTime.Now) { Id = USER_ID, QualificationId = QUALIFICATION_ID });

            await dbContext.SaveChangesAsync();

            var service = new AdminUserService(dbContext, userManager, roleManager, signInManager, new Mock <IServerNewsService>().Object);

            IEnumerable <UserConciseViewModel> results = await service.AllAsync(new ClaimsPrincipal());

            Assert.IsNotNull(results);
            Assert.AreEqual(1, results.ToList().Count);

            UserConciseViewModel foundModel = results.First();
            User foundUser = dbContext.Users.Include(u => u.Qualification).First(u => u.Id == USER_ID);

            Assert.AreEqual(foundUser.FullName, foundModel.FullName);
            Assert.AreEqual(foundUser.Email, foundModel.Email);
            Assert.AreEqual(foundUser.Id, foundModel.Id);
            Assert.AreEqual(foundUser.TwoFactorEnabled, foundModel.Is2FAEnabled);
            Assert.AreEqual(foundUser.Qualification.Name, foundModel.Qualification);
        }
        public async Task CategoryById()
        {
            // Arrange
            var db = this.GetDatabase();

            var firstUser = new User {
                Id = "first", Name = "First"
            };
            var secondUser = new User {
                Id = "second", Name = "Second"
            };
            var thirdUser = new User {
                Id = "third", Name = "Third"
            };

            db.AddRange(firstUser, secondUser, thirdUser);

            await db.SaveChangesAsync();

            var adminUserService = new AdminUserService(db);
            // Act
            var result = await adminUserService.AllAsync();


            // Assert
            result
            .Should()
            .HaveCount(3);
        }
Beispiel #3
0
        public async Task FindAsyncShouldReturnCorrectResultSearchCount()
        {
            // Arrange
            var db    = TestInit.InitializeInmemoryDatabase();
            var user1 = new User()
            {
                Id = "1", FirstName = "user1f", Surname = "user1s", Email = "*****@*****.**"
            };
            var user2 = new User()
            {
                Id = "2", FirstName = "user2f", Surname = "user2s", Email = "*****@*****.**"
            };
            var user3 = new User()
            {
                Id = "3", FirstName = "user3f", Surname = "user3s", Email = "*****@*****.**"
            };

            db.AddRange(user1, user2, user3);
            await db.SaveChangesAsync();

            var adminUserService = new AdminUserService(db);

            // Act
            var result = await adminUserService.AllAsync("user2");

            // Assert
            Assert.True(result.Count() == 1);
        }
Beispiel #4
0
        public async Task AllAsyncShouldReturnAllUsers()
        {
            // Arange
            var dbContext = Testing.CreateDatabaseContext();
            var mapper    = Testing.CreateMapper();

            await dbContext
            .Users
            .AddRangeAsync(new User { Id = "1" }, new User { Id = "2" }, new User { Id = "3" });

            await dbContext.SaveChangesAsync();

            var adminUserService = new AdminUserService(dbContext, mapper);
            // Act

            var result = await adminUserService.AllAsync();

            // Assert
            result
            .Should()
            .Match(r => r.ElementAt(0).Id == "1" &&
                   r.ElementAt(1).Id == "2" &&
                   r.ElementAt(2).Id == "3")
            .And
            .HaveCount(3);
        }
Beispiel #5
0
        public async Task All_WithNone_ReturnEmptyCollection()
        {
            var service = new AdminUserService(dbContext, userManager, roleManager, signInManager, new Mock <IServerNewsService>().Object);

            IEnumerable <UserConciseViewModel> results = await service.AllAsync(new ClaimsPrincipal());

            Assert.IsNotNull(results);
            Assert.AreEqual(0, results.ToList().Count);
        }
Beispiel #6
0
        public async Task All_WithSome_ReturnAll()
        {
            await dbContext.Users.AddRangeAsync(
                new User("TestName1", "TestUserName1", "*****@*****.**", DateTime.Now),
                new User("TestName2", "TestUserName2", "*****@*****.**", DateTime.Now),
                new User("TestName3", "TestUserName3", "*****@*****.**", DateTime.Now));

            await dbContext.SaveChangesAsync();

            var service = new AdminUserService(dbContext, userManager, roleManager, signInManager, new Mock <IServerNewsService>().Object);

            IEnumerable <UserConciseViewModel> results = await service.AllAsync(new ClaimsPrincipal());

            Assert.IsNotNull(results);
            Assert.AreEqual(3, results.ToList().Count);
        }
        public async Task AllAsyncShouldReturnAllUsers()
        {
            using (var db = DbInfrastructure.GetDatabase())
            {
                for (var i = 0; i < 10; i++)
                {
                    var user = new User
                    {
                        Id                  = i.ToString(),
                        Email               = $"em{i}email.com",
                        FirstName           = $"Pesho {i}",
                        LastName            = $"Ivanov {i}",
                        UniqueCitizenNumber = $"UNIQUE {i}",
                        UserName            = $"Username {i}"
                    };

                    await db.AddAsync(user);
                }

                await db.SaveChangesAsync();

                var adminUserService = new AdminUserService(db);

                var expectedUsers = new List <AdminUserListingServiceModel>();

                for (var i = 0; i < 10; i++)
                {
                    expectedUsers.Add(new AdminUserListingServiceModel
                    {
                        Id       = i.ToString(),
                        Email    = $"em{i}email.com",
                        Username = $"Username {i}"
                    });
                }

                var allUsers = await adminUserService.AllAsync();

                var allUsersList = allUsers.ToList();

                for (var i = 0; i < 10; i++)
                {
                    Assert.Equal(expectedUsers[i].Id, allUsersList[i].Id);
                    Assert.Equal(expectedUsers[i].Email, allUsersList[i].Email);
                    Assert.Equal(expectedUsers[i].Username, allUsersList[i].Username);
                }
            }
        }
        public async Task FindNameShouldReturnNameOfTheCategory()
        {
            // Arrange
            Mapper.Initialize(config => config.AddProfile <AutoMapperProfile>());
            var db = this.Context;

            this.PopulateData(db);

            var categoriesService = new AdminUserService(db);
            var adminId           = "eggegegegegeadmin";

            // Act
            var result = await categoriesService.AllAsync(adminId);

            // Assert
            result
            .Should()
            .Match(r => r.ElementAt(0).Id == "eggegegegegepesho" &&
                   r.ElementAt(1).Id == "eggegegegegepesho2" &&
                   r.ElementAt(2).Id == "eggegegegegepesho3");
        }