Esempio n. 1
0
        public async Task AddNewValueToConfiguration_ShouldAddTheNewValue_WhenConfigurationExists()
        {
            // arrange
            var key      = _fixture.Create <string>();
            var version  = _fixture.Create <Version>();
            var dataType = _fixture.Create <ValueType>().ToString();
            var valueId  = _fixture.Create <Guid>();
            var data     = _fixture.Create <string>();
            var sequence = _fixture.Create <int>();
            var tags     = _fixture.CreateMany <string>().ToList();

            _sut =
                new InMemoryConfigurationRepository(new Dictionary
                                                    <string, Tuple <string, IDictionary <Version, IList <Tuple <Guid, int, string, IEnumerable <string> > > > > >
            {
                {
                    key,
                    new Tuple <string, IDictionary <Version, IList <Tuple <Guid, int, string, IEnumerable <string> > > > >(
                        dataType,
                        new Dictionary <Version, IList <Tuple <Guid, int, string, IEnumerable <string> > > >
                    {
                        { version, new List <Tuple <Guid, int, string, IEnumerable <string> > >() }
                    })
                }
            });

            var createdAt = DateTime.UtcNow;

            var expected = new StoredConfig
            {
                Type   = dataType,
                Values = new List <StoredConfigValues>
                {
                    new StoredConfigValues
                    {
                        Id              = valueId,
                        Sequence        = 1,
                        EnvironmentTags = tags,
                        Data            = data,
                        CreatedAt       = createdAt
                    }
                }
            };

            // act
            await _sut
            .AddNewValueToConfiguration(key, version, valueId, tags, data, createdAt)
            .ConfigureAwait(false);

            // assert
            (await _sut
             .GetConfiguration(key, version)
             .ConfigureAwait(false))
            .ShouldBeEquivalentTo(
                expected,
                options => options
                .Excluding((ISubjectInfo si) => si.SelectedMemberInfo.Name == "CreatedAt"));
        }
Esempio n. 2
0
        public void AddNewValueToConfiguration_ShouldThrowException_WhenConfigurationDoesNotExist()
        {
            // arrange
            var key      = _fixture.Create <string>();
            var version  = _fixture.Create <Version>();
            var dataType = _fixture.Create <ValueType>().ToString();
            var valueId  = _fixture.Create <Guid>();
            var data     = _fixture.Create <string>();
            var tags     = _fixture.CreateMany <string>().ToList();

            var unknownKey = _fixture.Create <string>();

            _sut =
                new InMemoryConfigurationRepository(new Dictionary
                                                    <string, Tuple <string, IDictionary <Version, IList <Tuple <Guid, int, string, IEnumerable <string> > > > > >
            {
                {
                    key,
                    new Tuple <string, IDictionary <Version, IList <Tuple <Guid, int, string, IEnumerable <string> > > > >(
                        dataType,
                        new Dictionary <Version, IList <Tuple <Guid, int, string, IEnumerable <string> > > >
                    {
                        { version, new List <Tuple <Guid, int, string, IEnumerable <string> > >() }
                    })
                }
            });


            Func <Task> exceptionThrower = async() => await _sut
                                           .AddNewValueToConfiguration(unknownKey, version, valueId, tags, data, DateTime.UtcNow)
                                           .ConfigureAwait(false);

            // act/assert
            exceptionThrower
            .ShouldThrow <ArgumentException>();
        }