Exemplo n.º 1
0
        public async Task GetAllExploreUsers_ShouldBeDoneSuccessfully()
        {
            // Arrange
            var friends = new List <User>();
            var friend  = new PowerUser()
            {
                Id        = 1,
                Firstname = "Milos"
            };

            friends.Add(friend);

            var friendsToReturn = new List <ExploreUserDto>()
            {
                new ExploreUserDto()
                {
                    Id        = 1,
                    Firstname = "Milos"
                }
            };

            _unitOfWorkMock.Setup(x => x.Friends.GetAllExploreUsers(It.IsAny <int>()))
            .ReturnsAsync(friends);

            _mapperMock.Setup(x => x.Map <ICollection <ExploreUserDto> >(It.IsAny <ICollection <User> >()))
            .Returns(friendsToReturn);

            // Act
            var result = await _sut.GetAllExploreUsers(It.IsAny <int>());

            // Assert
            Assert.Equal(friend.Id, result.FirstOrDefault().Id);
            Assert.Equal(friend.Firstname, result.FirstOrDefault().Firstname);
        }
Exemplo n.º 2
0
        public IActionResult Tag(string tag)
        {
            string    id       = User.Claims.FirstOrDefault() == null ? "" : User.Claims.FirstOrDefault().Issuer;
            PowerUser model    = Helper.CurrentUser(id, _context);
            var       tagModel = _context.Tags.Where(x => x.Name == tag).FirstOrDefault();

            List <Blogs> list = (from c in _context.Blogs
                                 join t in _context.BlogTag
                                 on new { id = c.Id } equals new { id = t.BlogId }
                                 into temp
                                 from bb in temp.DefaultIfEmpty()
                                 join p in _context.PowerUser
                                 on new { id = c.PowerUserId } equals new { id = p.Id }
                                 where bb.TagId == tagModel.Id && c.IsOpen == true
                                 orderby c.U_CreateDate descending
                                 select new Blogs
            {
                Id = c.Id,
                IsDelete = c.IsDelete,
                IsOpen = c.IsOpen,
                MainContent = c.MainContent,
                Title = c.Title,
                PageView = c.PageView,
                PowerUserId = c.PowerUserId,
                PowerUser = p,
                ReCommend = c.ReCommend,
                ShortContent = c.ShortContent,
                U_CreateDate = c.U_CreateDate
            }).ToList();


            ViewBag.UserInfo = model;
            ViewBag.TagList  = _context.Tags.ToList();
            return(View("Index", list));
        }
Exemplo n.º 3
0
        public async Task GetUser_ShouldReturnUser()
        {
            // Arrange
            var userId    = 1;
            var firstname = "Jelena";
            var lastname  = "Ralevic";
            var user      = new PowerUser()
            {
                Id        = userId,
                Firstname = firstname,
                Lastname  = lastname
            };

            var userToReturnDto = new UserToReturnDto()
            {
                Id        = userId,
                Firstname = firstname,
                Lastname  = lastname
            };

            _unitOfWorkMock.Setup(x => x.Users.GetUserByIdWithAdditionalInformation(userId))
            .ReturnsAsync(user);

            _mapperMock.Setup(x => x.Map <UserToReturnDto>(It.IsAny <PowerUser>()))
            .Returns(userToReturnDto);
            // Act
            var result = await _sut.GetUser(userId);

            // Assert
            Assert.Equal(userId, result.Id);
            Assert.Equal(firstname, result.Firstname);
            Assert.Equal(lastname, result.Lastname);
        }
Exemplo n.º 4
0
        //[ValidateAntiForgeryToken]
        public ActionResult Create(Tags tag)
        {
            try
            {
                if (string.IsNullOrEmpty(tag.Name))
                {
                    ModelState.AddModelError("Name", "请输入名次");
                }
                if (!ModelState.IsValid)
                {
                    return(View(tag));
                }
                PowerUser puser = Helper.CurrentUser(User.Claims.FirstOrDefault().Issuer, _db);
                Guid      id    = Guid.NewGuid();
                tag.Id           = id;
                tag.Creator      = puser.Cn;
                tag.CreatorId    = puser.Id;
                tag.U_CreateDate = DateTime.Now;
                _db.Tags.Add(tag);
                _db.SaveChanges();

                return(RedirectToAction("Index", "Tags"));
            }
            catch (Exception ex)
            {
                return(View());
            }
        }
Exemplo n.º 5
0
    public static void UpdateAllWires()
    {
        PowerUser.OffAll();

        for (int i = 0; i < wires.Count; ++i)
        {
            wires[i].UpdateConnection();
        }

        // propogate twice
        for (int i = 0; i < wires.Count; ++i)
        {
            wires[i].Propogate();
        }
        for (int i = 0; i < wires.Count; ++i)
        {
            wires[i].Propogate();
        }

        // check them out??? i dunno i hate my life
        for (int i = 0; i < wires.Count; ++i)
        {
            if (wires[i].powered)
            {
                wires[i].CheckPowerStatus();
            }
        }
    }
Exemplo n.º 6
0
        public async Task AcceptUser_ShouldBeReturnFalse_WhenIsNotCompleted()
        {
            // Arrange
            var expectedMessage  = "User hasn't joined group!";
            var groupId          = 1;
            var groupDescription = "Test";
            var groupName        = "Test";
            var creator          = new PowerUser()
            {
                Id = 1
            };
            var dateCreated = DateTime.Now;
            var isActive    = true;
            var locationId  = 1;
            var group       = new Group()
            {
                Id          = groupId,
                Description = groupDescription,
                Location    = new Location(),
                Matchdays   = new List <Matchday>(),
                Memberships = new List <Membership>(),
                Name        = groupName,
                CreatedBy   = creator,
                DateCreated = dateCreated,
                IsActive    = isActive,
                LocationId  = locationId
            };

            var membership = new Membership()
            {
                Accepted         = true,
                Favorite         = true,
                Group            = group,
                Role             = Role.Admin,
                User             = creator,
                DateAccepted     = DateTime.Now,
                DateSent         = DateTime.Now,
                GroupId          = groupId,
                MembershipStatus = MembershipStatus.Accepted,
                UserId           = creator.Id
            };

            _unitOfWork.Setup(x => x.Groups.GetById(It.IsAny <int>()))
            .ReturnsAsync(group);

            _unitOfWork.Setup(x => x.Users.GetById(It.IsAny <int>()))
            .ReturnsAsync(creator);

            _unitOfWork.Setup(x => x.Memberships.GetMembershipById(It.IsAny <int>(), It.IsAny <int>()))
            .ReturnsAsync(membership);

            _unitOfWork.Setup(x => x.Complete()).ReturnsAsync(false);

            // Act
            var result = await _sut.AcceptUser(It.IsAny <int>(), It.IsAny <int>());

            // Assert
            Assert.False(result.Key);
            Assert.Equal(expectedMessage, result.Value);
        }
Exemplo n.º 7
0
        // GET: PowerUser/Create
        public ActionResult Create()
        {
            PowerUser model = new PowerUser();

            ViewData["message"] = "";
            return(View(model));
        }
Exemplo n.º 8
0
        public IActionResult Create(string comment, string blogId)
        {
            try
            {
                var       creatorId = User.Claims.FirstOrDefault().Issuer;
                PowerUser puser     = Helper.CurrentUser(creatorId, _db);
                int       sortno    = _db.Comment.Where(x => x.BlogId.ToString() == blogId).DefaultIfEmpty().Max(x => x.SortNo);

                Comment model = new Comment();
                model.Id           = Guid.NewGuid();
                model.MainContent  = comment;
                model.Creator      = puser.UID;
                model.CreatorId    = puser.Id;
                model.Oppose       = 0;
                model.Support      = 0;
                model.BlogId       = Guid.Parse(blogId);
                model.U_CreateDate = DateTime.Now;
                model.SortNo       = sortno + 1;

                _db.Comment.Add(model);
                _db.SaveChanges();
                return(Content(JsonConvert.SerializeObject(model)));
            }
            catch (Exception ex)
            {
                return(View());
            }
        }
Exemplo n.º 9
0
        private void SaveAuthen(PowerUser model)
        {
            string userinfo = JsonConvert.SerializeObject(new PowerUser()
            {
                Id  = model.Id,
                UID = model.UID,
                Cn  = model.Cn
            });

            HttpContext.Session.SetString("UserInfo", userinfo);


            //使用Form验证方式
            List <Claim> claims = new List <Claim>();

            claims.Add(new Claim(ClaimTypes.Name, model.Cn, ClaimValueTypes.String, model.Id.ToString()));
            var userIdentity = new ClaimsIdentity("管理员"); //角色

            userIdentity.AddClaims(claims);
            var userPrincipal = new ClaimsPrincipal(userIdentity);


            HttpContext.SignInAsync(CookieAuthenInfo.WebCookieInstance, userPrincipal,
                                    new Microsoft.AspNetCore.Authentication.AuthenticationProperties
            {
                ExpiresUtc   = DateTime.UtcNow.AddDays(1),
                IsPersistent = true,
                AllowRefresh = false
            });
        }
Exemplo n.º 10
0
 public bool ReportBug(string id)
 {
     if (!PowerUser.IsPowerUser(User.Identity.Name))
     {
         return(false);
     }
     return(GameMgr.ReportBug(id));
 }
Exemplo n.º 11
0
 public bool RedoOneStep(string id)
 {
     if (!PowerUser.IsPowerUser(User.Identity.Name))
     {
         return(false);
     }
     return(GameMgr.RedoOneStep(id));
 }
Exemplo n.º 12
0
        public async Task UpdateUser_ShouldUpdate()
        {
            // Arrange
            var responseMessage = "User successfully updated.";
            var userId          = 1;
            var firstname       = "Jelena";
            var lastname        = "Ralevic";
            var countryId       = 2;
            var cityId          = 3;

            var user = new PowerUser()
            {
                Id        = userId,
                Firstname = firstname,
                Lastname  = lastname
            };

            var userToUpdateDto = new UserToUpdateDto()
            {
                Country = countryId,
                City    = cityId
            };

            var city = new City()
            {
                Id        = cityId,
                Name      = "Beograd",
                CountryId = countryId,
            };

            var country = new Country()
            {
                Id     = countryId,
                Name   = "Srbija",
                Cities = new List <City>()
                {
                    city
                }
            };

            _unitOfWorkMock.Setup(x => x.Users.GetById(It.IsAny <int>()))
            .ReturnsAsync(user);

            _unitOfWorkMock.Setup(x => x.Countries.GetCountryWithCities(countryId))
            .ReturnsAsync(country);

            _unitOfWorkMock.Setup(x => x.Cities.GetCityById(cityId, countryId))
            .ReturnsAsync(city);

            _unitOfWorkMock.Setup(x => x.Complete())
            .ReturnsAsync(true);
            // Act
            var result = await _sut.UpdateUser(userId, userToUpdateDto);

            // Assert
            Assert.Equal(responseMessage, result.Value);
        }
Exemplo n.º 13
0
        /// <summary>
        /// 回退一步
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool UndoOneStep(string id)
        {
            var u = User.Identity;

            if (!PowerUser.IsPowerUser(User.Identity.Name))
            {
                return(false);
            }
            return(GameMgr.UndoOneStep(id));
        }
Exemplo n.º 14
0
        public async Task CreateGroup_ShouldReturnTrue_WhenLocationDoesntExist_AndIsCompleted()
        {
            // Arrange
            var expectedMessage = "Group created successfully!";
            var groupDto        = new GroupForCreationDto()
            {
                Image = null,
            };
            var powerUser = new PowerUser()
            {
                Id = 1
            };
            var group = new Group()
            {
                Id    = 1,
                Image = null
            };
            var membership = new Membership()
            {
                UserId           = powerUser.Id,
                Accepted         = true,
                Favorite         = true,
                Group            = null,
                Role             = Role.Member,
                User             = powerUser,
                DateAccepted     = DateTime.Now,
                DateSent         = DateTime.Now,
                GroupId          = group.Id,
                MembershipStatus = MembershipStatus.Sent
            };

            _unitOfWork.Setup(x => x.Users.GetById(It.IsAny <int>()))
            .ReturnsAsync(powerUser);

            _mapperMock.Setup(x => x.Map <Group>(It.IsAny <GroupForCreationDto>()))
            .Returns(group);

            _unitOfWork.Setup(x => x.Locations.GetByName(It.IsAny <string>()))
            .ReturnsAsync(() => null);

            _unitOfWork.Setup(x => x.Groups.Add(group)).Verifiable();

            _unitOfWork.Setup(x => x.Complete()).ReturnsAsync(true);

            _unitOfWork.Setup(x => x.Memberships.Add(membership)).Verifiable();


            // Act
            var result = await _sut.CreateGroup(It.IsAny <int>(), groupDto);

            // Assert
            Assert.True(result.Key);
            Assert.Equal(expectedMessage, result.Value);
        }
Exemplo n.º 15
0
        //[ValidateInput(false)]
        public IActionResult Create(IFormCollection collection)
        {
            try
            {
                Guid   id         = Guid.Parse(collection["Id"]);
                var    title      = collection["Title"];
                var    content    = collection["MainContent"];
                var    strIsopen  = collection["IsOPen"];
                bool   IsOpen     = strIsopen == "Tree" ? true : false;
                string checkedtag = collection["checkedtag"];

                if (string.IsNullOrEmpty(title) || string.IsNullOrEmpty(content))
                {
                    ViewBag.TagList = _context.Tags.ToList();
                    return(View());
                }



                PowerUser model = Helper.CurrentUser(User.Claims.FirstOrDefault().Issuer, _context);
                //Guid id = Guid.NewGuid();

                _context.Blogs.Add(new Blogs()
                {
                    Id = id, Title = title, U_CreateDate = DateTime.Now, PowerUser = model, ShortContent = Helper.ReplaceHtmlTag(content, 135), MainContent = content, IsOpen = IsOpen, IsDelete = false
                });

                List <BlogTag> taglist = new List <BlogTag>();
                string[]       tags    = checkedtag.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string item in tags)
                {
                    taglist.Add(new BlogTag()
                    {
                        Id = Guid.NewGuid(), BlogId = id, TagId = Guid.Parse(item), U_CreateDate = DateTime.Now
                    });
                }
                _context.BlogTag.AddRange(taglist);

                var list = _context.Tags.Where(x => tags.Contains(x.Id.ToString())).ToList();
                foreach (var item in list)
                {
                    item.BlogNum++;
                }
                _context.Tags.UpdateRange(list);

                _context.SaveChanges();
                return(RedirectToAction("Index", "Home"));
            }
            catch
            {
                return(View());
            }
        }
Exemplo n.º 16
0
 /// <summary>
 /// 恢复备份
 /// </summary>
 /// <param name="filename"></param>
 /// <returns></returns>
 public IActionResult RestoreData(string filename)
 {
     if (!PowerUser.IsPowerUser(User.Identity.Name))
     {
         return(Redirect("/home/index"));
     }
     ViewData["nameList"] = string.Join(",", GameMgr.RestoreDictionary(filename));
     //恢复到未维护状态
     ServerStatus.IsStopSyntax = false;
     return(Redirect("/home/viewgame/" + "test01"));
     //return View();
 }
Exemplo n.º 17
0
        public async Task <ICollection <Membership> > GetCreatedGroupsForUser(PowerUser powerUser)
        {
            var groups = await DataContext.Memberships
                         .Where(m => m.UserId == powerUser.Id && m.Role == Role.Owner)
                         .Include(m => m.Group)
                         .ThenInclude(g => g.Memberships)
                         .Include(m => m.Group.Location)
                         .ThenInclude(l => l.City)
                         .ThenInclude(l => l.Country)
                         .ToListAsync();

            return(groups);
        }
Exemplo n.º 18
0
        private async Task LoadAsync(PowerUser user)
        {
            var userName = await _userManager.GetUserNameAsync(user);

            var phoneNumber = await _userManager.GetPhoneNumberAsync(user);

            Username = userName;

            Input = new InputModel
            {
                PhoneNumber = phoneNumber
            };
        }
Exemplo n.º 19
0
        private async Task LoadAsync(PowerUser user)
        {
            var email = await _userManager.GetEmailAsync(user);

            Email = email;

            Input = new InputModel
            {
                NewEmail = email,
            };

            IsEmailConfirmed = await _userManager.IsEmailConfirmedAsync(user);
        }
Exemplo n.º 20
0
        public async Task <ICollection <GroupToReturnDto> > GetAllCreatedGroups(int userId)
        {
            var user = await _unitOfWork.Users.GetUserByIdWithAdditionalInformation(userId);

            if (!(user is PowerUser))
            {
                return(null);
            }

            PowerUser powerUser     = (PowerUser)user;
            var       createdGroups = await _unitOfWork.Groups.GetCreatedGroupsForUser(powerUser);

            return(_mapper.Map <ICollection <GroupToReturnDto> >(createdGroups));
        }
Exemplo n.º 21
0
        /// <summary>
        /// 删除游戏
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>

        public bool DeleteOneGame(string id)
        {
            if (!PowerUser.IsPowerUser(User.Identity.Name))
            {
                return(false);
            }
            //数据库一起删除
            GameInfoModel gameInfoModel = this.dbContext.GameInfoModel.SingleOrDefault(item => item.name == id);

            if (gameInfoModel != null)
            {
                this.dbContext.GameInfoModel.Remove(gameInfoModel);
                this.dbContext.SaveChanges();
            }
            return(GameMgr.DeleteOneGame(id));
        }
Exemplo n.º 22
0
        // GET: PowerUser
        public ActionResult Index()
        {
            string    userId = User.Claims.FirstOrDefault().Issuer;
            PowerUser model  = _db.PowerUser.Where(x => x.Id == Guid.Parse(userId)).FirstOrDefault();

            if (model.IsSuperAdmin == true)
            {
                var list = _db.Tags.ToList();
                return(View(list));
            }
            else
            {
                var list = _db.Tags.Where(x => x.CreatorId == Guid.Parse(userId)).ToList();
                return(View(list));
            }
        }
Exemplo n.º 23
0
        public IActionResult DeleteAllGame()
        {
            if (!PowerUser.IsPowerUser(User.Identity.Name))
            {
                return(Redirect("/home/index"));
            }
            var task = _userManager.GetUserAsync(HttpContext.User);

            Task[] taskarray = new Task[] { task };
            Task.WaitAll(taskarray, millisecondsTimeout: 1000);
            if ("*****@*****.**".Equals(task.Result.UserName))
            {
                GameMgr.DeleteAllGame();
            }
            return(Redirect("/home/index"));
        }
Exemplo n.º 24
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl      = returnUrl ?? Url.Content("~/");
            ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();
            if (ModelState.IsValid)
            {
                var user = new PowerUser {
                    UserName = Input.Email, Email = Input.Email
                };
                var result = await _userManager.CreateAsync(user, Input.Password);

                if (result.Succeeded)
                {
                    _logger.LogInformation("User created a new account with password.");

                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
                    var callbackUrl = Url.Page(
                        "/Account/ConfirmEmail",
                        pageHandler: null,
                        values: new { area = "Identity", userId = user.Id, code = code },
                        protocol: Request.Scheme);

                    await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
                                                      $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");

                    if (_userManager.Options.SignIn.RequireConfirmedAccount)
                    {
                        return(RedirectToPage("RegisterConfirmation", new { email = Input.Email }));
                    }
                    else
                    {
                        await _signInManager.SignInAsync(user, isPersistent : false);

                        return(LocalRedirect(returnUrl));
                    }
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }
Exemplo n.º 25
0
        public ActionResult Create(IFormCollection collection)
        {
            PowerUser model = new PowerUser();

            try
            {
                string uid      = collection["UID"];
                string password = collection["PassWord"];
                string cn       = collection["Cn"];
                Guid   id       = Guid.NewGuid();
                model.Id           = id;
                model.UID          = uid;
                model.Cn           = cn;
                model.PassWord     = password;
                model.U_CreateDate = DateTime.Now;

                if (_db.PowerUser.Where(x => x.UID == uid.Trim()).Count() > 0)
                {
                    ViewData["message"] = "用户名已存在";
                    return(View(model));
                }

                _db.PowerUser.Add(model);
                _db.SaveChanges();

                string userinfo = JsonConvert.SerializeObject(new PowerUser()
                {
                    Id  = id,
                    UID = uid,
                    Cn  = cn
                });

                HttpContext.Session.SetString("UserInfo", userinfo);

                SaveAuthen(model);

                return(RedirectToAction("Index", "Home"));

                // TODO: Add insert logic her
            }
            catch (Exception ex)
            {
                ViewData["message"] = "账号注册异常,刷新后重试";
                return(View(model));
            }
        }
Exemplo n.º 26
0
    public void Disconnect(bool rightArm)
    {
        if (rightArm)
        {
            rightType = CType.NULL;
            rightWire = null;
            rightPow  = null;
        }
        else
        {
            leftType = CType.NULL;
            leftWire = null;
            leftPow  = null;
        }

        UpdateAllWires();
    }
Exemplo n.º 27
0
        public async Task GainAchievement_ShouldNotGainAchievement_WhenGainedAchievementIsNotSaved()
        {
            // Arrange
            var userId = 1;
            var user   = new PowerUser
            {
                Id = userId
            };

            var achievementName   = "Top goal scorer";
            var achievementId     = 1;
            var achievementPoints = 5;
            var achievementIcon   = "test";
            var achievementValue  = 10;
            var achievement       = new Achievement
            {
                Id     = achievementId,
                Name   = achievementName,
                Points = achievementPoints,
                Icon   = achievementIcon,
                Value  = achievementValue
            };

            var dateAchieved         = DateTime.Now;
            var gainedAchievementDto = new GainedAchievementForCreationDto
            {
                UserId       = userId,
                DateAchieved = dateAchieved,
                Value        = achievementValue
            };

            _unitOfWorkMock.Setup(x => x.Achievements.GetAchievementByValue(It.IsAny <int>()))
            .ReturnsAsync(achievement);
            _unitOfWorkMock.Setup(x => x.Achievements.GetGainedAchievement(It.IsAny <int>(), achievementValue))
            .ReturnsAsync(() => null);
            _unitOfWorkMock.Setup(x => x.Users.GetById(It.IsAny <int>()))
            .ReturnsAsync(user);
            _unitOfWorkMock.Setup(x => x.Complete())
            .ReturnsAsync(false);
            // Act
            KeyValuePair <bool, string> response = await _sut.GainAchievement(userId, gainedAchievementDto);

            // Assert
            Assert.False(response.Key);
            Assert.Equal("Problem gaining achievement!", response.Value);
        }
Exemplo n.º 28
0
        private async Task LoadSharedKeyAndQrCodeUriAsync(PowerUser user)
        {
            // Load the authenticator key & QR code URI to display on the form
            var unformattedKey = await _userManager.GetAuthenticatorKeyAsync(user);

            if (string.IsNullOrEmpty(unformattedKey))
            {
                await _userManager.ResetAuthenticatorKeyAsync(user);

                unformattedKey = await _userManager.GetAuthenticatorKeyAsync(user);
            }

            SharedKey = FormatKey(unformattedKey);

            var email = await _userManager.GetEmailAsync(user);

            AuthenticatorUri = GenerateQrCodeUri(email, unformattedKey);
        }
Exemplo n.º 29
0
        public async Task GetAllCreatedGroups_ShouldBeDoneSuccessfully()
        {
            // Arrange
            var groupsToReturn = new List <GroupToReturnDto>()
            {
                new GroupToReturnDto()
                {
                    Id = 1
                }
            };

            var memberships = new List <Membership>()
            {
                new Membership()
                {
                    UserId = 1,
                }
            };

            var powerUser = new PowerUser()
            {
                Id = 1
            };

            _unitOfWork.Setup(x => x.Users.GetUserByIdWithAdditionalInformation(It.IsAny <int>()))
            .ReturnsAsync(powerUser);

            _unitOfWork.Setup(x => x.Groups.GetCreatedGroupsForUser(powerUser))
            .ReturnsAsync(memberships);

            _mapperMock.Setup(x => x.Map <ICollection <GroupToReturnDto> >(memberships))
            .Returns(groupsToReturn);

            // Act
            var result = await _sut.GetAllCreatedGroups(It.IsAny <int>());

            // Assert
            var group = result.FirstOrDefault();

            Assert.NotNull(group);
            Assert.NotNull(result);
            Assert.NotEmpty(result);
            Assert.Equal(1, group.Id);
        }
Exemplo n.º 30
0
        public async Task AcceptUser_ShouldReturnFalse_WhenUserIsMissing()
        {
            // Arrange
            var expectedMessage  = "Specified user doesn't exist!";
            var groupId          = 1;
            var groupDescription = "Test";
            var groupName        = "Test";
            var creator          = new PowerUser()
            {
                Id = 1
            };
            var dateCreated = DateTime.Now;
            var isActive    = true;
            var locationId  = 1;
            var group       = new Group()
            {
                Id          = groupId,
                Description = groupDescription,
                Location    = new Location(),
                Matchdays   = new List <Matchday>(),
                Memberships = new List <Membership>(),
                Name        = groupName,
                CreatedBy   = creator,
                DateCreated = dateCreated,
                IsActive    = isActive,
                LocationId  = locationId
            };

            _unitOfWork.Setup(x => x.Groups.GetById(It.IsAny <int>()))
            .ReturnsAsync(group);

            _unitOfWork.Setup(x => x.Users.GetById(It.IsAny <int>()))
            .ReturnsAsync(() => null);

            // Act
            var result = await _sut.AcceptUser(It.IsAny <int>(), It.IsAny <int>());

            // Assert
            Assert.False(result.Key);
            Assert.Equal(expectedMessage, result.Value);
        }