Esempio n. 1
0
        public void MoreThanOneNestedObject_DeserializerThrows()
        {
            CommunicationIdentifierModel[] modelsWithTooManyNestedObjects = new[]
            {
                new CommunicationIdentifierModel
                {
                    RawId             = TestRawId,
                    CommunicationUser = new CommunicationUserIdentifierModel(TestUserId),
                    PhoneNumber       = new PhoneNumberIdentifierModel(TestPhoneNumber),
                },
                new CommunicationIdentifierModel
                {
                    RawId              = TestRawId,
                    CommunicationUser  = new CommunicationUserIdentifierModel(TestUserId),
                    MicrosoftTeamsUser = new MicrosoftTeamsUserIdentifierModel(TestTeamsUserId, isAnonymous: true, CommunicationCloudEnvironmentModel.Public),
                },
                new CommunicationIdentifierModel
                {
                    RawId              = TestRawId,
                    PhoneNumber        = new PhoneNumberIdentifierModel(TestPhoneNumber),
                    MicrosoftTeamsUser = new MicrosoftTeamsUserIdentifierModel(TestTeamsUserId, isAnonymous: true, CommunicationCloudEnvironmentModel.Public),
                },
            };

            foreach (CommunicationIdentifierModel item in modelsWithTooManyNestedObjects)
            {
                Assert.Throws <JsonException>(() => CommunicationIdentifierSerializer.Deserialize(item));
            }
        }
Esempio n. 2
0
        public void MissingProperty_DeserializerThrows()
        {
            CommunicationIdentifierModel[] modelsWithMissingMandatoryProperty = new[]
            {
                new CommunicationIdentifierModel(CommunicationIdentifierKind.Unknown),            // Missing Id
                new CommunicationIdentifierModel(CommunicationIdentifierKind.CommunicationUser),  // Missing Id
                new CommunicationIdentifierModel(CommunicationIdentifierKind.CallingApplication), // Missing Id
                new CommunicationIdentifierModel(CommunicationIdentifierKind.PhoneNumber)
                {
                    Id = "some id"
                },                                                                                            // Missing PhoneNumber
                new CommunicationIdentifierModel(CommunicationIdentifierKind.MicrosoftTeamsUser)
                {
                    Id = "some id", MicrosoftTeamsUserId = "some id"
                },                                                                                                                                     // Missing IsAnonymous
                new CommunicationIdentifierModel(CommunicationIdentifierKind.MicrosoftTeamsUser)
                {
                    Id = "some id", IsAnonymous = true
                },                                                                                                                       // Missing MicrosoftTeamsUserId
            };

            foreach (CommunicationIdentifierModel item in modelsWithMissingMandatoryProperty)
            {
                Assert.Throws <JsonException>(() => CommunicationIdentifierSerializer.Deserialize(item));
            }
        }
Esempio n. 3
0
        public void MissingProperty_DeserializerThrows()
        {
            CommunicationIdentifierModel[] modelsWithMissingMandatoryProperty = new[]
            {
                new CommunicationIdentifierModel(), // Missing RawId
                new CommunicationIdentifierModel {
                    CommunicationUser = new CommunicationUserIdentifierModel()
                },                                                                                               // Missing Id
                new CommunicationIdentifierModel {
                    PhoneNumber = new PhoneNumberIdentifierModel(), RawId = TestRawId
                },                                                                                                      // Missing PhoneNumber
                new CommunicationIdentifierModel {
                    RawId = TestRawId, MicrosoftTeamsUser = new MicrosoftTeamsUserIdentifierModel {
                        UserId = TestTeamsUserId, Cloud = CommunicationCloudEnvironmentModel.Public
                    }
                },                                                                                                                                                                                                  // Missing IsAnonymous
                new CommunicationIdentifierModel {
                    RawId = TestRawId, MicrosoftTeamsUser = new MicrosoftTeamsUserIdentifierModel {
                        IsAnonymous = true, Cloud = CommunicationCloudEnvironmentModel.Public
                    }
                },                                                                                                                                                                                            // Missing UserId
                new CommunicationIdentifierModel {
                    RawId = TestRawId, MicrosoftTeamsUser = new MicrosoftTeamsUserIdentifierModel {
                        UserId = TestTeamsUserId, IsAnonymous = true,
                    }
                },                                                                                                                                                                    // Missing Cloud
            };

            foreach (CommunicationIdentifierModel item in modelsWithMissingMandatoryProperty)
            {
                Assert.Throws <JsonException>(() => CommunicationIdentifierSerializer.Deserialize(item));
            }
        }
Esempio n. 4
0
        public void DeserializeUnknown()
        {
            UnknownIdentifier identifier = (UnknownIdentifier)CommunicationIdentifierSerializer.Deserialize(
                new CommunicationIdentifierModel
            {
                RawId = TestRawId,
            });
            UnknownIdentifier expectedIdentifier = new UnknownIdentifier(TestRawId);

            Assert.AreEqual(expectedIdentifier.Id, identifier.Id);
            Assert.AreEqual(expectedIdentifier, identifier);
        }
Esempio n. 5
0
        public void DeserializeCommunicationUser()
        {
            CommunicationUserIdentifier identifier = (CommunicationUserIdentifier)CommunicationIdentifierSerializer.Deserialize(
                new CommunicationIdentifierModel(CommunicationIdentifierKind.CommunicationUser)
            {
                Id = "some id",
            });

            CommunicationUserIdentifier expectedIdentifier = new CommunicationUserIdentifier("some id");

            Assert.AreEqual(expectedIdentifier.Id, identifier.Id);
            Assert.AreEqual(expectedIdentifier, identifier);
        }
Esempio n. 6
0
        public void DeserializeCommunicationUser()
        {
            CommunicationUserIdentifier identifier = (CommunicationUserIdentifier)CommunicationIdentifierSerializer.Deserialize(
                new CommunicationIdentifierModel
            {
                CommunicationUser = new CommunicationUserIdentifierModel(TestUserId),
                RawId             = TestRawId,
            });

            CommunicationUserIdentifier expectedIdentifier = new CommunicationUserIdentifier(TestUserId);

            Assert.AreEqual(expectedIdentifier.Id, identifier.Id);
            Assert.AreEqual(expectedIdentifier, identifier);
        }
Esempio n. 7
0
        public void DeserializePhoneNumber()
        {
            PhoneNumberIdentifier identifier = (PhoneNumberIdentifier)CommunicationIdentifierSerializer.Deserialize(
                new CommunicationIdentifierModel
            {
                PhoneNumber = new PhoneNumberIdentifierModel(TestPhoneNumber),
                RawId       = TestRawId,
            });

            PhoneNumberIdentifier expectedIdentifier = new PhoneNumberIdentifier(TestPhoneNumber, TestRawId);

            Assert.AreEqual(expectedIdentifier.PhoneNumber, identifier.PhoneNumber);
            Assert.AreEqual(expectedIdentifier.RawId, identifier.RawId);
            Assert.AreEqual(expectedIdentifier, identifier);
        }
Esempio n. 8
0
        public void DeserializeUnknown()
        {
            AssertCorrectness(
                new UnknownIdentifier("some id"),
                CommunicationIdentifierSerializer.Deserialize(
                    new CommunicationIdentifierModel(CommunicationIdentifierKind.Unknown)
            {
                Id = "some id",
            }));

            AssertCorrectness(
                new UnknownIdentifier("some id"),
                CommunicationIdentifierSerializer.Deserialize(
                    new CommunicationIdentifierModel(new CommunicationIdentifierKind("Some Future Type"))
            {
                Id = "some id",
            }));
Esempio n. 9
0
        public void DeserializeMicrosoftTeamsUser(bool isAnonymous)
        {
            MicrosoftTeamsUserIdentifier identifier = (MicrosoftTeamsUserIdentifier)CommunicationIdentifierSerializer.Deserialize(
                new CommunicationIdentifierModel
            {
                MicrosoftTeamsUser = new MicrosoftTeamsUserIdentifierModel(TestTeamsUserId)
                {
                    IsAnonymous = isAnonymous,
                    Cloud       = TestTeamsCloud,
                },
                RawId = TestRawId,
            });

            MicrosoftTeamsUserIdentifier expectedIdentifier = new MicrosoftTeamsUserIdentifier(TestTeamsUserId, isAnonymous, CommunicationCloudEnvironment.Gcch, TestRawId);

            Assert.AreEqual(expectedIdentifier.UserId, identifier.UserId);
            Assert.AreEqual(expectedIdentifier.IsAnonymous, identifier.IsAnonymous);
            Assert.AreEqual(expectedIdentifier.Cloud, identifier.Cloud);
            Assert.AreEqual(expectedIdentifier.RawId, identifier.RawId);
            Assert.AreEqual(expectedIdentifier, identifier);
        }