Exemplo n.º 1
0
        public void Tasks_CreateTask_TaskCreated()
        {
            var resp = CreateTask();

            Assert.IsTrue(resp.Succeeded);
            Assert.IsTrue(_taskRecords.Contains(x => x.Name.Equals(TaskName)));
        }
Exemplo n.º 2
0
 public bool Exists(string userId)
 {
     return(_userRecords.Contains(x => x.Id.Matches(userId)));
 }
Exemplo n.º 3
0
        public async Task BasicTest()
        {
            IEntityStore <Key, Value> entityStore = this.GetEntityStore <Key, Value>("basicTestEntity");
            await entityStore.Put(new Key { Type = "A", Id = 1 }, new Value { Prop1 = "Foo", Prop2 = 10 });

            await entityStore.Put(new Key { Type = "A", Id = 2 }, new Value { Prop1 = "Foo", Prop2 = 20 });

            await entityStore.Put(new Key { Type = "A", Id = 3 }, new Value { Prop1 = "Foo", Prop2 = 30 });

            await entityStore.Put(new Key { Type = "B", Id = 1 }, new Value { Prop1 = "Bar", Prop2 = 10 });

            await entityStore.Put(new Key { Type = "B", Id = 2 }, new Value { Prop1 = "Bar", Prop2 = 20 });

            await entityStore.Put(new Key { Type = "B", Id = 3 }, new Value { Prop1 = "Bar", Prop2 = 30 });

            //act/assert to validate key.
            Option <(Key key, Value value)> itemRetrieved = await entityStore.GetFirstEntry();

            Assert.True(itemRetrieved.HasValue);
            itemRetrieved.ForEach(
                pair =>
            {
                Assert.Equal("A", pair.key.Type);
                Assert.Equal(1, pair.key.Id);
            });


            itemRetrieved = await entityStore.GetLastEntry();

            Assert.True(itemRetrieved.HasValue);
            itemRetrieved.ForEach(
                pair =>
            {
                Assert.Equal("B", pair.key.Type);
                Assert.Equal(3, pair.key.Id);
            });

            Option <Value> optionValue1 = await entityStore.Get(new Key { Type = "A", Id = 1 });

            Assert.True(optionValue1.HasValue);
            Value value1 = optionValue1.OrDefault();

            Assert.Equal("Foo", value1.Prop1);
            Assert.Equal(10, value1.Prop2);

            Option <Value> optionValue2 = await entityStore.Get(new Key { Type = "B", Id = 3 });

            Assert.True(optionValue2.HasValue);
            Value value2 = optionValue2.OrDefault();

            Assert.Equal("Bar", value2.Prop1);
            Assert.Equal(30, value2.Prop2);

            Assert.True(await entityStore.Contains(new Key {
                Type = "B", Id = 2
            }));
            Assert.False(await entityStore.Contains(new Key {
                Type = "B", Id = 4
            }));

            await entityStore.Remove(new Key { Type = "A", Id = 1 });

            Assert.False(await entityStore.Contains(new Key {
                Type = "A", Id = 1
            }));
            Assert.False((await entityStore.Get(new Key {
                Type = "A", Id = 1
            })).HasValue);
        }
Exemplo n.º 4
0
        public async Task SmokeTest()
        {
            // Arrange
            IEncryptionProvider                 encryptionProvider = new TestEncryptionProvider();
            IEntityStore <string, string>       entityStore        = GetEntityStore <string, string>("smokeTest");
            IKeyValueStore <string, TestDevice> encryptedStore     = new UpdatableEncryptedStore <string, TestDevice>(entityStore, encryptionProvider);
            string key       = "device1";
            var    device    = new TestDevice(Guid.NewGuid().ToString(), new KeyAuth(Guid.NewGuid().ToString()));
            var    deviceNew = new TestDevice(Guid.NewGuid().ToString(), new KeyAuth(Guid.NewGuid().ToString()));

            // Act / Assert
            bool contains = await encryptedStore.Contains("device1");

            Assert.False(contains);
            contains = await entityStore.Contains("device1");

            Assert.False(contains);

            // Add a value to the underlying store and make sure encrypted store returns it correctly
            await entityStore.Put(key, device.ToJson());

            contains = await encryptedStore.Contains("device1");

            Assert.True(contains);
            contains = await entityStore.Contains("device1");

            Assert.True(contains);

            Option <TestDevice> retrievedValue = await encryptedStore.Get("device1");

            Assert.True(retrievedValue.HasValue);
            Assert.Equal(device.GenId, retrievedValue.OrDefault().GenId);
            Assert.Equal(device.Auth.Key, retrievedValue.OrDefault().Auth.Key);

            Option <string> storedValue = await entityStore.Get("device1");

            Assert.True(storedValue.HasValue);
            TestDevice storedTestDevice = storedValue.OrDefault().FromJson <TestDevice>();

            Assert.Equal(device.GenId, storedTestDevice.GenId);
            Assert.Equal(device.Auth.Key, storedTestDevice.Auth.Key);

            // Add a value to the encrypted store and make sure underlying store sees the encrypted value
            await encryptedStore.Put(key, deviceNew);

            contains = await encryptedStore.Contains("device1");

            Assert.True(contains);

            retrievedValue = await encryptedStore.Get("device1");

            Assert.True(retrievedValue.HasValue);
            Assert.Equal(deviceNew.GenId, retrievedValue.OrDefault().GenId);
            Assert.Equal(deviceNew.Auth.Key, retrievedValue.OrDefault().Auth.Key);

            storedValue = await entityStore.Get("device1");

            Assert.True(storedValue.HasValue);

            string encryptedDeviceJson = Convert.ToBase64String(Encoding.UTF8.GetBytes(deviceNew.ToJson()));
            var    encryptedData       = new UpdatableEncryptedStore <string, TestDevice> .EncryptedData(true, encryptedDeviceJson);

            Assert.Equal(encryptedData.ToJson(), storedValue.OrDefault());

            retrievedValue = await encryptedStore.Get("device2");

            Assert.False(retrievedValue.HasValue);

            await encryptedStore.Remove("device1");

            contains = await encryptedStore.Contains("device1");

            Assert.False(contains);

            retrievedValue = await encryptedStore.Get("device1");

            Assert.False(retrievedValue.HasValue);
        }