示例#1
0
 public static string GenerateSingleUseToken()
 {
     using (var db = RavenSessionProvider.Get())
     {
         var name = Environment.MachineName + "-single-use-token";
         var application = new Application() { Id = Guid.NewGuid().ToString(), Name = name };
         db.Store(application);
         db.SaveChanges();
         db.ClearStaleIndexes();
         return application.Id;
     }
 }
        public void Should_return_true_when_applicationid_is_known()
        {
            // Given
            var applicationId = MakeFake.Guid;
            var instanceToLoad = new Application();
            var fakeRavenSessionProvider = MakeFake.RavenSessionProvider<Application>(instanceToLoad);
            var applicationService = new ApplicationService(fakeRavenSessionProvider);

            // When
            var isRegistered = applicationService.IsRegistered(applicationId);

            // Then
            isRegistered.ShouldBe(true);
        }
        public void Should_return_new_Application_when_new_application_is_registered()
        {
            // Given
            var applicationName = MakeFake.Name;
            var instanceToLoad = new Application() { Name = applicationName};
            var fakeRavenSessionProvider = MakeFake.RavenSessionProvider<Application>(instanceToLoad);
            var applicationService = new ApplicationService(fakeRavenSessionProvider);

            // When
            var application = applicationService.Register(applicationName);

            // Then
            application.Name.ShouldBe(applicationName);
            application.Id.IsGuid().ShouldBe(true);
        }
        public void Should_return_new_Application_when_application_is_registered_with_existing_applicationid()
        {
            // Given
            var applicationName = MakeFake.Name;
            var applicationId = MakeFake.Guid;
            var instanceToLoad = new Application() { Id = applicationId, Name = applicationName };
            var fakeRavenSessionProvider = MakeFake.RavenSessionProvider<Application>(instanceToLoad);
            var applicationService = new ApplicationService(fakeRavenSessionProvider);

            // When
            var application = applicationService.Transfer(applicationName, applicationId);

            // Then
            application.Name.ShouldBe(applicationName);
            application.Id.ShouldBe(applicationId);
        }
        public void Should_return_application_when_known_applicationid_is_supplied()
        {
            // Given
            var applicationId = MakeFake.Guid;
            var applicationName = MakeFake.Name;
            var instanceToLoad = new Application() { Id = applicationId, Name = applicationName };
            var fakeRavenSessionProvider = MakeFake.RavenSessionProvider<Application>(instanceToLoad);
            var applicationService = new ApplicationService(fakeRavenSessionProvider);

            // When
            var application = applicationService.Get(applicationId);

            // Then
            application.Name.ShouldBe(applicationName);
            application.Id.ShouldBe(applicationId);
        }
示例#6
0
 public static string GetConsoleApplicationId(string name)
 {
     if (string.IsNullOrWhiteSpace(name)) return null;
     using (var db = RavenSessionProvider.Get())
     {
         var application = db.Query<Application, Indexes.Application_ByName>().FirstOrDefault(app => app.Name == name);
         if (application == null)
         {
             application = new Application() { Id = Guid.NewGuid().ToString(), Name = name };
             db.Store(application);
             db.SaveChanges();
             db.ClearStaleIndexes();
         }
         return application.Id;
     }
 }