예제 #1
0
        public async Task GetAllGroups_ReturnsGroups()
        {
            var group1 = new Group
            {
                Id   = 1,
                Name = "Group 1"
            };
            var group2 = new Group
            {
                Id   = 2,
                Name = "Group 2"
            };

            var service = new Mock <IGroupService>();

            service.Setup(x => x.FetchAll())
            .Returns(Task.FromResult(new List <Group> {
                group1, group2
            }))
            .Verifiable();


            var controller = new GroupsController(service.Object, Mapper.Instance);

            var result = (await controller.GetGroups()).Result as OkObjectResult;

            List <GroupViewModel> groups = ((IEnumerable <GroupViewModel>)result.Value).ToList();

            Assert.AreEqual(2, groups.Count);
            AssertAreEqual(groups[0], group1);
            AssertAreEqual(groups[1], group2);
            service.VerifyAll();
        }
        private void CreateGroupIdToChannelNameDic()
        {
            groupToAddtionalChannelDic = new Dictionary <string, string>();
            Dictionary <string, string> countyToAlertDic = CreateCountyToAlertDic();
            IEnumerable <AADIdentity>   groups           = groupsController.GetGroups(graphClientManager.GetGraphHttpClient())
                                                           .GetAwaiter().GetResult();

            foreach (string countyName in countyToAlertDic.Keys)
            {
                bool groupAlreayCreated = false;
                foreach (AADIdentity identity in groups)
                {
                    if (identity.DisplayName.Equals(countyName, StringComparison.InvariantCultureIgnoreCase))
                    {
                        groupToAddtionalChannelDic.Add(identity.Id, countyToAlertDic[countyName]);
                        groupAlreayCreated = true;
                        break;
                    }
                }

                if (!groupAlreayCreated)
                {
                    AADIdentity group = groupsController
                                        .CreateGroup(graphClientManager.GetGraphHttpClient(), countyName).GetAwaiter().GetResult();
                    groupToAddtionalChannelDic.Add(group.Id, countyToAlertDic[countyName]);
                }
            }
        }
예제 #3
0
        public void GetAllGroups_ShouldReturnAllGroups()
        {
            var testGroup  = GetTestGroup();
            var controller = new GroupsController(testGroup);

            var result = controller.GetGroups() as DbQuery <Group>;

            Assert.AreEqual(testGroup.Count, result.Count());
        }
예제 #4
0
        public async Task GetGroups_Groups_ReturnsMergedGroupsStatusOk()
        {
            // Arrange
            var controller = new GroupsController(new GroupRepositoryStub(), new UserRepositoryStub(),
                                                  new SmartLockRepositoryStub(), new AzureAdRepositoryStub(), _mapper);


            /*var groups = new List<Group>
             * {
             *      new Group { Id = Guid.Parse("c374cb18-862e-4fef-871f-ae08337d1f76"), Status = Status.Active  },
             *      new Group { Id = Guid.Parse("1933c967-2e14-4e95-bdb0-54723595672d"), Status = Status.Inactive },
             *      new Group { Id = Guid.Parse("e44e9133-6f88-42b9-84ba-970f9293c87a"), Status = Status.Suspended },
             *      new Group { Id = Guid.Parse("e1f2df93-23b6-45ec-9e2f-a845fcd25cff"), Status = Status.Active}
             * };*/

            // Act
            var result = await controller.GetGroups();

            // Assert
            Assert.IsInstanceOfType(result.Result, typeof(OkObjectResult));
        }
        public IEnumerable <string> GetNewTeamsGroupIds()
        {
            List <string>             groupIdList = new List <string>();
            IEnumerable <AADIdentity> groups      = groupsController.GetGroups(graphClientManager.GetGraphHttpClient())
                                                    .GetAwaiter().GetResult();

            foreach (string stateName in GetUSStateNamesHasConfirmedCases())
            {
                AADIdentity group = groups.FirstOrDefault(x =>
                                                          x.DisplayName.Equals(stateName, StringComparison.InvariantCultureIgnoreCase));
                if (group == null)
                {
                    Console.WriteLine($"Warning: Cannot find group with display name '{stateName}'");
                }
                else
                {
                    groupIdList.Add(group.Id);
                }
            }

            return(groupIdList);
        }