Example #1
0
        public void SerializePhoneNumber(string?expectedRawId)
        {
            CommunicationIdentifierModel model = CommunicationIdentifierSerializer.Serialize(new PhoneNumberIdentifier(TestPhoneNumber, expectedRawId));

            Assert.AreEqual(TestPhoneNumber, model.PhoneNumber.Value);
            Assert.AreEqual(expectedRawId, model.RawId);
        }
Example #2
0
        public static CommunicationIdentifier Deserialize(CommunicationIdentifierModel identifier)
        {
            string rawId = AssertNotNull(identifier.RawId, nameof(identifier.RawId), nameof(CommunicationIdentifierModel));

            AssertMaximumOneNestedModel(identifier);

            if (identifier.CommunicationUser is CommunicationUserIdentifierModel user)
            {
                return(new CommunicationUserIdentifier(AssertNotNull(user.Id, nameof(user.Id), nameof(CommunicationUserIdentifierModel))));
            }

            if (identifier.PhoneNumber is PhoneNumberIdentifierModel phoneNumber)
            {
                return(new PhoneNumberIdentifier(
                           AssertNotNull(phoneNumber.Value, nameof(phoneNumber.Value), nameof(PhoneNumberIdentifierModel)),
                           AssertNotNull(identifier.RawId, nameof(identifier.RawId), nameof(PhoneNumberIdentifierModel))));
            }

            if (identifier.MicrosoftTeamsUser is MicrosoftTeamsUserIdentifierModel teamsUser)
            {
                return(new MicrosoftTeamsUserIdentifier(
                           AssertNotNull(teamsUser.UserId, nameof(teamsUser.UserId), nameof(MicrosoftTeamsUserIdentifierModel)),
                           AssertNotNull(teamsUser.IsAnonymous, nameof(teamsUser.IsAnonymous), nameof(MicrosoftTeamsUserIdentifierModel)),
                           Deserialize(AssertNotNull(teamsUser.Cloud, nameof(teamsUser.Cloud), nameof(MicrosoftTeamsUserIdentifierModel))),
                           rawId));
            }

            return(new UnknownIdentifier(rawId));
        public static CommunicationIdentifier Deserialize(CommunicationIdentifierModel identifier)
        {
            var id   = identifier.Id;
            var kind = identifier.Kind;

            if (kind == CommunicationIdentifierKind.CommunicationUser)
            {
                return(new CommunicationUserIdentifier(AssertNotNull(id, nameof(identifier.Id), kind)));
            }
            if (kind == CommunicationIdentifierKind.CallingApplication)
            {
                return(new CallingApplicationIdentifier(AssertNotNull(id, nameof(identifier.Id), kind)));
            }
            if (kind == CommunicationIdentifierKind.PhoneNumber)
            {
                return(new PhoneNumberIdentifier(AssertNotNull(identifier.PhoneNumber, nameof(identifier.PhoneNumber), kind)));
            }
            if (kind == CommunicationIdentifierKind.MicrosoftTeamsUser)
            {
                return(new MicrosoftTeamsUserIdentifier(
                           AssertNotNull(identifier.MicrosoftTeamsUserId, nameof(identifier.MicrosoftTeamsUserId), kind),
                           AssertNotNull(identifier.IsAnonymous, nameof(identifier.IsAnonymous), kind)));
            }

            return(new UnknownIdentifier(AssertNotNull(id, nameof(identifier.Id), kind)));
        }
Example #4
0
        public void SerializeUnknown()
        {
            CommunicationIdentifierModel model = CommunicationIdentifierSerializer.Serialize(new UnknownIdentifier("some id"));

            Assert.AreEqual(CommunicationIdentifierKind.Unknown, model.Kind);
            Assert.AreEqual("some id", model.Id);
        }
Example #5
0
        public void SerializeCommunicationUser()
        {
            CommunicationIdentifierModel model = CommunicationIdentifierSerializer.Serialize(new CommunicationUserIdentifier("some id"));

            Assert.AreEqual(CommunicationIdentifierKind.CommunicationUser, model.Kind);
            Assert.AreEqual("some id", model.Id);
        }
Example #6
0
        public void SerializeMicrosoftTeamsUser(bool isAnonymous, string?expectedRawId)
        {
            CommunicationIdentifierModel model = CommunicationIdentifierSerializer.Serialize(new MicrosoftTeamsUserIdentifier(TestTeamsUserId, isAnonymous, CommunicationCloudEnvironment.Dod, expectedRawId));

            Assert.AreEqual(TestTeamsUserId, model.MicrosoftTeamsUser.UserId);
            Assert.AreEqual(CommunicationCloudEnvironmentModel.Dod, model.MicrosoftTeamsUser.Cloud);
            Assert.AreEqual(isAnonymous, model.MicrosoftTeamsUser.IsAnonymous);
            Assert.AreEqual(expectedRawId, model.RawId);
        }
Example #7
0
            static void AssertMaximumOneNestedModel(CommunicationIdentifierModel identifier)
            {
                List <string> presentProperties = new List <string>();

                if (identifier.CommunicationUser is not null)
                {
                    presentProperties.Add(nameof(identifier.CommunicationUser));
                }
                if (identifier.PhoneNumber is not null)
                {
                    presentProperties.Add(nameof(identifier.PhoneNumber));
                }
                if (identifier.MicrosoftTeamsUser is not null)
                {
                    presentProperties.Add(nameof(identifier.MicrosoftTeamsUser));
                }

                if (presentProperties.Count > 1)
                {
                    throw new JsonException($"Only one of the properties in {{{string.Join(", ", presentProperties)}}} should be present.");
                }
            }
Example #8
0
        public void SerializeUnknown()
        {
            CommunicationIdentifierModel model = CommunicationIdentifierSerializer.Serialize(new UnknownIdentifier(TestRawId));

            Assert.AreEqual(TestRawId, model.RawId);
        }
Example #9
0
        public void SerializeCommunicationUser()
        {
            CommunicationIdentifierModel model = CommunicationIdentifierSerializer.Serialize(new CommunicationUserIdentifier(TestUserId));

            Assert.AreEqual(TestUserId, model.CommunicationUser.Id);
        }