Exemplo n.º 1
0
        public void TryGetShouldReturnFalseWhenItemIsNotInCollection()
        {
            // arrange
            Expression <Func <Entity, int> > property = e => e.Id;
            IAnnotationConfiguration         item;
            var collection = new AnnotationConfigurationCollection();

            // act
            var result = collection.TryGet(property.GetMediaResourceKey(), out item);

            // assert
            Assert.False(result);
            Assert.Null(item);
        }
Exemplo n.º 2
0
        public void TryGetShouldReturnTrueWhenItemIsInCollection()
        {
            // arrange
            Expression <Func <Entity, int> > property = e => e.Id;
            var configuration = new Mock <IAnnotationConfiguration>().Object;
            IAnnotationConfiguration item;
            var collection = new AnnotationConfigurationCollection();

            collection.Add(property.GetMediaResourceKey(), configuration);

            // act
            var result = collection.TryGet(property.GetMediaResourceKey(), out item);

            // assert
            Assert.True(result);
            Assert.Same(configuration, item);
        }
Exemplo n.º 3
0
        public void AddShouldNotAllowSamePropertyMoreThanOnce()
        {
            // arrange
            var expected = $"The property '{typeof( Entity ).FullName}.Id' cannot be configured as an annotation more than once.";
            Expression <Func <Entity, int> > property = e => e.Id;
            var configuration = new Mock <IAnnotationConfiguration>().Object;
            var collection    = new AnnotationConfigurationCollection();

            collection.Add(property.GetMediaResourceKey(), configuration);

            // act
            var ex     = Assert.Throws <InvalidOperationException>(() => collection.Add(property.GetMediaResourceKey(), configuration));
            var actual = ex.Message;

            // assert
            Assert.Equal(expected, actual);
        }
Exemplo n.º 4
0
        public void CollectionShouldEnumerateInExpectedOrder()
        {
            // arrange
            Expression <Func <Entity, int> >    property1 = e => e.Id;
            Expression <Func <Entity, string> > property2 = e => e.FirstName;
            Expression <Func <Entity, string> > property3 = e => e.LastName;
            var    configuration1 = new Mock <IAnnotationConfiguration>().Object;
            var    configuration2 = new Mock <IAnnotationConfiguration>().Object;
            var    configuration3 = new Mock <IAnnotationConfiguration>().Object;
            var    expected = new[] { configuration1, configuration2, configuration3 }.AsEnumerable();
            var    collection = new AnnotationConfigurationCollection();
            string name;

            // act
            collection.Add(property1.GetInstanceAnnotationKey(out name), configuration1);
            collection.Add(property2.GetInstanceAnnotationKey(out name), configuration2);
            collection.Add(property3.GetInstanceAnnotationKey(out name), configuration3);

            var actual = collection.AsEnumerable();

            // assert
            Assert.Equal(expected, actual);
        }
Exemplo n.º 5
0
        public void AddShouldAppendExpectedItemsToCollection()
        {
            // arrange
            var expected = 3;
            Expression <Func <Entity, int> >    property1 = e => e.Id;
            Expression <Func <Entity, string> > property2 = e => e.FirstName;
            Expression <Func <Entity, string> > property3 = e => e.LastName;
            var    configuration1 = new Mock <IAnnotationConfiguration>().Object;
            var    configuration2 = new Mock <IAnnotationConfiguration>().Object;
            var    configuration3 = new Mock <IAnnotationConfiguration>().Object;
            var    collection     = new AnnotationConfigurationCollection();
            string name;

            // act
            collection.Add(property1.GetInstanceAnnotationKey(out name), configuration1);
            collection.Add(property2.GetInstanceAnnotationKey(out name), configuration2);
            collection.Add(property3.GetInstanceAnnotationKey(out name), configuration3);

            var actual = collection.Count;

            // assert
            Assert.Equal(expected, actual);
        }
Exemplo n.º 6
0
        public void IndexerShouldReturnItemAtExpectedIndex()
        {
            // arrange
            Expression <Func <Entity, int> >    property1 = e => e.Id;
            Expression <Func <Entity, string> > property2 = e => e.FirstName;
            Expression <Func <Entity, string> > property3 = e => e.LastName;
            var    configuration1 = new Mock <IAnnotationConfiguration>().Object;
            var    configuration2 = new Mock <IAnnotationConfiguration>().Object;
            var    configuration3 = new Mock <IAnnotationConfiguration>().Object;
            var    expected       = new[] { configuration1, configuration2, configuration3 };
            var    collection     = new AnnotationConfigurationCollection();
            string name;

            // act
            collection.Add(property1.GetInstanceAnnotationKey(out name), configuration1);
            collection.Add(property2.GetInstanceAnnotationKey(out name), configuration2);
            collection.Add(property3.GetInstanceAnnotationKey(out name), configuration3);

            // assert
            for (var i = 0; i < expected.Length; i++)
            {
                Assert.Same(expected[i], collection[i]);
            }
        }