Exemplo n.º 1
0
 private void SetLocalProperties(string organizationName, string applicationName, string hostName, int port)
 {
     LocalCoreRegistryRepository          = new ApplicationRegistrationRepository();
     LocalCoreRegistryRepository.Database = new SQLiteDatabase(WorkspaceDirectory, nameof(CoreClient));
     CoreServiceRegistryContainer.GetServiceRegistry().Get <IStorableTypesProvider>().AddTypes(LocalCoreRegistryRepository);
     ProcessDescriptor = ProcessDescriptor.ForApplicationRegistration(LocalCoreRegistryRepository, hostName, port, applicationName, organizationName);
 }
Exemplo n.º 2
0
        public void EnsureSingleDoesntDuplicate()
        {
            ServiceRegistry glooRegistry           = CoreServiceRegistryContainer.GetServiceRegistry();
            ApplicationRegistrationRepository repo = glooRegistry.Get <ApplicationRegistrationRepository>();
            CompositeRepository compositeRepo      = glooRegistry.Get <CompositeRepository>();

            compositeRepo.UnwireBackup();
            Machine machine = Machine.Current;

            repo.Delete(machine);
            Machine retrieved = repo.Query <Machine>(Filter.Where("Name") == machine.Name && Filter.Where("Cuid") == machine.Cuid).FirstOrDefault();

            Expect.IsNull(retrieved);
            Machine ensured = machine.EnsureSingle <Machine>(repo, "Name", "Cuid");

            Expect.IsNotNull(ensured, "Ensured was null");
            Machine ensuredAgain = ensured.EnsureSingle <Machine>(repo, "Name", "Cuid");

            Expect.AreEqual(ensured.Id, ensuredAgain.Id);
            Expect.AreEqual(ensured.Uuid, ensuredAgain.Uuid);
            Expect.AreEqual(ensured.Cuid, ensuredAgain.Cuid);

            Expect.AreEqual(1, repo.Query <Machine>(new { Name = machine.Name, Cuid = machine.Cuid }).Count());
            repo.Delete(machine);
        }
Exemplo n.º 3
0
        private CoreApplicationRegistrationService GetTestService()
        {
            ServiceRegistry registry = CoreServiceRegistryContainer.GetServiceRegistry();
            CoreApplicationRegistrationService svc = registry.Get <CoreApplicationRegistrationService>();

            registry.SetProperties(svc);
            return(svc);
        }
Exemplo n.º 4
0
 public void CanSaveMachineInCoreRegistryRepo()
 {
     ApplicationRegistrationRepository repo = CoreServiceRegistryContainer.GetServiceRegistry().Get<ApplicationRegistrationRepository>();
     Client test = Client.Of(repo, "test", "test", 80);//Machine.ClientOf(repo, "test", 80);
     test = repo.Save(test);
     Expect.IsTrue(test.Id > 0);
     Client test2 = Client.Of(repo, "test", "test", 80);//Machine.ClientOf(repo, "test", 90);
     test2 = repo.Save(test2);
     Expect.IsTrue(test2.Id > 0);
 }
Exemplo n.º 5
0
        public void CanSaveUserToCompositeRepo()
        {
            CompositeRepository repo = CoreServiceRegistryContainer.GetServiceRegistry().Get <CompositeRepository>();

            ApplicationRegistration.User user = new ApplicationRegistration.User();
            user.UserName = 9.RandomLetters();
            user          = repo.Save(user);
            ApplicationRegistration.User retrieved = repo.Retrieve <ApplicationRegistration.User>(user.Uuid);
            Expect.AreEqual(user.UserName, retrieved.UserName);
            Expect.AreEqual(user.Id, retrieved.Id);
            Expect.AreEqual(user.Uuid, retrieved.Uuid);
        }
Exemplo n.º 6
0
 public void CoreClientCanRegisterAndConnectClient()
 {
     Message.PrintLine("This test requires a gloo server to be running on port 9100 of the localhost", ConsoleColor.Yellow);
     ApplicationRegistrationRepository repo = CoreServiceRegistryContainer.GetServiceRegistry().Get<ApplicationRegistrationRepository>();
     ConsoleLogger logger = new ConsoleLogger() { AddDetails = false };
     logger.StartLoggingThread();
     CoreClient client = new CoreClient("Bam.Net", "CoreServicesTestApp", "localhost", 9100, logger);
     client.LocalCoreRegistryRepository = repo;
     CoreServiceResponse registrationResponse = client.RegisterClient();
     Expect.IsTrue(registrationResponse.Success, registrationResponse.Message);
     CoreServiceResponse response = client.Connect();
     List<CoreServiceResponse> responses = response.Data.FromJObject<List<CoreServiceResponse>>();
     Expect.IsTrue(response.Success, string.Join("\r\n", responses.Select(r => r.Message).ToArray()));
 }
Exemplo n.º 7
0
        public void RegisterCreatesMachineEntry()
        {
            OutLineFormat("This test requires a gloo server to be running on port 9100 of the localhost", ConsoleColor.Yellow);
            ConsoleLogger logger = new ConsoleLogger();

            logger.AddDetails = false;
            logger.StartLoggingThread();
            ApplicationRegistrationRepository repo = CoreServiceRegistryContainer.GetServiceRegistry().Get <ApplicationRegistrationRepository>();
            CoreClient client = new CoreClient("TestOrg", "TestApp", $".\\{nameof(RegisterCreatesMachineEntry)}", logger);

            client.LocalCoreRegistryRepository = repo;
            CoreServiceResponse registrationResponse = client.RegisterClient();
            Machine             machine = repo.OneMachineWhere(m => m.Name == Machine.Current.Name);

            Expect.IsNotNull(machine);
            Pass(nameof(RegisterCreatesMachineEntry));
        }
Exemplo n.º 8
0
        public void WhoAmITest()
        {
            //OutLineFormat("This test requires a gloo server to be running on port 9100 of the localhost", ConsoleColor.Yellow);
            ConsoleLogger logger = new ConsoleLogger()
            {
                AddDetails = false
            };
            const string server = "localhost";// "int-heart.bamapps.net";
            const int port = 80;
            logger.StartLoggingThread();
            ApplicationRegistrationRepository repo = CoreServiceRegistryContainer.GetServiceRegistry().Get<ApplicationRegistrationRepository>();            
            CoreClient client = new CoreClient("TestOrg", "TestApp", server, port, logger)
            {
                UseServiceSubdomains = false,
                LocalCoreRegistryRepository = repo
            };
            client.InvocationException += (o, args) => logger.AddEntry("Invocation Exception: {0}", ((ServiceProxyInvokeEventArgs)args).Exception, args.PropertiesToString());
            client.MethodInvoked += (o, args) => logger.AddEntry("ProxyClient Method Invoked: {0}", args.PropertiesToString());

            CoreServiceResponse registrationResponse = client.RegisterClient();
            Client current = Client.Of(client.LocalCoreRegistryRepository, client.ApplicationName, server, port);
            
            CoreServiceResponse response = client.Connect();

            string whoAmI = client.UserRegistryService.WhoAmI();
            Expect.AreEqual(current.ToString(), whoAmI);

            whoAmI = client.ApplicationRegistryService.WhoAmI();
            Expect.AreEqual(current.ToString(), whoAmI);

            whoAmI = client.ConfigurationService.WhoAmI();
            Expect.AreEqual(current.ToString(), whoAmI);
            
            whoAmI = client.LoggerService.WhoAmI();
            Expect.AreEqual(current.ToString(), whoAmI);

            whoAmI = client.DiagnosticService.WhoAmI();
            Expect.AreEqual(current.ToString(), whoAmI);

            Pass($"You are {whoAmI}");
        }
Exemplo n.º 9
0
 public void MustBeLoggedInToRegister()
 {
     After.Setup((Action <SetupContext>)(ctx =>
     {
         ctx.CopyFrom((Incubation.Incubator)CoreServiceRegistryContainer.GetServiceRegistry());
     }))
     .WhenA <CoreApplicationRegistrationService>("tries to register application when not logged in", cars =>
     {
         ProcessDescriptor descriptor = ProcessDescriptor.ForApplicationRegistration(cars.CoreRegistryRepository, "localhost", 8080, "testApp", "testOrg");
         return(cars.RegisterApplication(descriptor));
     })
     .TheTest
     .ShouldPass(because =>
     {
         CoreServiceResponse result = because.ResultAs <CoreServiceResponse>();
         because.ItsTrue("the response was not successful", !result.Success, "request should have failed");
         because.ItsTrue("the message says 'You must be logged in to do that'", result.Message.Equals("You must be logged in to do that"));
         because.IllLookAtIt(result.Message);
     })
     .SoBeHappy()
     .UnlessItFailed();
 }
Exemplo n.º 10
0
 public void MustBeLoggedInToRegister()
 {
     After.Setup(setupContext =>
     {
         setupContext.CopyFrom((CoreServiceRegistryContainer.GetServiceRegistry()));
     })
     .WhenA <ApplicationRegistryService>("tries to register application when not logged in", applicationRegistryService =>
     {
         ProcessDescriptor descriptor = ProcessDescriptor.ForApplicationRegistration(applicationRegistryService.ApplicationRegistrationRepository, "localhost", 8080, "testApp", "testOrg");
         return(applicationRegistryService.RegisterApplicationProcess(descriptor));
     })
     .TheTest
     .ShouldPass((because, objectUnderTest) =>
     {
         because.ItsTrue($"object under test is of type {nameof(ApplicationRegistryService)}", objectUnderTest.GetType() == typeof(ApplicationRegistryService));
         CoreServiceResponse result = because.ResultAs <CoreServiceResponse>();
         because.ItsTrue("the response was not successful", !result.Success, "request should have failed");
         because.ItsTrue("the message says 'You must be logged in to do that'", result.Message.Equals("You must be logged in to do that"));
         because.IllLookAtIt(result.Message);
     })
     .SoBeHappy()
     .UnlessItFailed();
 }
Exemplo n.º 11
0
        public void WhoAmITest()
        {
            OutLineFormat("This test requires a gloo server to be running on port 9100 of the localhost", ConsoleColor.Yellow);
            ConsoleLogger logger = new ConsoleLogger();

            logger.AddDetails = false;
            const string server = "localhost";
            const int    port   = 9100;

            logger.StartLoggingThread();
            ApplicationRegistrationRepository repo = CoreServiceRegistryContainer.GetServiceRegistry().Get <ApplicationRegistrationRepository>();
            CoreClient client = new CoreClient("TestOrg", "TestApp", server, port, logger);

            client.LocalCoreRegistryRepository = repo;
            CoreServiceResponse registrationResponse = client.RegisterClient();
            Client current = Client.Of(client.LocalCoreRegistryRepository, client.ApplicationName, server, port);

            CoreServiceResponse response = client.Connect();

            string whoAmI = client.UserRegistryService.WhoAmI();

            Expect.AreEqual(current.ToString(), whoAmI);

            whoAmI = client.ApplicationRegistryService.WhoAmI();
            Expect.AreEqual(current.ToString(), whoAmI);

            whoAmI = client.ConfigurationService.WhoAmI();
            Expect.AreEqual(current.ToString(), whoAmI);

            whoAmI = client.LoggerService.WhoAmI();
            Expect.AreEqual(current.ToString(), whoAmI);

            whoAmI = client.DiagnosticService.WhoAmI();
            Expect.AreEqual(current.ToString(), whoAmI);

            Pass($"You are {whoAmI}");
        }
Exemplo n.º 12
0
        public static T GetService <T>()
        {
            ServiceRegistry svcRegistry = CoreServiceRegistryContainer.GetServiceRegistry();

            return(svcRegistry.Get <T>());
        }