Ejemplo n.º 1
0
        public async Task CountersInitialize_with_EnsureDefaultCounterCreation_should_not_overwrite_existing_counters()
        {
            using (var server = GetNewServer(port: 8091))
            {
                using (var counterStore = new CounterStore
                {
                    Url = $"{server.DocumentStore.Url}:{server.Configuration.Port}",
                    Name = DefaultCounterStorageName
                })
                {
                    counterStore.Initialize(true);

                    await counterStore.IncrementAsync("G", "C");

                    await counterStore.DecrementAsync("G", "C2");
                }

                using (var counterStore = new CounterStore
                {
                    Url = $"{server.DocumentStore.Url}:{server.Configuration.Port}",
                    Name = DefaultCounterStorageName
                })
                {
                    counterStore.Initialize(true);
                    var summary = await counterStore.Admin.GetCountersByStorage(DefaultCounterStorageName);

                    Assert.Equal(2, summary.Count);
                    Assert.NotNull(summary.SingleOrDefault(x => x.Total == 1 && x.GroupName == "G" && x.CounterName == "C"));
                    Assert.NotNull(summary.SingleOrDefault(x => x.Total == -1 && x.GroupName == "G" && x.CounterName == "C2"));
                }
            }
        }
Ejemplo n.º 2
0
        public async Task When_Counter_has_apiKey_auth_then_operations_with_wrong_apiKey_should_fail()
        {
            String storeName;

            using (var store = NewRemoteCountersStore("TestStore")) //this will create the TestStore
            {
                storeName = store.Name;
                await store.IncrementAsync("G", "C");
            }

            Database.Server.Security.Authentication.EnableOnce();
            ConfigureApiKey(servers[0].SystemDatabase, "thisIsApiKeyName", "thisIsSecret", storeName);
            ConfigureApiKey(servers[0].SystemDatabase, "NotThisIsApiKeyName", "thisIsSecret", "NonExistingResourceName");

            using (var store = new CounterStore
            {
                Url = servers[0].SystemDatabase.ServerUrl,
                Name = storeName,
                Credentials = new OperationCredentials(BadApiKey, null)
            })
            {
                store.Initialize();
                var e = Assert.Throws <ErrorResponseException>(() => AsyncHelpers.RunSync(() => store.IncrementAsync("G", "C")));

                Assert.Equal(HttpStatusCode.Forbidden, e.StatusCode);
            }

            using (var store = new CounterStore
            {
                Url = servers[0].SystemDatabase.ServerUrl,
                Name = storeName,
                Credentials = new OperationCredentials(GoodApiKey, null)
            })
            {
                store.Initialize();
                Assert.DoesNotThrow(() => AsyncHelpers.RunSync(() => store.IncrementAsync("G", "C")));
            }
        }