Example #1
0
        public void UpdateLoginUserTest()
        {
            var environmentFactory = EnvironmentFactoryFactory.Create();
            var userOperations     = environmentFactory.ManagementEnvironment.MgmtUserOperations;

            var email = EmailHelper.Generate();

            var salt         = Crypto.GenerateSalt();
            var passwordHash = Crypto.CalcualteHash("password", salt);
            var id           = userOperations.Create(new User()
            {
                Name = "new user", Email = email, Activated = true, ActivationCode = "12345"
            }, passwordHash, salt);

            var loginUser = userOperations.GetLoginUser(email);

            var salt2         = Crypto.GenerateSalt();
            var passwordHash2 = Crypto.CalcualteHash("password2", salt);

            loginUser.PasswordHash = passwordHash2;
            loginUser.Salt         = salt2;

            userOperations.Update(loginUser);

            var loginUser2 = userOperations.GetLoginUser(email);

            Assert.AreEqual(id, loginUser2.UserId);
            Assert.AreEqual(email, loginUser2.Email);
            Assert.AreEqual(passwordHash2, loginUser2.PasswordHash);
            Assert.AreEqual(salt2, loginUser2.Salt);
        }
Example #2
0
        public void IsNotExistsTest()
        {
            var environmentFactory = EnvironmentFactoryFactory.Create();
            var userOperations     = environmentFactory.ManagementEnvironment.MgmtUserOperations;

            Assert.IsFalse(userOperations.IsExists("nosuch"));
        }
Example #3
0
        public void UpdateServiceTest()
        {
            var environmentFactory = EnvironmentFactoryFactory.Create();
            var companyOperations  = environmentFactory.ManagementEnvironment.MgmtCompanyOperations;
            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.Name  += "mod";
            newService.ApiKey = Identity.Next();
            serviceOperations.Update(newService);

            var updatedService = serviceOperations.Get(id);
            var services       = companyOperations.ListServices(companyId);

            Assert.AreEqual("new servicemod", updatedService.Name);
            Assert.AreEqual(newService.ApiKey, updatedService.ApiKey);
            Assert.AreEqual(1, services.Count);
            Assert.AreEqual("new servicemod", services[0].Name);
        }
Example #4
0
        private void Initialize()
        {
            var environmentFactory = EnvironmentFactoryFactory.Create();

            _authenticationContext = Substitute.For <IAuthenticationContext>();

            var userOperations = environmentFactory.ManagementEnvironment.MgmtUserOperations;

            _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");

            _serviceOperations = environmentFactory.ManagementEnvironment.MgmtServiceOperations;
            _serviceService    = new ServiceService(_serviceOperations, _companyOperations, _authenticationContext, null, new CapabilityProvider(settingProvider));
            _serviceId         = _serviceService.Create(new ServiceDto()
            {
                CompanyId = _companyId, Name = "new service"
            });

            _networkOperations = environmentFactory.ManagementEnvironment.MgmtNetworkOperations;
            _networkService    = new NetworkService(_networkOperations, _serviceOperations, _companyOperations, _authenticationContext, null);
        }
Example #5
0
        public void DeleteCompanyTest()
        {
            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);

            companyOperations.Delete(companyId);

            var companies = userOperations.ListCompanies(userId);

            AssertionHelper.AssertThrows <NotFoundException>(() => companyOperations.Get(companyId));
            AssertionHelper.AssertThrows <NotFoundException>(() => companyOperations.ListUsers(companyId));

            Assert.AreEqual(0, companies.Count);
        }
Example #6
0
        public void ListCompaniesTest()
        {
            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 company1 = new Company {
                Name = "new company1"
            };
            var company2 = new Company {
                Name = "new company2"
            };

            var company1Id = companyOperations.Create(company1, userId);
            var company2Id = companyOperations.Create(company2, userId);

            var companies = userOperations.ListCompanies(userId);

            Assert.AreEqual(2, companies.Count);

            var c1 = companies.Single(c => c.Id == company1Id);
            var c2 = companies.Single(c => c.Id == company2Id);

            Assert.AreEqual(company1Id, c1.Id);
            Assert.AreEqual(company1.Name, c1.Name);
            Assert.AreEqual(company2Id, c2.Id);
            Assert.AreEqual(company2.Name, c2.Name);
        }
Example #7
0
        public void SendForgotPasswordEmail()
        {
            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 mailer = Substitute.For <IMailer>();

            var email = EmailHelper.Generate();

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

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

            userService.SendForgotPasswordEmail(email, mailer);

            mailer.Received().SendForgotPasswordEmail(userId, "new user", email, Arg.Any <string>(), Arg.Any <string>());
        }
        public void ResolveConnectringStringByNameTest()
        {
            if (!IsIntegrationTest())
            {
                return;
            }

            var settingOperation = Substitute.For <Thriot.Objects.Model.Operations.ISettingOperations>();

            var dynamicConnectionStringResolver = new DynamicConnectionStringResolver(settingOperation);
            var telemetryEnvrionment            = EnvironmentFactoryFactory.Create().TelemetryEnvironment;

            settingOperation.Get(null).ReturnsForAnyArgs(new Setting(SettingId.GetConnection("ResolvableConnectionString"), telemetryEnvrionment.ConnectionString));

            var settingsDictionary = GetTimeSeriesSettings();

            settingsDictionary.Remove(telemetryEnvrionment.ConnectionStringParamName);
            settingsDictionary[telemetryEnvrionment.ConnectionStringNameName] = "ResolvableConnectionString";

            var telemetryDataSinkTimeSeries = GetTelemetryDataSinkTimeSeries();

            telemetryDataSinkTimeSeries.Setup(dynamicConnectionStringResolver, settingsDictionary);

            settingOperation.ReceivedWithAnyArgs(1).Get(Arg.Any <SettingId>());
        }
Example #9
0
        public void ChangePasswordTest()
        {
            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(userId);

            userService.ChangePassword(new ChangePasswordDto {
                CurrentPassword = "******", NewPassword = "******"
            });

            AssertionHelper.AssertThrows <AuthenticationException>(
                () =>
                userService.ChangePassword(new ChangePasswordDto
            {
                CurrentPassword = "******",
                NewPassword     = "******"
            }));
        }
Example #10
0
        public void ResendActivationEmail()
        {
            var environmentFactory    = EnvironmentFactoryFactory.Create();
            var mailer                = Substitute.For <IMailer>();
            var authenticationContext = Substitute.For <IAuthenticationContext>();

            authenticationContext.GetContextUser().Returns((string)null);
            var userOperations = environmentFactory.ManagementEnvironment.MgmtUserOperations;

            var settingProvider = Substitute.For <ISettingProvider>();

            settingProvider.EmailActivation.Returns(true);

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

            var email = EmailHelper.Generate();

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

            userService.ResendActivationEmail(email, mailer);

            mailer.DidNotReceiveWithAnyArgs().SendForgotPasswordEmail(null, null, null, null, null);
        }
Example #11
0
        public void ActivationAlreadyLoggedInFailTest()
        {
            var environmentFactory    = EnvironmentFactoryFactory.Create();
            var mailer                = Substitute.For <IMailer>();
            var authenticationContext = Substitute.For <IAuthenticationContext>();

            authenticationContext.GetContextUser().Returns("123456");
            var userOperations  = environmentFactory.ManagementEnvironment.MgmtUserOperations;
            var settingProvider = Substitute.For <ISettingProvider>();

            settingProvider.EmailActivation.Returns(true);

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

            var    email          = EmailHelper.Generate();
            string activationCode = null;

            mailer.When(
                m => m.SendActivationMail(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>()))
            .Do(call => { activationCode = (string)call.Args()[3]; });
            var userId = userService.Register(new RegisterDto()
            {
                Name = "new user", Email = email, Password = "******"
            }, mailer);

            userService.Activate(userId, activationCode);
        }
Example #12
0
        public void DeleteDeviceTest()
        {
            var environmentFactory = EnvironmentFactoryFactory.Create();
            var deviceOperations   = environmentFactory.ManagementEnvironment.MgmtDeviceOperations;
            var networkOperations  = environmentFactory.ManagementEnvironment.MgmtNetworkOperations;

            var compServiceNetworkIds = CreateCompanyAndServiceAndNetwork();

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

            deviceOperations.Delete(id);

            var devices = networkOperations.ListDevices(compServiceNetworkIds.NetworkId);

            AssertionHelper.AssertThrows <NotFoundException>(() => deviceOperations.Get(id));

            Assert.AreEqual(0, devices.Count);
        }
Example #13
0
        public void CreateDeviceTest()
        {
            var environmentFactory = EnvironmentFactoryFactory.Create();
            var deviceOperations   = environmentFactory.ManagementEnvironment.MgmtDeviceOperations;

            var compServiceNetworkIds = CreateCompanyAndServiceAndNetwork();

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

            Assert.AreEqual(32, id.Length);
        }
Example #14
0
        public void GetCompanyTest()
        {
            var environmentFactory = EnvironmentFactoryFactory.Create();

            var company1Id = _companyService.Create("new company1");
            var company2Id = _companyService.Create("new company2");

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

            _companyService.UpdateIncomingTelemetryDataSinks(company1Id, incoming);

            var platformCompanyOperations = environmentFactory.ManagementEnvironment.ObjCompanyOperations;

            var c1 = platformCompanyOperations.Get(company1Id);
            var c2 = platformCompanyOperations.Get(company2Id);

            Assert.AreEqual(company1Id, c1.Id);
            Assert.AreEqual(1, c1.TelemetryDataSinkSettings.Incoming.Count());
            Assert.AreEqual("test", c1.TelemetryDataSinkSettings.Incoming.First().SinkName);
            Assert.AreEqual(2, c1.TelemetryDataSinkSettings.Incoming.First().Parameters.Count);

            Assert.AreEqual(company2Id, c2.Id);
            Assert.IsNull(c2.TelemetryDataSinkSettings.Incoming);
        }
Example #15
0
        public void TryResetPasswordEmailNotActivated()
        {
            var environmentFactory    = EnvironmentFactoryFactory.Create();
            var mailer                = Substitute.For <IMailer>();
            var authenticationContext = Substitute.For <IAuthenticationContext>();

            authenticationContext.GetContextUser().Returns((string)null);
            var userOperations = environmentFactory.ManagementEnvironment.MgmtUserOperations;

            var settingProvider = Substitute.For <ISettingProvider>();

            settingProvider.EmailActivation.Returns(true);

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

            var email = EmailHelper.Generate();

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

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

            userService.ResetPassword(new ResetPasswordDto
            {
                ConfirmationCode = "fck",
                Password         = "******",
                UserId           = userId
            });
        }
Example #16
0
        public void UpdateSuccessTest()
        {
            var environmentFactory = EnvironmentFactoryFactory.Create();
            var userOperations     = environmentFactory.ManagementEnvironment.MgmtUserOperations;

            var email = EmailHelper.Generate();

            var salt         = Crypto.GenerateSalt();
            var passwordHash = Crypto.CalcualteHash("password", salt);
            var id           = userOperations.Create(new User()
            {
                Name = "new user", Email = email, Activated = true, ActivationCode = "12345"
            }, passwordHash, salt);

            var user = userOperations.Get(id);

            user.Activated      = false;
            user.ActivationCode = "54321";

            userOperations.Update(user);

            user = userOperations.Get(id);

            Assert.AreEqual(id, user.Id);
            Assert.AreEqual("new user", user.Name);
            Assert.AreEqual(email, user.Email);
            Assert.AreEqual(false, user.Activated);
            Assert.AreEqual("54321", user.ActivationCode);
        }
Example #17
0
        public void ListCompaniesTest()
        {
            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 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);

            var compId = companyService.Create("new company");

            var companies = userService.ListCompanies();

            Assert.AreEqual(1, companies.Count);
            Assert.AreEqual(compId, companies[0].Id);
        }
Example #18
0
        public void GetSettingTest()
        {
            var environmentFactory = EnvironmentFactoryFactory.Create();
            var setting            = environmentFactory.ManagementEnvironment.ObjSettingOperations.Get(Setting.TelemetrySetupServiceApiKey);

            Assert.AreEqual(32, setting.Value.Length);
        }
Example #19
0
        public void GetMeTest()
        {
            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(userId);

            var user = userService.GetMe();

            Assert.AreEqual(userId, user.Id);
            Assert.AreEqual("new user", user.Name);
            Assert.AreEqual(email, user.Email);
        }
Example #20
0
        public void AddUserTest()
        {
            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 user2Id = userOperations.Create(new User()
            {
                Name = "new user", Email = EmailHelper.Generate()
            }, passwordHash, salt);

            companyOperations.AddUser(companyId, user2Id);

            var users = companyOperations.ListUsers(companyId);

            Assert.AreEqual(2, users.Count);

            companyOperations.AddUser(companyId, user2Id);

            users = companyOperations.ListUsers(companyId);
            Assert.AreEqual(2, users.Count);
        }
Example #21
0
        public void CommitOutgoingMessageRealTest()
        {
            var environmentFactory = EnvironmentFactoryFactory.Create();

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

            var pltDeviceOperations = environmentFactory.ManagementEnvironment.ObjDeviceOperations;

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

            messagingService.RecordOutgoingMessage(_deviceId, _deviceId, "32412341243");

            var msg = messagingService.Peek(_deviceId);

            Assert.AreEqual(OutgoingState.Ok, msg.State);
            Assert.AreEqual(_deviceId, msg.Message.DeviceId);
            Assert.AreEqual("32412341243", msg.Message.Payload);
            Assert.AreEqual(_deviceId, msg.Message.SenderDeviceId);

            var state = messagingService.Commit(_deviceId);

            Assert.AreEqual(OutgoingState.Ok, state);

            var state2 = messagingService.Commit(_deviceId);

            Assert.AreEqual(OutgoingState.Ok, state2);

            MessagingWorkers.Stop();
        }
Example #22
0
        public void DeleteServiceTest()
        {
            var environmentFactory = EnvironmentFactoryFactory.Create();
            var companyOperations  = environmentFactory.ManagementEnvironment.MgmtCompanyOperations;
            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);

            serviceOperations.Delete(id);

            var services = companyOperations.ListServices(companyId);

            AssertionHelper.AssertThrows <NotFoundException>(() => serviceOperations.Get(id));

            Assert.AreEqual(0, services.Count);
        }
Example #23
0
        public void GetMeFailedTest()
        {
            var environmentFactory = EnvironmentFactoryFactory.Create();
            var userOperations     = environmentFactory.ManagementEnvironment.MgmtUserOperations;

            userOperations.Get("231413245");
        }
Example #24
0
        private CompanyServiceIdPair CreateCompanyAndService()
        {
            var environmentFactory = EnvironmentFactoryFactory.Create();
            var userOperations     = environmentFactory.ManagementEnvironment.MgmtUserOperations;
            var companyOperations  = environmentFactory.ManagementEnvironment.MgmtCompanyOperations;
            var serviceOperations  = environmentFactory.ManagementEnvironment.MgmtServiceOperations;

            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);

            return(new CompanyServiceIdPair {
                CompanyId = companyId, ServiceId = serviceId
            });
        }
Example #25
0
        public void TryCreateServiceUnderOthersCompanyTest()
        {
            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 userId2 = 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");

            authenticationContext.GetContextUser().Returns(userId2);

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

            serviceService.Create(new ServiceDto()
            {
                CompanyId = companyId1, Name = "svc"
            });
        }
Example #26
0
        public void CreateNetworkUnderNetworkTest()
        {
            var environmentFactory = EnvironmentFactoryFactory.Create();
            var networkOperations  = environmentFactory.ManagementEnvironment.MgmtNetworkOperations;

            var companyServiceIdPair = CreateCompanyAndService();

            var parentNetworkId = CreateParentNetwork(networkOperations, companyServiceIdPair);

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

            Assert.AreEqual(32, id.Length);
        }
Example #27
0
        public void DeleteNetworkUnderServiceTest()
        {
            var environmentFactory = EnvironmentFactoryFactory.Create();
            var serviceOperations  = environmentFactory.ManagementEnvironment.MgmtServiceOperations;
            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()
            });

            networkOperations.Delete(id);

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

            AssertionHelper.AssertThrows <NotFoundException>(() => networkOperations.Get(id));

            Assert.AreEqual(0, networks.Count);
        }
Example #28
0
        public void GetNetworkUnderServiceTest()
        {
            var environmentFactory = EnvironmentFactoryFactory.Create();

            var network1Id = _networkService.Create(new NetworkDto()
            {
                ServiceId = _serviceId,
                CompanyId = _companyId,
                Name      = "new network1"
            });

            var network2Id = _networkService.Create(new NetworkDto()
            {
                ServiceId = _serviceId,
                CompanyId = _companyId,
                Name      = "new network2"
            });

            var pltNetworkOperations = environmentFactory.ManagementEnvironment.ObjNetworkOperations;

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

            Assert.AreEqual(network1Id, dg1.Id);
            Assert.AreEqual(_companyId, dg1.CompanyId);
            Assert.AreEqual(_serviceId, dg1.ServiceId);
            Assert.IsNull(dg1.ParentNetworkId);
            Assert.AreEqual(32, dg1.NetworkKey.Length);
            Assert.AreEqual(network2Id, dg2.Id);
            Assert.AreEqual(_companyId, dg2.CompanyId);
            Assert.AreEqual(_serviceId, dg2.ServiceId);
            Assert.IsNull(dg2.ParentNetworkId);
            Assert.AreEqual(32, dg2.NetworkKey.Length);
            Assert.AreNotEqual(dg1.NetworkKey, dg2.NetworkKey);
        }
Example #29
0
        public void TryCreateDeviceUnderOtherNetworkTest()
        {
            var environmentFactory    = EnvironmentFactoryFactory.Create();
            var authenticationContext = Substitute.For <IAuthenticationContext>();
            var messagingService      = 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);
            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 deviceOperations = environmentFactory.ManagementEnvironment.MgmtDeviceOperations;
            var deviceService    = new DeviceService(deviceOperations, networkOperations, serviceOperations, companyOperations, authenticationContext, messagingService);

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

            var device = new DeviceDto()
            {
                NetworkId = networkId2,
                CompanyId = companyId1,
                ServiceId = serviceId1,
                Name      = "test"
            };

            deviceService.Create(device);
        }
Example #30
0
        protected void Initialize()
        {
            var environmentFactory = EnvironmentFactoryFactory.Create();

            _authenticationContext = Substitute.For <IAuthenticationContext>();
            var 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;
            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"
                        }
                    }
                }
            });
            _networkService = new NetworkService(networkOperations, serviceOperations, companyOperations, _authenticationContext, telemetryDataSinkSetupServiceClient);

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

            var deviceOperations = environmentFactory.ManagementEnvironment.MgmtDeviceOperations;

            _deviceService = new DeviceService(deviceOperations, networkOperations, serviceOperations, companyOperations,
                                               _authenticationContext, messagingServiceClient);
        }