Beispiel #1
0
        public void GetBy_MustOnlyReturnConfigurationDataBelongingToGroup()
        {
            var groupId        = Guid.NewGuid();
            var configuration1 = new FeatureConfigurationStub {
                GroupId = groupId
            };
            var configuration2 = new FeatureConfigurationStub {
                GroupId = Guid.NewGuid()
            };
            var configuration3 = new FeatureConfigurationStub {
                GroupId = groupId
            };
            var configuration4 = new FeatureConfigurationStub {
                GroupId = Guid.NewGuid()
            };

            sut.Save(configuration1);
            sut.Save(configuration2);
            sut.Save(configuration3);
            sut.Save(configuration4);

            var configurations = sut.GetBy(groupId);

            Assert.AreEqual(2, configurations.Count);
            Assert.AreEqual(configurations[0].GroupId, groupId);
            Assert.AreEqual(configurations[1].GroupId, groupId);
            Assert.IsTrue(configurations.Any(c => c.Id == configuration1.Id));
            Assert.IsFalse(configurations.Any(c => c.Id == configuration2.Id));
            Assert.IsTrue(configurations.Any(c => c.Id == configuration3.Id));
            Assert.IsFalse(configurations.Any(c => c.Id == configuration4.Id));
        }
Beispiel #2
0
        public void GetAll_MustReturnAllConfigurationData()
        {
            var configuration1 = new FeatureConfigurationStub {
                GroupId = Guid.NewGuid()
            };
            var configuration2 = new FeatureConfigurationStub {
                GroupId = Guid.Empty
            };
            var configuration3 = new FeatureConfigurationStub {
                GroupId = Guid.Empty
            };
            var configuration4 = new FeatureConfigurationStub {
                GroupId = Guid.NewGuid()
            };

            sut.Save(configuration1);
            sut.Save(configuration2);
            sut.Save(configuration3);
            sut.Save(configuration4);

            var configurations = sut.GetAllConfigurations();

            Assert.AreEqual(4, configurations.Count);
            Assert.AreEqual(configurations[0].GroupId, configuration1.GroupId);
            Assert.AreEqual(configurations[1].GroupId, configuration2.GroupId);
            Assert.AreEqual(configurations[2].GroupId, configuration3.GroupId);
            Assert.AreEqual(configurations[3].GroupId, configuration4.GroupId);
            Assert.IsTrue(configurations.Any(c => c.Id == configuration1.Id));
            Assert.IsTrue(configurations.Any(c => c.Id == configuration2.Id));
            Assert.IsTrue(configurations.Any(c => c.Id == configuration3.Id));
            Assert.IsTrue(configurations.Any(c => c.Id == configuration4.Id));
        }
Beispiel #3
0
        public void Delete_MustDeleteFileIfEmpty()
        {
            var configuration = new FeatureConfigurationStub();

            sut.Save(configuration);
            Assert.IsTrue(File.Exists(filePath));

            sut.Delete(configuration);
            Assert.IsFalse(File.Exists(filePath));
        }
Beispiel #4
0
        public void Delete_MustNotFailIfDataNotInBackup()
        {
            var configuration = new FeatureConfigurationStub();

            sut.Delete(configuration);

            sut.Save(new FeatureConfigurationStub());
            sut.Save(new FeatureConfigurationStub());
            sut.Save(new FeatureConfigurationStub());

            sut.Delete(configuration);
        }
Beispiel #5
0
        public void Save_MustSaveGivenData()
        {
            var configuration = new FeatureConfigurationStub();

            sut.Save(configuration);

            Assert.IsTrue(File.Exists(filePath));

            using (var stream = File.Open(filePath, FileMode.Open))
            {
                Assert.IsInstanceOfType(new BinaryFormatter().Deserialize(stream), typeof(IList <IFeatureConfiguration>));
            }
        }
Beispiel #6
0
        public void Save_MustNotOverwriteExistingData()
        {
            var configuration1 = new FeatureConfigurationStub();
            var configuration2 = new FeatureConfigurationStub();
            var configuration3 = new FeatureConfigurationStub();
            var configuration4 = new FeatureConfigurationStub();
            var configuration5 = new FeatureConfigurationStub();

            sut.Save(configuration1);
            sut.Save(configuration2);
            sut.Save(configuration3);

            Assert.AreEqual(3, sut.GetAllConfigurations().Count);

            sut.Save(configuration4);
            sut.Save(configuration5);

            Assert.AreEqual(5, sut.GetAllConfigurations().Count);
        }
Beispiel #7
0
        public void Delete_MustOnlyRemoveGivenData()
        {
            var configuration1 = new FeatureConfigurationStub();
            var configuration2 = new FeatureConfigurationStub();
            var configuration3 = new FeatureConfigurationStub();
            var toDelete       = new FeatureConfigurationStub();

            sut.Save(configuration1);
            sut.Save(configuration2);
            sut.Save(toDelete);
            sut.Save(configuration3);
            sut.Delete(toDelete);

            var configurations = sut.GetAllConfigurations();

            Assert.AreEqual(3, configurations.Count);
            Assert.IsFalse(configurations.Any(c => c.Id == toDelete.Id));
            Assert.IsTrue(configurations.Any(c => c.Id == configuration1.Id));
            Assert.IsTrue(configurations.Any(c => c.Id == configuration2.Id));
            Assert.IsTrue(configurations.Any(c => c.Id == configuration3.Id));
        }