Esempio n. 1
0
        public void WhenPuttingThenGettingMultipleTimes_TheOriginalResultShouldBeTheSame()
        {
            // Arrange
            var store = new JsonStore(_rootFileLocation);
            var id    = Guid.NewGuid();
            var initialItemToStore = new StorableBase
            {
                Id         = id,
                Properties = new Dictionary <string, object>
                {
                    { "key", "value" }
                }
            };

            // Act
            _ = store.Put(initialItemToStore);
            var retrievedFirstTime = store.Get(id);

            _ = store.Put(retrievedFirstTime);
            var retrievedSecondTime = store.Get(id);

            _ = store.Put(retrievedSecondTime);
            var retrievedThirdTime = store.Get(id);

            // Assert (using serialization as a quick way to deep check the values of dictionary)
            var itemToStorePropertiesAsJson = JsonSerializer.Serialize(initialItemToStore.Properties);
            var storedPropertiesAsJson      = JsonSerializer.Serialize(retrievedThirdTime.Properties);

            Assert.Equal(initialItemToStore.Id, retrievedThirdTime.Id);
            Assert.Equal(itemToStorePropertiesAsJson, storedPropertiesAsJson);
        }
Esempio n. 2
0
        public void AfterAnObjectIsStored_RetrievingItMatches()
        {
            // Arrange
            var store       = new JsonStore(_rootFileLocation);
            var id          = Guid.NewGuid();
            var itemToStore = new StorableBase
            {
                Id         = id,
                Properties = new Dictionary <string, object>
                {
                    { "key", "value" }
                }
            };

            _ = store.Put(itemToStore);

            // Act
            var storedItem = store.Get(id);

            // Assert (using serialization as a quick way to deep check the values of dictionary)
            var itemToStorePropertiesAsJson = JsonSerializer.Serialize(itemToStore.Properties);
            var storedPropertiesAsJson      = JsonSerializer.Serialize(storedItem.Properties);

            Assert.Equal(itemToStore.Id, storedItem.Id);
            Assert.Equal(itemToStorePropertiesAsJson, storedPropertiesAsJson);
        }
Esempio n. 3
0
        public void WhenPuttingPropertiesWithComplexValueTypes_TheyAreReturnedCorrectly()
        {
            // Arrange
            var store        = new JsonStore(_rootFileLocation);
            var id           = Guid.NewGuid();
            var complexValue = new ExampleComplexSerializableType
            {
                StringValue  = "example",
                IntegerValue = 12345
            };
            var itemToStore = new StorableBase
            {
                Id         = id,
                Properties = new Dictionary <string, object>
                {
                    { "key", complexValue }
                }
            };

            // Act
            _ = store.Put(itemToStore);
            var retrievedItem = store.Get(id);

            // Assert
            var jsonKeyToCheck    = retrievedItem.Properties["key"];
            var deserializedValue = JsonSerializer.Deserialize <ExampleComplexSerializableType>(((JsonElement)jsonKeyToCheck).GetRawText());

            Assert.Equal(complexValue.StringValue, deserializedValue.StringValue);
            Assert.Equal(complexValue.IntegerValue, deserializedValue.IntegerValue);
        }
Esempio n. 4
0
        public void WhenOverwritingAnExistingObjectUsingPut_TheNewerObjectIsReturned()
        {
            // Arrange
            var store = new JsonStore(_rootFileLocation);
            var id    = Guid.NewGuid();
            var initialItemToStore = new StorableBase
            {
                Id         = id,
                Properties = new Dictionary <string, object>
                {
                    { "key", "value" }
                }
            };

            _ = store.Put(initialItemToStore);

            // Act
            var itemToStore = new StorableBase
            {
                Id         = id,
                Properties = new Dictionary <string, object>
                {
                    { "key", "newValue" }
                }
            };

            _ = store.Put(itemToStore);

            var storedItem = store.Get(id);

            // Assert
            Assert.Equal("newValue", storedItem.Properties["key"].ToString());
        }
Esempio n. 5
0
        public void WhenGettingAnObjectWhichDoesNotExist_ANotFoundExceptionIsThrown()
        {
            // Arrange
            var store = new JsonStore(_rootFileLocation);


            // Assert
            Assert.Throws <KeyNotFoundException>(() => { store.Get(Guid.NewGuid()); });
        }
Esempio n. 6
0
        public void AfterDeletingAnObject_AttemptingToGetItThrowsANotFoundException()
        {
            // Arrange
            var store = new JsonStore(_rootFileLocation);
            var id    = Guid.NewGuid();
            var initialItemToStore = new StorableBase
            {
                Id         = id,
                Properties = new Dictionary <string, object>
                {
                    { "key", "value" }
                }
            };

            _ = store.Put(initialItemToStore);

            // Act
            store.Delete(id);

            // Assert
            Assert.Throws <KeyNotFoundException>(() => { store.Get(id); });
        }