Beispiel #1
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);
        }
Beispiel #2
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);
        }
Beispiel #3
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     = "******"
            }));
        }
Beispiel #4
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);
        }
Beispiel #5
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);
        }