public async Task DeleteTeam()
        {
            CSEntryChange cs = CSEntryChange.Create();

            cs.ObjectType             = "team";
            cs.ObjectModificationType = ObjectModificationType.Add;
            cs.CreateAttributeAdd("displayName", "mytestteam");
            cs.CreateAttributeAdd("owner", UnitTestControl.Users.GetRange(0, 1).Select(t => t.Id).ToList <object>());

            string teamid = await TeamTests.SubmitCSEntryChange(cs);

            cs                        = CSEntryChange.Create();
            cs.ObjectType             = "team";
            cs.ObjectModificationType = ObjectModificationType.Delete;
            cs.AnchorAttributes.Add(AnchorAttribute.Create("id", teamid));

            await TeamTests.SubmitCSEntryChange(cs);

            try
            {
                var team = await GraphHelperGroups.GetGroup(UnitTestControl.Client, teamid, CancellationToken.None);

                Assert.Fail("The team was not deleted");
            }
            catch (ServiceException ex)
            {
                if (ex.StatusCode != System.Net.HttpStatusCode.NotFound)
                {
                    Assert.Fail("The team was not deleted");
                }
            }
        }
        public async Task CreateTeamTestDeniedPermissions()
        {
            string mailNickname = $"ut-{Guid.NewGuid()}";

            CSEntryChange cs = CSEntryChange.Create();

            cs.ObjectType             = "team";
            cs.ObjectModificationType = ObjectModificationType.Add;
            cs.CreateAttributeAdd("displayName", "mytestteam");
            cs.CreateAttributeAdd("description", "my description");
            cs.CreateAttributeAdd("mailNickname", mailNickname);
            cs.CreateAttributeAdd("owner", UnitTestControl.Users.GetRange(0, 1).Select(t => t.Id).ToList <object>());

            cs.CreateAttributeAdd("memberSettings_allowCreateUpdateChannels", false);
            cs.CreateAttributeAdd("memberSettings_allowDeleteChannels", false);
            cs.CreateAttributeAdd("memberSettings_allowAddRemoveApps", false);
            cs.CreateAttributeAdd("memberSettings_allowCreateUpdateRemoveTabs", false);
            cs.CreateAttributeAdd("memberSettings_allowCreateUpdateRemoveConnectors", false);
            cs.CreateAttributeAdd("guestSettings_allowCreateUpdateChannels", false);
            cs.CreateAttributeAdd("guestSettings_allowDeleteChannels", false);
            cs.CreateAttributeAdd("messagingSettings_allowUserEditMessages", false);
            cs.CreateAttributeAdd("messagingSettings_allowUserDeleteMessages", false);
            cs.CreateAttributeAdd("messagingSettings_allowOwnerDeleteMessages", false);
            cs.CreateAttributeAdd("messagingSettings_allowTeamMentions", false);
            cs.CreateAttributeAdd("messagingSettings_allowChannelMentions", false);
            cs.CreateAttributeAdd("funSettings_allowGiphy", false);
            cs.CreateAttributeAdd("funSettings_giphyContentRating", "Moderate");
            cs.CreateAttributeAdd("funSettings_allowStickersAndMemes", false);
            cs.CreateAttributeAdd("funSettings_allowCustomMemes", false);
            cs.CreateAttributeAdd("visibility", "Public");

            string teamid = await TeamTests.SubmitCSEntryChange(cs);

            var team = await GraphHelperTeams.GetTeam(UnitTestControl.BetaClient, teamid, CancellationToken.None);

            var group = await GraphHelperGroups.GetGroup(UnitTestControl.Client, teamid, CancellationToken.None);

            Assert.AreEqual("mytestteam", group.DisplayName);
            Assert.AreEqual("my description", group.Description);
            Assert.AreEqual(mailNickname, group.MailNickname);
            Assert.AreEqual("Public", group.Visibility, true);

            Assert.AreEqual(false, team.MemberSettings.AllowCreateUpdateChannels);
            Assert.AreEqual(false, team.MemberSettings.AllowDeleteChannels);
            Assert.AreEqual(false, team.MemberSettings.AllowAddRemoveApps);
            Assert.AreEqual(false, team.MemberSettings.AllowCreateUpdateRemoveTabs);
            Assert.AreEqual(false, team.MemberSettings.AllowCreateUpdateRemoveConnectors);
            Assert.AreEqual(false, team.GuestSettings.AllowCreateUpdateChannels);
            Assert.AreEqual(false, team.GuestSettings.AllowDeleteChannels);
            Assert.AreEqual(false, team.MessagingSettings.AllowUserEditMessages);
            Assert.AreEqual(false, team.MessagingSettings.AllowUserDeleteMessages);
            Assert.AreEqual(false, team.MessagingSettings.AllowOwnerDeleteMessages);
            Assert.AreEqual(false, team.MessagingSettings.AllowTeamMentions);
            Assert.AreEqual(false, team.MessagingSettings.AllowChannelMentions);
            Assert.AreEqual(false, team.FunSettings.AllowGiphy);
            Assert.AreEqual(GiphyRatingType.Moderate, team.FunSettings.GiphyContentRating);
            Assert.AreEqual(false, team.FunSettings.AllowStickersAndMemes);
            Assert.AreEqual(false, team.FunSettings.AllowCustomMemes);
        }
        private static async Task <string> SubmitCSEntryChange(CSEntryChange cs)
        {
            string teamid;

            CSEntryChangeResult teamResult = await TeamTests.teamExportProvider.PutCSEntryChangeAsync(cs);

            if (cs.ObjectModificationType == ObjectModificationType.Add)
            {
                TeamTests.AddTeamToCleanupTask(teamResult);
                teamid = teamResult.GetAnchorValueOrDefault <string>("id");
            }
            else
            {
                teamid = cs.GetAnchorValueOrDefault <string>("id");
            }

            Assert.IsTrue(teamResult.ErrorCode == MAExportError.Success);

            return(teamid);
        }
        public async Task CreateTeamFromEduTemplate()
        {
            string template = "https://graph.microsoft.com/beta/teamsTemplates('educationClass')";

            CSEntryChange cs = CSEntryChange.Create();

            cs.ObjectType             = "team";
            cs.ObjectModificationType = ObjectModificationType.Add;
            cs.CreateAttributeAdd("displayName", "mytestteam");
            cs.CreateAttributeAdd("owner", UnitTestControl.Users.GetRange(0, 1).Select(t => t.Id).ToList <object>());
            cs.CreateAttributeAdd("template", template);

            string teamid = await TeamTests.SubmitCSEntryChange(cs);

            var team = await GraphHelperTeams.GetTeam(UnitTestControl.BetaClient, teamid, CancellationToken.None);

            //Assert.AreEqual(template, team.Template);
            // Template information is not being returned from the API, so the following check looks for an attribute only present on classroom templates
            Assert.IsNotNull(team.AdditionalData);
            Assert.IsTrue(team.AdditionalData.ContainsKey("classSettings"));
        }
        public async Task ArchiveTeam()
        {
            CSEntryChange cs = CSEntryChange.Create();

            cs.ObjectType             = "team";
            cs.ObjectModificationType = ObjectModificationType.Add;
            cs.CreateAttributeAdd("displayName", "mytestteam");
            cs.CreateAttributeAdd("owner", UnitTestControl.Users.GetRange(0, 1).Select(t => t.Id).ToList <object>());

            string teamid = await TeamTests.SubmitCSEntryChange(cs);

            cs                        = CSEntryChange.Create();
            cs.ObjectType             = "team";
            cs.ObjectModificationType = ObjectModificationType.Update;
            cs.AnchorAttributes.Add(AnchorAttribute.Create("id", teamid));
            cs.CreateAttributeAdd("isArchived", true);
            await TeamTests.SubmitCSEntryChange(cs);

            var team = await GraphHelperTeams.GetTeam(UnitTestControl.BetaClient, teamid, CancellationToken.None);

            Assert.IsTrue(team.IsArchived ?? false);
        }
        public async Task CreateTeamTestUpdatePermissions()
        {
            CSEntryChange cs = CSEntryChange.Create();

            cs.ObjectType             = "team";
            cs.ObjectModificationType = ObjectModificationType.Add;
            cs.CreateAttributeAdd("displayName", "mytestteam");
            cs.CreateAttributeAdd("owner", UnitTestControl.Users.GetRange(0, 1).Select(t => t.Id).ToList <object>());
            cs.CreateAttributeAdd("memberSettings_allowCreateUpdateChannels", false);
            cs.CreateAttributeAdd("memberSettings_allowDeleteChannels", false);
            cs.CreateAttributeAdd("memberSettings_allowAddRemoveApps", false);
            cs.CreateAttributeAdd("memberSettings_allowCreateUpdateRemoveTabs", false);
            cs.CreateAttributeAdd("memberSettings_allowCreateUpdateRemoveConnectors", false);
            cs.CreateAttributeAdd("guestSettings_allowCreateUpdateChannels", false);
            cs.CreateAttributeAdd("guestSettings_allowDeleteChannels", false);
            cs.CreateAttributeAdd("messagingSettings_allowUserEditMessages", false);
            cs.CreateAttributeAdd("messagingSettings_allowUserDeleteMessages", false);
            cs.CreateAttributeAdd("messagingSettings_allowOwnerDeleteMessages", false);
            cs.CreateAttributeAdd("messagingSettings_allowTeamMentions", false);
            cs.CreateAttributeAdd("messagingSettings_allowChannelMentions", false);
            cs.CreateAttributeAdd("funSettings_allowGiphy", false);
            cs.CreateAttributeAdd("funSettings_giphyContentRating", "Moderate");
            cs.CreateAttributeAdd("funSettings_allowStickersAndMemes", false);
            cs.CreateAttributeAdd("funSettings_allowCustomMemes", false);

            string teamid = await TeamTests.SubmitCSEntryChange(cs);

            var team = await GraphHelperTeams.GetTeam(UnitTestControl.BetaClient, teamid, CancellationToken.None);

            var group = await GraphHelperGroups.GetGroup(UnitTestControl.Client, teamid, CancellationToken.None);

            Assert.AreEqual("mytestteam", group.DisplayName);
            Assert.AreEqual(false, team.MemberSettings.AllowCreateUpdateChannels);
            Assert.AreEqual(false, team.MemberSettings.AllowDeleteChannels);
            Assert.AreEqual(false, team.MemberSettings.AllowAddRemoveApps);
            Assert.AreEqual(false, team.MemberSettings.AllowCreateUpdateRemoveTabs);
            Assert.AreEqual(false, team.MemberSettings.AllowCreateUpdateRemoveConnectors);
            Assert.AreEqual(false, team.GuestSettings.AllowCreateUpdateChannels);
            Assert.AreEqual(false, team.GuestSettings.AllowDeleteChannels);
            Assert.AreEqual(false, team.MessagingSettings.AllowUserEditMessages);
            Assert.AreEqual(false, team.MessagingSettings.AllowUserDeleteMessages);
            Assert.AreEqual(false, team.MessagingSettings.AllowOwnerDeleteMessages);
            Assert.AreEqual(false, team.MessagingSettings.AllowTeamMentions);
            Assert.AreEqual(false, team.MessagingSettings.AllowChannelMentions);
            Assert.AreEqual(false, team.FunSettings.AllowGiphy);
            Assert.AreEqual(GiphyRatingType.Moderate, team.FunSettings.GiphyContentRating);
            Assert.AreEqual(false, team.FunSettings.AllowStickersAndMemes);
            Assert.AreEqual(false, team.FunSettings.AllowCustomMemes);

            cs                        = CSEntryChange.Create();
            cs.ObjectType             = "team";
            cs.ObjectModificationType = ObjectModificationType.Update;
            cs.AnchorAttributes.Add(AnchorAttribute.Create("id", teamid));
            cs.CreateAttributeReplace("memberSettings_allowCreateUpdateChannels", true);
            cs.CreateAttributeReplace("memberSettings_allowDeleteChannels", true);
            cs.CreateAttributeReplace("memberSettings_allowAddRemoveApps", true);
            cs.CreateAttributeReplace("memberSettings_allowCreateUpdateRemoveTabs", true);
            cs.CreateAttributeReplace("memberSettings_allowCreateUpdateRemoveConnectors", true);
            cs.CreateAttributeReplace("guestSettings_allowCreateUpdateChannels", true);
            cs.CreateAttributeReplace("guestSettings_allowDeleteChannels", true);
            cs.CreateAttributeReplace("messagingSettings_allowUserEditMessages", true);
            cs.CreateAttributeReplace("messagingSettings_allowUserDeleteMessages", true);
            cs.CreateAttributeReplace("messagingSettings_allowOwnerDeleteMessages", true);
            cs.CreateAttributeReplace("messagingSettings_allowTeamMentions", true);
            cs.CreateAttributeReplace("messagingSettings_allowChannelMentions", true);
            cs.CreateAttributeReplace("funSettings_allowGiphy", true);
            cs.CreateAttributeReplace("funSettings_giphyContentRating", "Strict");
            cs.CreateAttributeReplace("funSettings_allowStickersAndMemes", true);
            cs.CreateAttributeReplace("funSettings_allowCustomMemes", true);

            await TeamTests.SubmitCSEntryChange(cs);

            team = await GraphHelperTeams.GetTeam(UnitTestControl.BetaClient, teamid, CancellationToken.None);

            Assert.AreEqual(true, team.MemberSettings.AllowCreateUpdateChannels);
            Assert.AreEqual(true, team.MemberSettings.AllowDeleteChannels);
            Assert.AreEqual(true, team.MemberSettings.AllowAddRemoveApps);
            Assert.AreEqual(true, team.MemberSettings.AllowCreateUpdateRemoveTabs);
            Assert.AreEqual(true, team.MemberSettings.AllowCreateUpdateRemoveConnectors);
            Assert.AreEqual(true, team.GuestSettings.AllowCreateUpdateChannels);
            Assert.AreEqual(true, team.GuestSettings.AllowDeleteChannels);
            Assert.AreEqual(true, team.MessagingSettings.AllowUserEditMessages);
            Assert.AreEqual(true, team.MessagingSettings.AllowUserDeleteMessages);
            Assert.AreEqual(true, team.MessagingSettings.AllowOwnerDeleteMessages);
            Assert.AreEqual(true, team.MessagingSettings.AllowTeamMentions);
            Assert.AreEqual(true, team.MessagingSettings.AllowChannelMentions);
            Assert.AreEqual(true, team.FunSettings.AllowGiphy);
            Assert.AreEqual(GiphyRatingType.Strict, team.FunSettings.GiphyContentRating);
            Assert.AreEqual(true, team.FunSettings.AllowStickersAndMemes);
            Assert.AreEqual(true, team.FunSettings.AllowCustomMemes);
        }