public void GetGroups_ShouldReturn_NotNull()
        {
            // Arrange
            var groups = new List <GroupsModel> {
                new GroupsModel()
            };
            List <GroupsDtoModel> groupsDtos = new List <GroupsDtoModel>();

            fakeGroupsRepository.Setup(a => a.GetAll()).Returns(groups);
            groupsService = new GroupsService(fakeGroupsRepository.Object);

            try
            {
                // Act
                groupsDtos         = (List <GroupsDtoModel>)groupsService.GetGroups();
                operationSucceeded = true;
            }
            catch (Exception ex)
            {
                errorMessage = ex.Message + " | " + ex.StackTrace;
            }

            // Assert
            Assert.IsTrue(groupsDtos.Count > 0, errorMessage);
        }
Exemple #2
0
        // Get groups.
        // This snippet requires an admin work account.
        public async Task <ActionResult> GetGroups()
        {
            ResultsViewModel results = new ResultsViewModel();

            try
            {
                // Get groups.
                results.Items = await groupsService.GetGroups();
            }
            catch (ServiceException se)
            {
                if ((se.InnerException as AuthenticationException)?.Error.Code == Resource.Error_AuthChallengeNeeded)
                {
                    HttpContext.Request.GetOwinContext().Authentication.Challenge();
                    return(new EmptyResult());
                }
                return(RedirectToAction("Index", "Error", new { message = string.Format(Resource.Error_Message, Request.RawUrl, se.Error.Code, se.Error.Message) }));
            }
            return(View("Groups", results));
        }
Exemple #3
0
        // Get groups.
        // This snippet requires an admin work account.
        public async Task <ActionResult> GetGroups()
        {
            ResultsViewModel results = new ResultsViewModel();

            try
            {
                // Initialize the GraphServiceClient.
                GraphServiceClient graphClient = SDKHelper.GetAuthenticatedClient();

                // Get groups.
                results.Items = await groupsService.GetGroups(graphClient);
            }
            catch (ServiceException se)
            {
                if (se.Error.Message == Resource.Error_AuthChallengeNeeded)
                {
                    return(new EmptyResult());
                }
                return(RedirectToAction("Index", "Error", new { message = string.Format(Resource.Error_Message, Request.RawUrl, se.Error.Code, se.Error.Message) }));
            }
            return(View("Groups", results));
        }