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); }
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); }
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); }
public IActionResult CreateNetwork([FromBody] NetworkDto networkDto) // POST: api/v1/networks { return(Json(_networkService.Create(networkDto))); }
public void CreateNetworkUnderServiceTest() { var id = _networkService.Create(GetNetwork()); Assert.AreEqual(32, id.Length); }