public void It_has_certain_properties()
        {
            // Arrange
            var it = new FeatureBitEfDefinition
            {
                ExcludedEnvironments = "foo",
                LastModifiedByUser   = "******",
                IncludedEnvironments = "zissou",
                CreatedDateTime      = DateTime.Now.AddDays(-1),
                Name                          = "bat",
                CreatedByUser                 = "******",
                AllowedUsers                  = "buzz",
                Id                            = 22,
                LastModifiedDateTime          = DateTime.Now,
                MinimumAllowedPermissionLevel = 22,
                OnOff                         = true
            };

            // Act
            var validationResults = new List <ValidationResult>();

            // Assert
            Validator.TryValidateObject(it, new ValidationContext(it), validationResults, true);
            validationResults.Count.Should().Be(0);
        }
        public void It_has_MaxLength_for_certain_properties()
        {
            // Arrange
            var it = new FeatureBitEfDefinition {
                Name = "foo", CreatedByUser = "******", LastModifiedByUser = "******"
            };

            it.Name = new string('*', 101);
            it.ExcludedEnvironments = new string('*', 301);
            it.AllowedUsers         = new string('*', 2049);
            it.IncludedEnvironments = new string('*', 301);
            it.CreatedByUser        = new string('*', 101);
            it.LastModifiedByUser   = new string('*', 101);

            // Act
            var validationResults = new List <ValidationResult>();

            // Assert
            Validator.TryValidateObject(it, new ValidationContext(it), validationResults, true);
            validationResults.Should().Contain(r => r.ErrorMessage == "The field Name must be a string or array type with a maximum length of '100'.");
            validationResults.Should().Contain(r => r.ErrorMessage == "The field ExcludedEnvironments must be a string or array type with a maximum length of '300'.");
            validationResults.Should().Contain(r => r.ErrorMessage == "The field IncludedEnvironments must be a string or array type with a maximum length of '300'.");
            validationResults.Should().Contain(r => r.ErrorMessage == "The field AllowedUsers must be a string or array type with a maximum length of '2048'.");
            validationResults.Should().Contain(r => r.ErrorMessage == "The field CreatedByUser must be a string or array type with a maximum length of '100'.");
            validationResults.Should().Contain(r => r.ErrorMessage == "The field LastModifiedByUser must be a string or array type with a maximum length of '100'.");
        }
        public async Task It_throws_if_you_try_to_add_an_invalid_entity()
        {
            // Arrange
            var item1 = new FeatureBitEfDefinition {
                Name = "item1"
            };

            // Act

            // Assert
            await Assert.ThrowsAsync <InvalidDataException>(async() => await _it.AddAsync(item1));
        }
        public async Task It_throws_if_you_try_to_add_an_entity_with_a_duplicate_name()
        {
            // Arrange
            AddThreeDefinitions();
            var item1 = new FeatureBitEfDefinition {
                Name = "item1", CreatedByUser = "******", LastModifiedByUser = "******"
            };

            // Act

            // Assert
            await Assert.ThrowsAsync <DataException>(async() => await _it.AddAsync(item1));
        }
        public void It_requires_certain_properties()
        {
            // Arrange
            var it = new FeatureBitEfDefinition();
            var validationResults = new List <ValidationResult>();

            // Act
            Validator.TryValidateObject(it, new ValidationContext(it), validationResults, true);

            // Assert
            validationResults.Should().Contain(r => r.ErrorMessage == "The Name field is required.");
            validationResults.Should().Contain(r => r.ErrorMessage == "The CreatedByUser field is required.");
            validationResults.Should().Contain(r => r.ErrorMessage == "The LastModifiedByUser field is required.");
        }
        public async Task ItCanAddIFeatureBitDefinitions()
        {
            // Arrange
            var item1 = new FeatureBitEfDefinition {
                Name = "item1", CreatedByUser = "******", LastModifiedByUser = "******"
            };

            // Act
            IFeatureBitDefinition result = await _it.AddAsync(item1);

            // Assert
            result.Name.Should().Be("item1");
            result.Id.Should().NotBe(0);
            using (var context = new FeatureBitsEfDbContext(_options))
            {
                context.FeatureBitDefinitions.Should().Contain(f => f.Name == "item1");
            }
        }
        public async Task ItCanUpsertIFeatureBitDefinitions()
        {
            // Arrange
            AddThreeDefinitions();
            var defToUpsert = new FeatureBitEfDefinition
            {
                Name               = "New feature bit",
                CreatedByUser      = "******",
                LastModifiedByUser = "******"
            };

            // Act
            await _it.UpdateAsync(defToUpsert);

            // Assert
            using (var context = new FeatureBitsEfDbContext(_options))
            {
                context.FeatureBitDefinitions.Count().Should().Be(4);
                context.FeatureBitDefinitions.Should().Contain(f => f.Name == "New feature bit");
            }
        }