Exemplo n.º 1
0
        public void AssertPropertyValue_ProfileSaved_AllowsCheckingTheValueSet()
        {
            string   aString    = "aString";
            DateTime aDateTime  = 5.September(2011);
            TimeSpan anInterval = 4.Days();
            byte     enumB      = 1;

            new ProfileSubject("anyName")
            {
                AString       = aString,
                ANullableDate = aDateTime,
                AnEnum        = ACustomEnum.B,
                AnInterval    = anInterval
            }
            // important to save the values to the profile system
            .Save();

            ProfileTestProvider provider = (ProfileTestProvider)ProfileManager.Provider;

            provider
            .AssertPropertyValue(ProfileSubject.A_STRING, value => Assert.That(value, Is.EqualTo(aString)))
            .AssertPropertyValue(ProfileSubject.AN_ENUM, value => Assert.That(value, Is.EqualTo(enumB)))
            .AssertPropertyValue(ProfileSubject.A_NULLABLE_DATE, value => Assert.That(value, Is.EqualTo(aDateTime)))
            .AssertPropertyValue(ProfileSubject.AN_INTERVAL, value => Assert.That(value, Is.EqualTo(anInterval)));
        }
Exemplo n.º 2
0
        public void StubValues_IDictionary_PreparesValuesToBeRetrieved()
        {
            string   aString    = "aString";
            DateTime aDateTime  = 5.September(2011);
            TimeSpan anInterval = 4.Days();
            byte     enumB      = 1;

            ProfileTestProvider          provider    = (ProfileTestProvider)ProfileManager.Provider;
            IDictionary <string, object> iDictionary = new Dictionary <string, object>
            {
                { ProfileSubject.A_STRING, aString },
                { ProfileSubject.AN_ENUM, enumB },
                { ProfileSubject.A_NULLABLE_DATE, aDateTime },
                { ProfileSubject.AN_INTERVAL, anInterval }
            };

            provider.StubValues(iDictionary);

            var subject = new ProfileSubject("anyName");

            Assert.That(subject.AString, Is.EqualTo(aString));
            Assert.That(subject.AnEnum, Is.EqualTo(ACustomEnum.B));
            Assert.That(subject.ANullableDate, Is.EqualTo(aDateTime));
            Assert.That(subject.AnInterval, Is.EqualTo(anInterval));
        }
Exemplo n.º 3
0
        public void StubValues_UndefinedProperty_DoesNotThrow()
        {
            ProfileTestProvider provider = (ProfileTestProvider)ProfileManager.Provider;

            Assert.That(() => provider.StubValues(new { notDefinedInConfiguration = 3m }),
                        Throws.Nothing);
        }
Exemplo n.º 4
0
        public void AssertPropertyValue_UndefinedValue_NoException()
        {
            new ProfileSubject("anyName")
            {
                AString = "aString",
            }
            .Save();

            ProfileTestProvider provider = (ProfileTestProvider)ProfileManager.Provider;

            Assert.That(() => provider.AssertPropertyValue("notDefinedInConfiguration", _ => { }),
                        Throws.Nothing);
        }
Exemplo n.º 5
0
        public void AssertPropertyValue_ProfileNotSaved_ProviderIsNotWareOfValue()
        {
            ProfileTestProvider provider = (ProfileTestProvider)ProfileManager.Provider;

            provider.StubValues(new { AString = "previous" });
            var subject = new ProfileSubject("anyName")
            {
                AString = "set"
            };

            // subject.Save();

            provider.AssertPropertyValue(ProfileSubject.A_STRING, value => Assert.That(value, Is.Not.EqualTo("set")));
        }
Exemplo n.º 6
0
        public void Pair_HelpsToSpecifyProfileTesterStubs()
        {
            var provider = new ProfileTestProvider();

            // it does save keystrokes
            provider.StubValues(
                KeyValue.Pair("key1", 3),
                KeyValue.Pair("key2", 13.Hours()));

            // generics make it more verbose
            provider.StubValues(
                new KeyValuePair <string, object>("key1", 3),
                new KeyValuePair <string, object>("key2", 13.Hours()));
        }
Exemplo n.º 7
0
        public void Pair_HelpsToSpecifyProfileTesterStubs()
        {
            var provider = new ProfileTestProvider();

            // it does save keystrokes
            provider.StubValues(
                KeyValue.Pair("key1", 3),
                KeyValue.Pair("key2", 13.Hours()));

            // generics make it more verbose
            provider.StubValues(
                new KeyValuePair<string, object>("key1", 3),
                new KeyValuePair<string, object>("key2", 13.Hours()));
        }
Exemplo n.º 8
0
        public void AssertPropertyValue_HandlesNullProperties()
        {
            new ProfileSubject("anyName")
            {
                AString       = null,
                ANullableDate = null,
            }
            .Save();

            ProfileTestProvider provider = (ProfileTestProvider)ProfileManager.Provider;

            provider
            .AssertPropertyValue(ProfileSubject.A_STRING, value => Assert.That(value, Is.Null))
            .AssertPropertyValue(ProfileSubject.A_NULLABLE_DATE, value => Assert.That(value, Is.Null));
        }
Exemplo n.º 9
0
        public void Properties_ExposesAllNames()
        {
            new ProfileSubject("anyName")
            {
                AString       = "aString",
                ANullableDate = 5.September(2011),
                AnEnum        = ACustomEnum.B,
                AnInterval    = 4.Days()
            }
            // important to save the values to the profile system
            .Save();

            ProfileTestProvider provider = (ProfileTestProvider)ProfileManager.Provider;

            Assert.That(new[] { "AString", "ANullableDate", "AnEnum", "AnInterval" },
                        Is.SubsetOf(provider.Properties.Cast <SettingsPropertyValue>().Select(v => v.Name)));
        }
Exemplo n.º 10
0
        public void StubValues_HandlesNullValues()
        {
            ProfileTestProvider provider = (ProfileTestProvider)ProfileManager.Provider;

            provider.StubValues(
                new Dictionary <string, object>
            {
                { ProfileSubject.A_STRING, null },
                { ProfileSubject.A_NULLABLE_DATE, null }
            });

            var subject = new ProfileSubject("anyName");

            // the default value of a string property is string.Empty
            // Can be overriden by using the defaultValue attribute in the profile definition
            Assert.That(subject.AString, Is.Empty);
            Assert.That(subject.ANullableDate, Is.Null);
        }
Exemplo n.º 11
0
        public void Properties_ExposesAllValues()
        {
            string   aString    = "aString";
            DateTime aDateTime  = 5.September(2011);
            TimeSpan anInterval = 4.Days();
            byte     enumB      = 1;

            new ProfileSubject("anyName")
            {
                AString       = aString,
                ANullableDate = aDateTime,
                AnEnum        = ACustomEnum.B,
                AnInterval    = anInterval
            }
            // important to save the values to the profile system
            .Save();

            ProfileTestProvider provider = (ProfileTestProvider)ProfileManager.Provider;

            Assert.That(new object[] { aString, aDateTime, enumB, anInterval },
                        Is.SubsetOf(provider.Properties.Cast <SettingsPropertyValue>().Select(v => v.PropertyValue)));
        }
Exemplo n.º 12
0
        public void StubValues_AnonymousObject_PreparesValuesToBeRetrieved()
        {
            string   aString    = "aString";
            DateTime aDateTime  = 5.September(2011);
            TimeSpan anInterval = 4.Days();
            byte     enumB      = 1;

            ProfileTestProvider provider = (ProfileTestProvider)ProfileManager.Provider;

            provider.StubValues(new
            {
                aString,
                AnEnum        = enumB,
                ANullableDate = aDateTime,
                anInterval
            });

            var subject = new ProfileSubject("anyName");

            Assert.That(subject.AString, Is.EqualTo(aString));
            Assert.That(subject.AnEnum, Is.EqualTo(ACustomEnum.B));
            Assert.That(subject.ANullableDate, Is.EqualTo(aDateTime));
            Assert.That(subject.AnInterval, Is.EqualTo(anInterval));
        }
Exemplo n.º 13
0
 public void Setup()
 {
     ProfileTestProvider.SetAsDefault();
 }