Example #1
0
        private void Initialize()
        {
            var environmentFactory = EnvironmentFactoryFactory.Create();

            _authenticationContext  = Substitute.For <IAuthenticationContext>();
            _messagingServiceClient = Substitute.For <IMessagingServiceClient>();

            var userOperations    = environmentFactory.ManagementEnvironment.MgmtUserOperations;
            var companyOperations = environmentFactory.ManagementEnvironment.MgmtCompanyOperations;
            var settingProvider   = new SettingProvider(environmentFactory.ManagementEnvironment.MgmtSettingOperations);

            var userService = new UserService(userOperations, _authenticationContext, settingProvider, null);

            _userId = userService.Register(new RegisterDto()
            {
                Name = "user", Email = EmailHelper.Generate(), Password = "******"
            }, null);

            _companyService = new CompanyService(companyOperations, _authenticationContext, null, new CapabilityProvider(settingProvider));

            _authenticationContext.GetContextUser().Returns(_userId);

            _companyId = _companyService.Create("new company");

            var serviceOperations = environmentFactory.ManagementEnvironment.MgmtServiceOperations;

            _serviceService = new ServiceService(serviceOperations, companyOperations, _authenticationContext, null, new CapabilityProvider(settingProvider));
            _serviceId      = _serviceService.Create(new ServiceDto()
            {
                CompanyId = _companyId, Name = "new service"
            });

            var networkOperations = environmentFactory.ManagementEnvironment.MgmtNetworkOperations;

            _networkService = new NetworkService(networkOperations, serviceOperations, companyOperations, _authenticationContext, null);

            var network = new NetworkDto()
            {
                Name            = "new network",
                ParentNetworkId = null,
                CompanyId       = _companyId,
                ServiceId       = _serviceId
            };

            _networkId = _networkService.Create(network);

            _messagingServiceClient.Initialize("1234").ReturnsForAnyArgs(1);

            var deviceOperations = environmentFactory.ManagementEnvironment.MgmtDeviceOperations;

            _deviceService = new DeviceService(deviceOperations, networkOperations, serviceOperations, companyOperations,
                                               _authenticationContext, _messagingServiceClient);
        }
Example #2
0
        public void GetNetworkUnderServiceTest()
        {
            var environmentFactory = EnvironmentFactoryFactory.Create();
            var networkOperations  = environmentFactory.ManagementEnvironment.MgmtNetworkOperations;

            var companyServiceIdPair = CreateCompanyAndService();

            var network1 = new Network()
            {
                Service = new Service()
                {
                    Id = companyServiceIdPair.ServiceId
                },
                Company = new Company()
                {
                    Id = companyServiceIdPair.CompanyId
                },
                Name       = "new network1",
                NetworkKey = Crypto.GenerateSafeRandomToken()
            };
            var network2 = new Network()
            {
                Service = new Service()
                {
                    Id = companyServiceIdPair.ServiceId
                },
                Company = new Company()
                {
                    Id = companyServiceIdPair.CompanyId
                },
                Name       = "new network2",
                NetworkKey = Crypto.GenerateSafeRandomToken()
            };

            var network1Id = networkOperations.Create(network1);
            var network2Id = networkOperations.Create(network2);

            var dg1 = networkOperations.Get(network1Id);
            var dg2 = networkOperations.Get(network2Id);

            Assert.AreEqual(network1Id, dg1.Id);
            Assert.AreEqual(network1.Name, dg1.Name);
            Assert.AreEqual(companyServiceIdPair.CompanyId, dg1.Company.Id);
            Assert.AreEqual(companyServiceIdPair.ServiceId, dg1.Service.Id);
            Assert.AreEqual(network1.NetworkKey, dg1.NetworkKey);
            Assert.IsNull(dg1.ParentNetwork);
            Assert.AreEqual(network2Id, dg2.Id);
            Assert.AreEqual(network2.Name, dg2.Name);
            Assert.AreEqual(companyServiceIdPair.CompanyId, dg2.Company.Id);
            Assert.AreEqual(companyServiceIdPair.ServiceId, dg2.Service.Id);
            Assert.AreEqual(network2.NetworkKey, dg2.NetworkKey);
            Assert.IsNull(dg2.ParentNetwork);
        }
Example #3
0
        public void TryCreateNetworkUnderOtherNetworkTest()
        {
            var environmentFactory    = EnvironmentFactoryFactory.Create();
            var authenticationContext = Substitute.For <IAuthenticationContext>();

            var userOperations    = environmentFactory.ManagementEnvironment.MgmtUserOperations;
            var companyOperations = environmentFactory.ManagementEnvironment.MgmtCompanyOperations;
            var settingProvider   = new SettingProvider(environmentFactory.ManagementEnvironment.MgmtSettingOperations);
            var userService       = new UserService(userOperations, authenticationContext, settingProvider, null);

            var userId1 = userService.Register(new RegisterDto()
            {
                Name = "user", Email = EmailHelper.Generate(), Password = "******"
            }, null);

            var companyService = new CompanyService(companyOperations, authenticationContext, null, new CapabilityProvider(settingProvider));

            authenticationContext.GetContextUser().Returns(userId1);

            var companyId1 = companyService.Create("new company1");

            var serviceOperations = environmentFactory.ManagementEnvironment.MgmtServiceOperations;
            var serviceService    = new ServiceService(serviceOperations, companyOperations, authenticationContext, null, new CapabilityProvider(settingProvider));

            var serviceId1 = serviceService.Create(new ServiceDto {
                CompanyId = companyId1, Name = "svc"
            });

            var companyId2 = companyService.Create("new company2");

            var serviceId2 = serviceService.Create(new ServiceDto()
            {
                CompanyId = companyId2, Name = "svc"
            });

            var networkOperations = environmentFactory.ManagementEnvironment.MgmtNetworkOperations;
            var networkService    = new NetworkService(networkOperations, serviceOperations, companyOperations, authenticationContext, null);

            var networkId2 = networkService.Create(new NetworkDto()
            {
                ServiceId = serviceId2, CompanyId = companyId2, Name = "svc"
            });

            var network = new NetworkDto()
            {
                ParentNetworkId = networkId2,
                CompanyId       = companyId1,
                ServiceId       = serviceId1,
                Name            = "test"
            };

            networkService.Create(network);
        }
Example #4
0
        public void LoginFailed2Test()
        {
            var environmentFactory    = EnvironmentFactoryFactory.Create();
            var authenticationContext = Substitute.For <IAuthenticationContext>();

            var settingProvider = new SettingProvider(environmentFactory.ManagementEnvironment.MgmtSettingOperations);
            var userOperations  = environmentFactory.ManagementEnvironment.MgmtUserOperations;

            var userService = new UserService(userOperations, authenticationContext, settingProvider, null);

            userService.Login("*****@*****.**", "password2");
        }
Example #5
0
        public void GetMeNotAuthTest()
        {
            var environmentFactory    = EnvironmentFactoryFactory.Create();
            var authenticationContext = Substitute.For <IAuthenticationContext>();

            var userOperations = environmentFactory.ManagementEnvironment.MgmtUserOperations;

            var userService = new UserService(userOperations, authenticationContext, null, null);

            authenticationContext.GetContextUser().Returns((string)null);

            userService.GetMe();
        }
Example #6
0
        public static void AssemblyInitFunction(TestContext context)
        {
            EnvironmentFactoryFactory.Initialize(context.Properties);

            AssemblyResolver.Initialize();
            DtoMapper.Setup();

            var environmentFactory = EnvironmentFactoryFactory.Create();

            if (environmentFactory.TelemetryEnvironment.DataSinkCurrent != null)
            {
                SettingInitializer.Init();
            }
        }
Example #7
0
        public void ListNetworkUnderServiceTest()
        {
            var environmentFactory = EnvironmentFactoryFactory.Create();
            var serviceOperations  = environmentFactory.ManagementEnvironment.MgmtServiceOperations;
            var networkOperations  = environmentFactory.ManagementEnvironment.MgmtNetworkOperations;

            var companyServiceIdPair = CreateCompanyAndService();

            var network1 = new Network()
            {
                Service = new Service()
                {
                    Id = companyServiceIdPair.ServiceId
                },
                Company = new Company()
                {
                    Id = companyServiceIdPair.CompanyId
                },
                Name       = "new network1",
                NetworkKey = Crypto.GenerateSafeRandomToken()
            };
            var network2 = new Network()
            {
                Service = new Service()
                {
                    Id = companyServiceIdPair.ServiceId
                },
                Company = new Company()
                {
                    Id = companyServiceIdPair.CompanyId
                },
                Name       = "new network2",
                NetworkKey = Crypto.GenerateSafeRandomToken()
            };

            var network1Id = networkOperations.Create(network1);
            var network2Id = networkOperations.Create(network2);

            var networks = serviceOperations.ListNetworks(companyServiceIdPair.ServiceId);

            Assert.AreEqual(2, networks.Count);

            var dg1 = networks.Single(d => d.Id == network1Id);
            var dg2 = networks.Single(d => d.Id == network2Id);

            Assert.AreEqual(network1Id, dg1.Id);
            Assert.AreEqual(network1.Name, dg1.Name);
            Assert.AreEqual(network2Id, dg2.Id);
            Assert.AreEqual(network2.Name, dg2.Name);
        }
Example #8
0
        protected IDictionary <string, string> GetCurrentDataSettings()
        {
            var telemetryEnvrionment = EnvironmentFactoryFactory.Create().TelemetryEnvironment;

            var result = new Dictionary <string, string>
            {
                { telemetryEnvrionment.ConnectionStringParamName, telemetryEnvrionment.ConnectionString },
                { "Table", "CurrentData" }
            };

            PrepareAdditionalValues(telemetryEnvrionment, result);

            return(result);
        }
Example #9
0
        public void CreateTest()
        {
            var environmentFactory = EnvironmentFactoryFactory.Create();
            var userOperations     = environmentFactory.ManagementEnvironment.MgmtUserOperations;

            var salt         = Crypto.GenerateSalt();
            var passwordHash = Crypto.CalcualteHash("password", salt);
            var id           = userOperations.Create(new User()
            {
                Name = "new user", Email = EmailHelper.Generate()
            }, passwordHash, salt);

            Assert.AreEqual(32, id.Length);
        }
Example #10
0
        public void RecordOutgoingMessageRealTest()
        {
            var environmentFactory  = EnvironmentFactoryFactory.Create();
            var pltDeviceOperations = environmentFactory.ManagementEnvironment.ObjDeviceOperations;

            MessagingWorkers.Start(new TestBatchParameters(), environmentFactory.MessagingEnvironment.MessagingServiceClient);

            var messagingService = new MessagingService(new MessagingOperations(), pltDeviceOperations);

            var success = messagingService.RecordOutgoingMessage(_deviceId, _deviceId, "32412341243");

            Assert.AreEqual(OutgoingState.Ok, success);

            MessagingWorkers.Stop();
        }
Example #11
0
        public void ChangePasswordNotLoggedInTest()
        {
            var environmentFactory    = EnvironmentFactoryFactory.Create();
            var authenticationContext = Substitute.For <IAuthenticationContext>();

            var userOperations  = environmentFactory.ManagementEnvironment.MgmtUserOperations;
            var settingProvider = new SettingProvider(environmentFactory.ManagementEnvironment.MgmtSettingOperations);

            var userService = new UserService(userOperations, authenticationContext, settingProvider, null);

            authenticationContext.GetContextUser().Returns((string)null);

            userService.ChangePassword(new ChangePasswordDto {
                CurrentPassword = "******", NewPassword = "******"
            });
        }
Example #12
0
        public void UpdateCompany2Test()
        {
            var environmentFactory = EnvironmentFactoryFactory.Create();
            var userOperations     = environmentFactory.ManagementEnvironment.MgmtUserOperations;
            var companyOperations  = environmentFactory.ManagementEnvironment.MgmtCompanyOperations;

            var salt         = Crypto.GenerateSalt();
            var passwordHash = Crypto.CalcualteHash("password", salt);
            var userId       = userOperations.Create(new User()
            {
                Name = "new user", Email = EmailHelper.Generate()
            }, passwordHash, salt);

            var company = new Company {
                Name = "new company"
            };

            var companyId = companyOperations.Create(company, userId);

            var newCompany = companyOperations.Get(companyId);

            newCompany.TelemetryDataSinkSettings = new TelemetryDataSinkSettings()
            {
                Incoming =
                    new List <TelemetryDataSinkParameters>
                {
                    new TelemetryDataSinkParameters
                    {
                        SinkName   = "test",
                        Parameters = new Dictionary <string, string> {
                            { "k1", "v1" }, { "k2", "v2" }
                        }
                    }
                }
            };

            companyOperations.Update(newCompany);

            var updatedCompany = companyOperations.Get(companyId);
            var users          = companyOperations.ListUsers(companyId);

            Assert.AreEqual("new company", updatedCompany.Name);
            Assert.AreEqual(1, updatedCompany.TelemetryDataSinkSettings.Incoming.Count());
            Assert.AreEqual("test", updatedCompany.TelemetryDataSinkSettings.Incoming.First().SinkName);
            Assert.AreEqual(2, updatedCompany.TelemetryDataSinkSettings.Incoming.First().Parameters.Count);
            Assert.AreEqual(1, users.Count);
        }
Example #13
0
        public void UpdateNetworkUnderService2Test()
        {
            var environmentFactory = EnvironmentFactoryFactory.Create();
            var networkOperations  = environmentFactory.ManagementEnvironment.MgmtNetworkOperations;

            var companyServiceIdPair = CreateCompanyAndService();

            var id =
                networkOperations.Create(new Network()
            {
                Service = new Service()
                {
                    Id = companyServiceIdPair.ServiceId
                },
                Company = new Company()
                {
                    Id = companyServiceIdPair.CompanyId
                },
                Name       = "new network",
                NetworkKey = Crypto.GenerateSafeRandomToken()
            });

            var newnetwork = networkOperations.Get(id);

            newnetwork.TelemetryDataSinkSettings = new TelemetryDataSinkSettings()
            {
                Incoming =
                    new List <TelemetryDataSinkParameters>
                {
                    new TelemetryDataSinkParameters
                    {
                        SinkName   = "test",
                        Parameters = new Dictionary <string, string> {
                            { "k1", "v1" }, { "k2", "v2" }
                        }
                    }
                }
            };
            networkOperations.Update(newnetwork);

            var updatednetwork = networkOperations.Get(id);

            Assert.AreEqual("new network", updatednetwork.Name);
            Assert.AreEqual(1, updatednetwork.TelemetryDataSinkSettings.Incoming.Count());
            Assert.AreEqual("test", updatednetwork.TelemetryDataSinkSettings.Incoming.First().SinkName);
            Assert.AreEqual(2, updatednetwork.TelemetryDataSinkSettings.Incoming.First().Parameters.Count);
        }
Example #14
0
        private CompanyServiceNetworkIds CreateCompanyAndServiceAndNetwork()
        {
            var environmentFactory = EnvironmentFactoryFactory.Create();
            var userOperations     = environmentFactory.ManagementEnvironment.MgmtUserOperations;
            var companyOperations  = environmentFactory.ManagementEnvironment.MgmtCompanyOperations;
            var serviceOperations  = environmentFactory.ManagementEnvironment.MgmtServiceOperations;
            var networkOperations  = environmentFactory.ManagementEnvironment.MgmtNetworkOperations;

            var salt         = Crypto.GenerateSalt();
            var passwordHash = Crypto.CalcualteHash("password", salt);
            var userId       = userOperations.Create(new User()
            {
                Name = "new user", Email = EmailHelper.Generate()
            }, passwordHash, salt);

            var company = new Company {
                Name = "new company"
            };
            var companyId = companyOperations.Create(company, userId);

            var service = new Service {
                Company = new Company {
                    Id = companyId
                }, Name = "new service", ApiKey = Crypto.GenerateSafeRandomToken()
            };
            var serviceId = serviceOperations.Create(service);

            var networkId =
                networkOperations.Create(new Network()
            {
                Service = new Service()
                {
                    Id = serviceId
                },
                Company = new Company()
                {
                    Id = companyId
                },
                Name       = "new network",
                NetworkKey = Crypto.GenerateSafeRandomToken()
            });

            return(new CompanyServiceNetworkIds {
                CompanyId = companyId, ServiceId = serviceId, NetworkId = networkId
            });
        }
Example #15
0
        public void IsExistsTest()
        {
            var environmentFactory = EnvironmentFactoryFactory.Create();
            var userOperations     = environmentFactory.ManagementEnvironment.MgmtUserOperations;

            var email = EmailHelper.Generate();

            var salt         = Crypto.GenerateSalt();
            var passwordHash = Crypto.CalcualteHash("password", salt);

            userOperations.Create(new User()
            {
                Name = "new user", Email = email
            }, passwordHash, salt);

            Assert.IsTrue(userOperations.IsExists(email));
        }
Example #16
0
        public void CreateServiceTest()
        {
            var environmentFactory = EnvironmentFactoryFactory.Create();
            var serviceOperations  = environmentFactory.ManagementEnvironment.MgmtServiceOperations;

            var companyId = CreateCompany();

            var id = serviceOperations.Create(new Service()
            {
                Company = new Company()
                {
                    Id = companyId
                }, Name = "new service", ApiKey = Crypto.GenerateSafeRandomToken()
            });

            Assert.AreEqual(32, id.Length);
        }
        private void Initialize()
        {
            var environmentFactory = EnvironmentFactoryFactory.Create();

            _authenticationContext = Substitute.For <IAuthenticationContext>();

            var userOperations  = environmentFactory.ManagementEnvironment.MgmtUserOperations;
            var settingProvider = new SettingProvider(environmentFactory.ManagementEnvironment.MgmtSettingOperations);
            var userService     = new UserService(userOperations, _authenticationContext, settingProvider, null);

            _userId = userService.Register(new RegisterDto()
            {
                Name = "user", Email = EmailHelper.Generate(), Password = "******"
            }, null);

            _authenticationContext.GetContextUser().Returns(_userId);
        }
Example #18
0
        public void GetServiceTest()
        {
            var environmentFactory = EnvironmentFactoryFactory.Create();

            var service1 = new ServiceDto()
            {
                CompanyId = _companyId, Name = "new service1", ApiKey = Identity.Next()
            };
            var service2 = new ServiceDto()
            {
                CompanyId = _companyId, Name = "new service2", ApiKey = Identity.Next()
            };

            var service1Id = _serviceService.Create(service1);
            var service2Id = _serviceService.Create(service2);

            var incoming =
                new List <TelemetryDataSinkParametersDto>
            {
                new TelemetryDataSinkParametersDto
                {
                    SinkName   = "test",
                    Parameters = new Dictionary <string, string> {
                        { "k1", "v1" }, { "k2", "v2" }
                    }
                }
            };

            _serviceService.UpdateIncomingTelemetryDataSinks(service1Id, incoming);

            var platformServiceOperations = environmentFactory.ManagementEnvironment.ObjServiceOperations;

            var s1 = platformServiceOperations.Get(service1Id);
            var s2 = platformServiceOperations.Get(service2Id);

            Assert.AreEqual(service1Id, s1.Id);
            Assert.AreEqual(_companyId, s1.CompanyId);
            Assert.AreEqual(32, s1.ApiKey.Length);
            Assert.AreEqual(1, s1.TelemetryDataSinkSettings.Incoming.Count());
            Assert.AreEqual("test", s1.TelemetryDataSinkSettings.Incoming.First().SinkName);
            Assert.AreEqual(2, s1.TelemetryDataSinkSettings.Incoming.First().Parameters.Count); Assert.AreEqual(service2Id, s2.Id);
            Assert.AreEqual(_companyId, s2.CompanyId);
            Assert.AreEqual(32, s2.ApiKey.Length);
            Assert.IsNull(s2.TelemetryDataSinkSettings.Incoming);
        }
Example #19
0
        public void ListDevicesTest()
        {
            var networkId = _networkService.Create(new NetworkDto()
            {
                ServiceId = _serviceId,
                CompanyId = _companyId,
                Name      = "new network1"
            });

            var environmentFactory = EnvironmentFactoryFactory.Create();

            var device1 = new DeviceDto()
            {
                NetworkId = networkId,
                ServiceId = _serviceId,
                CompanyId = _companyId,
                Name      = "new device1"
            };
            var device2 = new DeviceDto()
            {
                NetworkId = networkId,
                ServiceId = _serviceId,
                CompanyId = _companyId,
                Name      = "new device2"
            };
            var device3 = new DeviceDto()
            {
                NetworkId = networkId,
                ServiceId = _serviceId,
                CompanyId = _companyId,
                Name      = "new device3"
            };

            _deviceService.Create(device1);
            var device2Id = _deviceService.Create(device2);

            _deviceService.Create(device3);

            var pltNetworkOperations = environmentFactory.ManagementEnvironment.ObjNetworkOperations;
            var ds = pltNetworkOperations.ListDevices(networkId);

            Assert.AreEqual(3, ds.Count());
            Assert.IsTrue(ds.Any(d => d.Id == device2Id && d.Name == device2.Name));
        }
Example #20
0
        public void TrySendForgotPasswordEmailLoggedIn()
        {
            var environmentFactory    = EnvironmentFactoryFactory.Create();
            var authenticationContext = Substitute.For <IAuthenticationContext>();

            var userOperations  = environmentFactory.ManagementEnvironment.MgmtUserOperations;
            var settingProvider = new SettingProvider(environmentFactory.ManagementEnvironment.MgmtSettingOperations);

            var userService = new UserService(userOperations, authenticationContext, settingProvider, null);

            var email = EmailHelper.Generate();

            userService.Register(new RegisterDto()
            {
                Name = "new user", Email = email, Password = "******"
            }, null);

            userService.SendForgotPasswordEmail(email, null);
        }
Example #21
0
        private static IPersistentStorage PoorMansContainerResolver()
        {
            var environmentFactoryFactory          = EnvironmentFactoryFactory.Create();
            var connectionStringResolverTypeString =
                environmentFactoryFactory.MessagingEnvironment.ConnectionStringResolverType;

            object[] args = null;
            if (connectionStringResolverTypeString != null)
            {
                var connectionStringResolver = (IConnectionStringResolver)Activator.CreateInstance(Type.GetType(connectionStringResolverTypeString));
                args = new object[] { connectionStringResolver };
            }

            var persistentStorageTypeString =
                environmentFactoryFactory.MessagingEnvironment.PersistentStorageType;
            var persistentStorage = (IPersistentStorage)Activator.CreateInstance(Type.GetType(persistentStorageTypeString), args);

            return(persistentStorage);
        }
Example #22
0
        public void GetUrlInfoTest()
        {
            var environmentFactory    = EnvironmentFactoryFactory.Create();
            var authenticationContext = Substitute.For <IAuthenticationContext>();

            authenticationContext.GetContextUser().Returns("12345");

            var settingProvider = new SettingProvider(environmentFactory.ManagementEnvironment.MgmtSettingOperations);

            var infoService = new InfoService(authenticationContext, settingProvider, null);

            var info = infoService.GetUrlInfo();

            Assert.IsNotNull(info.WebsiteUrl);
            Assert.IsNotNull(info.ManagementApiUrl);
            Assert.IsNotNull(info.PlatformApiUrl);
            Assert.IsNotNull(info.PlatformWsUrl);
            Assert.IsNotNull(info.ReportingApiUrl);
        }
Example #23
0
        public void UpdateDeviceTest()
        {
            var environmentFactory = EnvironmentFactoryFactory.Create();
            var deviceOperations   = environmentFactory.ManagementEnvironment.MgmtDeviceOperations;
            var networkOperations  = environmentFactory.ManagementEnvironment.MgmtNetworkOperations;

            var companyServiceNetworkIds = CreateCompanyAndServiceAndNetwork();

            var id =
                deviceOperations.Create(new Device()
            {
                Network = new Network()
                {
                    Id = companyServiceNetworkIds.NetworkId
                },
                Service = new Service()
                {
                    Id = companyServiceNetworkIds.ServiceId
                },
                Company = new Company()
                {
                    Id = companyServiceNetworkIds.CompanyId
                },
                Name      = "new device",
                DeviceKey = Crypto.GenerateSafeRandomToken()
            });


            var newDevice = deviceOperations.Get(id);

            newDevice.Name     += "mod";
            newDevice.DeviceKey = Identity.Next();
            deviceOperations.Update(newDevice);

            var updatedDevice = deviceOperations.Get(id);
            var devices       = networkOperations.ListDevices(companyServiceNetworkIds.NetworkId);

            Assert.AreEqual("new devicemod", updatedDevice.Name);
            Assert.AreEqual(1, devices.Count);
            Assert.AreEqual("new devicemod", devices[0].Name);
            Assert.AreEqual(newDevice.DeviceKey, updatedDevice.DeviceKey);
        }
Example #24
0
        public void UpdateService2Test()
        {
            var environmentFactory = EnvironmentFactoryFactory.Create();
            var serviceOperations  = environmentFactory.ManagementEnvironment.MgmtServiceOperations;

            var companyId = CreateCompany();

            var service = new Service()
            {
                Company = new Company()
                {
                    Id = companyId
                }, Name = "new service", ApiKey = Crypto.GenerateSafeRandomToken()
            };
            var id = serviceOperations.Create(service);

            var newService = serviceOperations.Get(id);

            newService.TelemetryDataSinkSettings = new TelemetryDataSinkSettings()
            {
                Incoming =
                    new List <TelemetryDataSinkParameters>
                {
                    new TelemetryDataSinkParameters
                    {
                        SinkName   = "test",
                        Parameters = new Dictionary <string, string> {
                            { "k1", "v1" }, { "k2", "v2" }
                        }
                    }
                }
            };

            serviceOperations.Update(newService);

            var updatedService = serviceOperations.Get(id);

            Assert.AreEqual("new service", updatedService.Name);
            Assert.AreEqual(1, updatedService.TelemetryDataSinkSettings.Incoming.Count());
            Assert.AreEqual("test", updatedService.TelemetryDataSinkSettings.Incoming.First().SinkName);
            Assert.AreEqual(2, updatedService.TelemetryDataSinkSettings.Incoming.First().Parameters.Count);
        }
Example #25
0
        protected void Initialize()
        {
            var environmentFactory = EnvironmentFactoryFactory.Create();

            _authenticationContext = Substitute.For <IAuthenticationContext>();

            var userOperations    = environmentFactory.ManagementEnvironment.MgmtUserOperations;
            var companyOperations = environmentFactory.ManagementEnvironment.MgmtCompanyOperations;
            var settingProvider   = new SettingProvider(environmentFactory.ManagementEnvironment.MgmtSettingOperations);

            var userService = new UserService(userOperations, _authenticationContext, settingProvider, null);
            var userId      = userService.Register(new RegisterDto()
            {
                Name = "user", Email = EmailHelper.Generate(), Password = "******"
            }, null);

            var companyService = new CompanyService(companyOperations, _authenticationContext, null, new CapabilityProvider(settingProvider));

            _authenticationContext.GetContextUser().Returns(userId);

            _companyId = companyService.Create("new company");

            var serviceOperations = environmentFactory.ManagementEnvironment.MgmtServiceOperations;
            var telemetryDataSinkSetupServiceClient = Substitute.For <ITelemetryDataSinkSetupServiceClient>();

            telemetryDataSinkSetupServiceClient.GetTelemetryDataSinksMetadata().Returns(
                new TelemetryDataSinksMetadataDtoClient
            {
                Incoming = new List <TelemetryDataSinkMetadataDtoClient>
                {
                    new TelemetryDataSinkMetadataDtoClient
                    {
                        Name              = "test",
                        Description       = null,
                        ParametersToInput = new List <string> {
                            "k1", "k2"
                        }
                    }
                }
            });
            _serviceService = new ServiceService(serviceOperations, companyOperations, _authenticationContext, telemetryDataSinkSetupServiceClient, new CapabilityProvider(settingProvider));
        }
Example #26
0
        private void Initialize()
        {
            var environmentFactory    = EnvironmentFactoryFactory.Create();
            var authenticationContext = new TestAuthenticationContext();

            var userOperations    = environmentFactory.ManagementEnvironment.MgmtUserOperations;
            var companyOperations = environmentFactory.ManagementEnvironment.MgmtCompanyOperations;
            var serviceOperations = environmentFactory.ManagementEnvironment.MgmtServiceOperations;
            var settingOperations = environmentFactory.ManagementEnvironment.MgmtSettingOperations;

            settingOperations.Update(new Setting(Setting.ServiceProfile, ServiceProfile.SingleService.ToString()));

            _settingProvider = new SettingProvider(settingOperations);

            _companyService = new CompanyService(companyOperations, authenticationContext, null, new CapabilityProvider(_settingProvider));
            _serviceService = new ServiceService(serviceOperations, companyOperations, authenticationContext, null, new CapabilityProvider(_settingProvider));
            var environmentPrebuilder = new EnvironmentPrebuilder(authenticationContext, _settingProvider, _companyService, _serviceService);

            _userService = new UserService(userOperations, authenticationContext, _settingProvider, environmentPrebuilder);
        }
Example #27
0
        public void ResendActivationEmailAlreadyActivated()
        {
            var environmentFactory    = EnvironmentFactoryFactory.Create();
            var authenticationContext = Substitute.For <IAuthenticationContext>();

            var userOperations  = environmentFactory.ManagementEnvironment.MgmtUserOperations;
            var settingProvider = new SettingProvider(environmentFactory.ManagementEnvironment.MgmtSettingOperations);

            var userService = new UserService(userOperations, authenticationContext, settingProvider, null);

            var email = EmailHelper.Generate();

            var userId = userService.Register(new RegisterDto()
            {
                Name = "new user", Email = email, Password = "******"
            }, null);

            authenticationContext.GetContextUser().Returns((string)null);

            userService.ResendActivationEmail(email, null);
        }
Example #28
0
        public void FindUserNoSuchTest()
        {
            var environmentFactory    = EnvironmentFactoryFactory.Create();
            var authenticationContext = Substitute.For <IAuthenticationContext>();

            var userOperations  = environmentFactory.ManagementEnvironment.MgmtUserOperations;
            var settingProvider = new SettingProvider(environmentFactory.ManagementEnvironment.MgmtSettingOperations);

            var userService = new UserService(userOperations, authenticationContext, settingProvider, null);

            var email = EmailHelper.Generate();

            userService.Register(new RegisterDto()
            {
                Name = "new user", Email = email, Password = "******"
            }, null);

            var user = userService.FindUser(email + "asdfasfd");

            Assert.IsNull(user);
        }
Example #29
0
        public void TryRegisterTwiceWithDifferentCasingTest()
        {
            var environmentFactory    = EnvironmentFactoryFactory.Create();
            var authenticationContext = Substitute.For <IAuthenticationContext>();

            var userOperations  = environmentFactory.ManagementEnvironment.MgmtUserOperations;
            var settingProvider = new SettingProvider(environmentFactory.ManagementEnvironment.MgmtSettingOperations);

            var userService = new UserService(userOperations, authenticationContext, settingProvider, null);

            var email = EmailHelper.Generate();

            userService.Register(new RegisterDto()
            {
                Name = "new user", Email = email.ToLower(), Password = "******"
            }, null);
            userService.Register(new RegisterDto()
            {
                Name = "new user", Email = email.ToUpper(), Password = "******"
            }, null);
        }
Example #30
0
        private string CreateCompany()
        {
            var environmentFactory = EnvironmentFactoryFactory.Create();
            var userOperations     = environmentFactory.ManagementEnvironment.MgmtUserOperations;
            var companyOperations  = environmentFactory.ManagementEnvironment.MgmtCompanyOperations;

            var salt         = Crypto.GenerateSalt();
            var passwordHash = Crypto.CalcualteHash("password", salt);
            var userId       = userOperations.Create(new User()
            {
                Name = "new user", Email = EmailHelper.Generate()
            }, passwordHash, salt);

            var company = new Company {
                Name = "new company"
            };

            var companyId = companyOperations.Create(company, userId);

            return(companyId);
        }