Beispiel #1
0
        public void GetDirectoryPublicKeys_ShouldCallTransportWithCorrectParams()
        {
            var mockTransport = new Mock <ITransport>();
            var directoryId   = Guid.NewGuid();

            mockTransport
            .Setup(p => p.OrganizationV3DirectoryKeysListPost(
                       It.Is <DirectoryKeysListPostRequest>(x => x.DirectoryId == directoryId)
                       , TestConsts.DefaultOrganizationEntity))
            .Returns(new KeysListPostResponse(new List <KeysListPostResponse.Key> {
                new KeysListPostResponse.Key
                {
                    Active    = true,
                    Created   = new DateTime(2020, 1, 1),
                    Expires   = new DateTime(2021, 1, 1),
                    Id        = "id",
                    PublicKey = "k"
                }
            }))
            .Verifiable();

            var client = new BasicOrganizationClient(TestConsts.DefaultOrgId, mockTransport.Object);

            var result = client.GetDirectoryPublicKeys(directoryId);

            mockTransport.Verify();

            Assert.IsTrue(result.Count == 1);
            Assert.IsTrue(result[0].Active == true);
            Assert.IsTrue(result[0].Created == new DateTime(2020, 1, 1));
            Assert.IsTrue(result[0].Expires == new DateTime(2021, 1, 1));
            Assert.IsTrue(result[0].Id == "id");
        }
Beispiel #2
0
        public void GetAllDirectorySdkKeys_InteractsWithTransport()
        {
            // setup
            var mock    = new Mock <ITransport>();
            var did     = Guid.NewGuid();
            var sdkKey1 = Guid.NewGuid();
            var sdkKey2 = Guid.NewGuid();
            var orgId   = Guid.NewGuid();

            mock.Setup(p => p.OrganizationV3DirectorySdkKeysListPost(
                           It.Is <OrganizationV3DirectorySdkKeysListPostRequest>(e => e.DirectoryId == did),
                           It.Is <EntityIdentifier>(e => e.Id == orgId && e.Type == EntityType.Organization)
                           ))
            .Returns(new OrganizationV3DirectorySdkKeysListPostResponse(new List <Guid> {
                sdkKey1, sdkKey2
            }))
            .Verifiable();

            // exec
            var client   = new BasicOrganizationClient(orgId, mock.Object);
            var response = client.GetAllDirectorySdkKeys(did);

            // verify
            mock.Verify();
            Assert.IsNotNull(response);
            Assert.IsTrue(response.Count == 2);
            Assert.AreEqual(sdkKey1, response[0]);
            Assert.AreEqual(sdkKey2, response[1]);
        }
Beispiel #3
0
        public void UpdateService_ShouldCallTransportWithCorrectParams()
        {
            var mockTransport = new Mock <ITransport>();
            var callbackUrl   = new Uri("http://example.com");
            var iconUrl       = new Uri("http://example.com/icon");
            var serviceId     = Guid.NewGuid();

            mockTransport.Setup(p =>
                                p.OrganizationV3ServicesPatch(
                                    It.IsAny <ServicesPatchRequest>(),
                                    It.IsAny <EntityIdentifier>()
                                    )
                                );

            var client = new BasicOrganizationClient(TestConsts.DefaultOrgId, mockTransport.Object);

            client.UpdateService(serviceId, "service name", "desc", iconUrl, callbackUrl, true);

            // verify the call made it to transport with right params
            mockTransport.Verify(
                x => x.OrganizationV3ServicesPatch(It.Is <ServicesPatchRequest>(
                                                       p => p.Active == true &&
                                                       p.Name == "service name" &&
                                                       p.Description == "desc" &&
                                                       p.CallbackUrl == callbackUrl &&
                                                       p.Icon == iconUrl &&
                                                       p.ServiceId == serviceId
                                                       ),
                                                   It.IsAny <EntityIdentifier>()), Times.Once());
        }
Beispiel #4
0
        public void GetAllServices_ShouldCallTransportWithCorrectParams()
        {
            var mockTransport = new Mock <ITransport>();
            var callbackUrl   = new Uri("http://example.com");
            var iconUrl       = new Uri("http://example.com/icon");
            var serviceObject = new ServicesGetResponse.Service {
                Active = true, CallbackUrl = callbackUrl, Description = "one service", Name = "my service", Icon = iconUrl, Id = Guid.NewGuid()
            };

            mockTransport.Setup(p => p.OrganizationV3ServicesGet(It.IsAny <EntityIdentifier>()))
            .Returns(new ServicesGetResponse(new List <ServicesGetResponse.Service> {
                serviceObject
            }))
            .Verifiable();

            var client         = new BasicOrganizationClient(TestConsts.DefaultOrgId, mockTransport.Object);
            var responseObject = client.GetAllServices();

            // verify the call made it to transport with right params
            mockTransport.Verify();

            // verify our code translated the objects OK
            Assert.AreEqual(responseObject[0].Active, serviceObject.Active);
            Assert.AreEqual(responseObject[0].CallbackUrl, serviceObject.CallbackUrl);
            Assert.AreEqual(responseObject[0].Description, serviceObject.Description);
            Assert.AreEqual(responseObject[0].Icon, serviceObject.Icon);
            Assert.AreEqual(responseObject[0].Id, serviceObject.Id);
            Assert.AreEqual(responseObject[0].Name, serviceObject.Name);
        }
Beispiel #5
0
        public void CreateService_ShouldCallTransportWithCorrectParams()
        {
            var mockTransport = new Mock <ITransport>();
            var callbackUrl   = new Uri("http://example.com");
            var iconUrl       = new Uri("http://example.com/icon");
            var returnedGuid  = Guid.NewGuid();

            mockTransport.Setup(p =>
                                p.OrganizationV3ServicesPost(
                                    It.IsAny <ServicesPostRequest>(),
                                    It.IsAny <EntityIdentifier>()
                                    )
                                )
            .Returns(new ServicesPostResponse {
                Id = returnedGuid
            });

            var client   = new BasicOrganizationClient(TestConsts.DefaultOrgId, mockTransport.Object);
            var response = client.CreateService("service name", "desc", iconUrl, callbackUrl, true);

            // verify the call made it to transport with right params
            mockTransport.Verify(
                x => x.OrganizationV3ServicesPost(It.Is <ServicesPostRequest>(
                                                      p => p.Active == true &&
                                                      p.Name == "service name" &&
                                                      p.Description == "desc" &&
                                                      p.CallbackUrl == callbackUrl &&
                                                      p.Icon == iconUrl
                                                      ),
                                                  It.IsAny <EntityIdentifier>()), Times.Once());

            // verify result from transport made its way back out
            Assert.AreEqual(returnedGuid, response);
        }
Beispiel #6
0
        public void GetDirectories_ShouldCallTransportWithCorrectParams()
        {
            var mock  = new Mock <ITransport>();
            var did   = Guid.NewGuid();
            var sdkid = Guid.NewGuid();
            var sid   = Guid.NewGuid();

            mock.Setup(
                m => m.OrganizationV3DirectoriesListPost(
                    It.IsAny <OrganizationV3DirectoriesListPostRequest>(),
                    It.IsAny <EntityIdentifier>()
                    ))
            .Returns(new OrganizationV3DirectoriesListPostResponse(new List <OrganizationV3DirectoriesListPostResponse.Directory>
            {
                new OrganizationV3DirectoriesListPostResponse.Directory
                {
                    Active     = true,
                    AndroidKey = "a",
                    Id         = did,
                    IosCertificateFingerprint = "i",
                    Name    = "n",
                    SdkKeys = new List <Guid>
                    {
                        sdkid
                    },
                    ServiceIds = new List <Guid>
                    {
                        sid
                    }
                }
            }));


            var client   = new BasicOrganizationClient(TestConsts.DefaultOrgId, mock.Object);
            var response = client.GetDirectories(new List <Guid>()
            {
                Guid.NewGuid()
            });

            Assert.IsTrue(response != null);
            Assert.IsTrue(response.Count == 1);
            Assert.IsTrue(response[0].Active);
            Assert.IsTrue(response[0].AndroidKey == "a");
            Assert.IsTrue(response[0].IosCertificateFingerprint == "i");
            Assert.IsTrue(response[0].Name == "n");
            Assert.IsTrue(response[0].SdkKeys.Count == 1);
            Assert.IsTrue(response[0].SdkKeys[0] == sdkid);
            Assert.IsTrue(response[0].ServiceIds.Count == 1);
            Assert.IsTrue(response[0].ServiceIds[0] == sid);
        }
Beispiel #7
0
        public void GetService_ShouldCallTransportWithCorrectParams()
        {
            var mockTransport = new Mock <ITransport>();
            var callbackUrl   = new Uri("http://example.com");
            var iconUrl       = new Uri("http://example.com/icon");
            var serviceId     = Guid.NewGuid();
            var serviceObject = new ServicesListPostResponse.Service
            {
                Id          = serviceId,
                Name        = "my name",
                Description = "my description",
                Active      = true,
                CallbackUrl = callbackUrl,
                Icon        = iconUrl
            };

            mockTransport.Setup(p =>
                                p.OrganizationV3ServicesListPost(
                                    It.IsAny <ServicesListPostRequest>(),
                                    It.IsAny <EntityIdentifier>()
                                    )
                                )
            .Returns(new ServicesListPostResponse(new List <ServicesListPostResponse.Service> {
                serviceObject
            }));

            var client         = new BasicOrganizationClient(TestConsts.DefaultOrgId, mockTransport.Object);
            var responseObject = client.GetService(serviceId);

            // verify the call made it to transport with right params
            mockTransport.Verify(
                x => x.OrganizationV3ServicesListPost(It.Is <ServicesListPostRequest>(
                                                          p => p.ServiceIds != null &&
                                                          p.ServiceIds.Count == 1 &&
                                                          p.ServiceIds[0] == serviceId
                                                          ),
                                                      It.IsAny <EntityIdentifier>()), Times.Once());

            // verify our code translated the objects OK
            Assert.AreEqual(responseObject.Active, serviceObject.Active);
            Assert.AreEqual(responseObject.CallbackUrl, serviceObject.CallbackUrl);
            Assert.AreEqual(responseObject.Description, serviceObject.Description);
            Assert.AreEqual(responseObject.Icon, serviceObject.Icon);
            Assert.AreEqual(responseObject.Id, serviceObject.Id);
            Assert.AreEqual(responseObject.Name, serviceObject.Name);
        }
Beispiel #8
0
        public void RemoveDirectorySdkKey_InteractsWithTransport()
        {
            var mock   = new Mock <ITransport>();
            var did    = Guid.NewGuid();
            var orgId  = Guid.NewGuid();
            var sdkKey = Guid.NewGuid();

            mock.Setup(p => p.OrganizationV3DirectorySdkKeysDelete(
                           It.Is <OrganizationV3DirectorySdkKeysDeleteRequest>(e => e.DirectoryId == did && e.SdkKey == sdkKey),
                           It.Is <EntityIdentifier>(e => e.Id == orgId && e.Type == EntityType.Organization)
                           )).Verifiable();

            var client = new BasicOrganizationClient(orgId, mock.Object);

            client.RemoveDirectorySdkKey(did, sdkKey);

            mock.Verify();
        }
Beispiel #9
0
        public void CreateDirectory_ShouldCallTransportWithCorrectParams()
        {
            var mockTransport = new Mock <ITransport>();
            var returnedId    = Guid.NewGuid();

            mockTransport.Setup(p =>
                                p.OrganizationV3DirectoriesPost(
                                    It.Is <OrganizationV3DirectoriesPostRequest>(x => x.Name == "x"),
                                    It.IsAny <EntityIdentifier>()))
            .Returns(new OrganizationV3DirectoriesPostResponse {
                Id = returnedId
            })
            .Verifiable();

            var client   = new BasicOrganizationClient(TestConsts.DefaultOrgId, mockTransport.Object);
            var response = client.CreateDirectory("x");

            Assert.AreEqual(returnedId, response);
        }
Beispiel #10
0
        public void RemoveDirectoryPublicKey_ShouldCallTransportWithCorrectParams()
        {
            var mockTransport = new Mock <ITransport>();
            var directoryId   = Guid.NewGuid();

            mockTransport
            .Setup(p => p.OrganizationV3DirectoryKeysDelete(
                       It.Is <DirectoryKeysDeleteRequest>(x =>
                                                          x.KeyId == "keyid" &&
                                                          x.DirectoryId == directoryId
                                                          ),
                       TestConsts.DefaultOrganizationEntity
                       )).Verifiable();

            var client = new BasicOrganizationClient(TestConsts.DefaultOrgId, mockTransport.Object);

            client.RemoveDirectoryPublicKey(directoryId, "keyid");

            mockTransport.Verify();
        }
Beispiel #11
0
        public void UpdateDirectory_ShouldCallTransportWithCorrectParams()
        {
            var mock = new Mock <ITransport>();

            mock.Setup(p =>
                       p.OrganizationV3DirectoriesPatch(
                           It.Is <OrganizationV3DirectoriesPatchRequest>(
                               x => x.Active == true &&
                               x.AndroidKey == "a" &&
                               x.IosP12 == "i" &&
                               x.DirectoryId == TestConsts.DefaultDirectoryId
                               ),
                           It.IsAny <EntityIdentifier>()))
            .Verifiable();

            var client = new BasicOrganizationClient(TestConsts.DefaultOrgId, mock.Object);

            client.UpdateDirectory(TestConsts.DefaultDirectoryId, true, "a", "i", true, TestConsts.DefaultWebhookUrl);
            mock.Verify();
        }
Beispiel #12
0
        public void UpdateDirectoryPublicKey_ShouldCallTransportWithCorrectParams()
        {
            var mockTransport = new Mock <ITransport>();
            var directoryId   = Guid.NewGuid();

            mockTransport
            .Setup(p => p.OrganizationV3DirectoryKeysPatch(
                       It.Is <DirectoryKeysPatchRequest>(x =>
                                                         x.Active == true &&
                                                         x.Expires == new DateTime(2020, 1, 1).ToUniversalTime() &&
                                                         x.KeyId == "keyid" &&
                                                         x.DirectoryId == directoryId
                                                         ),
                       TestConsts.DefaultOrganizationEntity
                       )).Verifiable();

            var client = new BasicOrganizationClient(TestConsts.DefaultOrgId, mockTransport.Object);

            client.UpdateDirectoryPublicKey(directoryId, "keyid", true, new DateTime(2020, 1, 1));

            mockTransport.Verify();
        }
Beispiel #13
0
        public void AddDirectoryPublicKey_ShouldCallTransportWithCorrectParams()
        {
            var mockTransport = new Mock <ITransport>();
            var directoryId   = Guid.NewGuid();

            mockTransport
            .Setup(p => p.OrganizationV3DirectoryKeysPost(It.Is <DirectoryKeysPostRequest>(x =>
                                                                                           x.Active == true &&
                                                                                           x.Expires == new DateTime(2020, 1, 1).ToUniversalTime() &&
                                                                                           x.PublicKey == "keyhere" &&
                                                                                           x.DirectoryId == directoryId), It.IsAny <EntityIdentifier>()))
            .Returns(new KeysPostResponse {
                Id = "keyid"
            })
            .Verifiable();

            var client = new BasicOrganizationClient(TestConsts.DefaultOrgId, mockTransport.Object);

            var response = client.AddDirectoryPublicKey(directoryId, "keyhere", true, new DateTime(2020, 1, 1));

            mockTransport.Verify();

            Assert.IsTrue(response == "keyid");
        }
Beispiel #14
0
        public void GenerateAndAddDirectorySdkKey_InteractsWithTransport()
        {
            var mock   = new Mock <ITransport>();
            var did    = Guid.NewGuid();
            var orgId  = Guid.NewGuid();
            var sdkKey = Guid.NewGuid();

            mock.Setup(
                m => m.OrganizationV3DirectorySdkKeysPost(
                    It.IsAny <OrganizationV3DirectorySdkKeysPostRequest>(),
                    It.IsAny <EntityIdentifier>()
                    )
                )
            .Returns(new OrganizationV3DirectorySdkKeysPostResponse {
                SdkKey = sdkKey
            })
            .Verifiable();

            var client   = new BasicOrganizationClient(orgId, mock.Object);
            var response = client.GenerateAndAddDirectorySdkKey(did);

            mock.Verify();
            Assert.AreEqual(sdkKey, response);
        }