public void GetValues_WhenDeepGraphWithEnumerables_CanExtractValues()
        {
            var prodNoProperty = StructurePropertyTestFactory.GetPropertyByPath <TestCustomer>("Orders.Lines.ProductNo");
            var pricesProperty = StructurePropertyTestFactory.GetPropertyByPath <TestCustomer>("Orders.Lines.Prices");

            var graph = new TestCustomer
            {
                Orders =
                {
                    new TestOrder
                    {
                        Lines =
                        {
                            new TestOrderLine {
                                ProductNo = "P1", Quantity = 1, Prices = new[]{                                  42, 4242 }
                            },
                            new TestOrderLine {
                                ProductNo = "P2", Quantity = 2, Prices = new[]{                                  43, 4343 }
                            }
                        }
                    }
                }
            };

            var productNos = IndexAccessorTestFactory.CreateFor(prodNoProperty).GetValues(graph);
            var prices     = IndexAccessorTestFactory.CreateFor(pricesProperty).GetValues(graph);

            CollectionAssert.AreEqual(new[] { "P1", "P2" }, productNos.Select(i => i.Value).ToArray());
            CollectionAssert.AreEqual(new[] { 42, 4242, 43, 4343 }, prices.Select(i => i.Value).ToArray());
        }
예제 #2
0
        public void Ctor_WhenMemberIsNotGuidIntOrLong_ThrowsException()
        {
            var concTokenProperty = StructurePropertyTestFactory.GetPropertyByPath <ModelWithStringMember>("ConcurrencyToken");

            var ex = Assert.Throws <SisoDbException>(() => new ConcurrencyTokenAccessor(concTokenProperty));

            Assert.AreEqual(ExceptionMessages.ConcurrencyTokenAccessor_Invalid_Type.Inject(concTokenProperty.Name), ex.Message);
        }
예제 #3
0
        public void Ctor_WhenMemberIsNotDateTime_ThrowsException()
        {
            var timeStampProperty = StructurePropertyTestFactory.GetPropertyByPath <ModelWithStringMember>(TimeStampMemberName);

            var ex = Assert.Throws <SisoDbException>(() => new TimeStampAccessor(timeStampProperty));

            Assert.AreEqual(ExceptionMessages.TimeStampAccessor_Invalid_Type.Inject(timeStampProperty.Name), ex.Message);
        }
예제 #4
0
        public void Ctor_WhenMemberIsNotOnRootLevel_ThrowsException()
        {
            var timeStampProperty = StructurePropertyTestFactory.GetPropertyByPath <ModelWithMemberNotInRoot>("NestedModelItem.TimeStamp");

            var ex = Assert.Throws <SisoDbException>(() => new TimeStampAccessor(timeStampProperty));

            Assert.AreEqual(ExceptionMessages.TimeStampAccessor_InvalidLevel.Inject(timeStampProperty.Name), ex.Message);
        }
예제 #5
0
        public void Ctor_WhenMemberIsNotOnRootLevel_ThrowsException()
        {
            var concTokenProperty = StructurePropertyTestFactory.GetPropertyByPath <ModelWithMemberNotInRoot>("NestedModelItem.ConcurrencyToken");

            var ex = Assert.Throws <SisoDbException>(() => new ConcurrencyTokenAccessor(concTokenProperty));

            Assert.AreEqual(ExceptionMessages.ConcurrencyTokenAccessor_InvalidLevel.Inject(concTokenProperty.Name), ex.Message);
        }
예제 #6
0
        public void GetValue_WhenUnAssignedNullableBool_ReturnsNull()
        {
            var item = new Dummy {
                NullableBool1 = null
            };
            var property = StructurePropertyTestFactory.GetPropertyByPath <Dummy>("NullableBool1");

            var actual = property.GetValue(item);

            Assert.IsNull(actual);
        }
예제 #7
0
        public void GetIdValue_WhenNullAssignedNullableGuidOnFirstLevel_ReturnsNull()
        {
            var item = new NullableGuidOnRoot {
                StructureId = null
            };
            var property = StructurePropertyTestFactory.GetPropertyByPath <NullableGuidOnRoot>("StructureId");

            var actual = property.GetValue(item);

            Assert.IsNull(actual);
        }
        public void GetValue_WhenArrayOfInt_ReturnsAValueArray()
        {
            var property = StructurePropertyTestFactory.GetPropertyByPath <TestCustomer>("Points");

            var container = new TestCustomer {
                Points = new[] { 5, 4, 3, 2, 1 }
            };
            var values = (IEnumerable <int>)property.GetValue(container);

            CollectionAssert.AreEqual(new[] { 5, 4, 3, 2, 1 }, values.ToArray());
        }
        public void GetIdValue_WhenNullAssignedNullableIntOnFirstLevel_ReturnsInt()
        {
            var item = new NullableIdentityOnRoot {
                Value = null
            };
            var property = StructurePropertyTestFactory.GetPropertyByPath <NullableIdentityOnRoot>("Value");

            var actual = property.GetValue(item);

            Assert.IsNull(actual);
        }
        public void GetValue_WhenSingleStringMember_SingleValueIsReturned()
        {
            var property = StructurePropertyTestFactory.GetPropertyByPath <TestCustomer>("CustomerNo");

            var customer = new TestCustomer {
                CustomerNo = "1234"
            };
            var customerNos = (string)property.GetValue(customer);

            Assert.AreEqual("1234", customerNos);
        }
예제 #11
0
        public void GetValue_WhenAssignedInt_ReturnsAssignedValue()
        {
            const int expected = 33;
            var       item     = new Dummy {
                Int1 = expected
            };
            var property = StructurePropertyTestFactory.GetPropertyByPath <Dummy>("Int1");

            var actual = property.GetValue(item);

            Assert.AreEqual(expected, actual);
        }
예제 #12
0
        public void GetValue_WhenAssignedNullableBool_ReturnsAssignedValue()
        {
            const bool expected = true;
            var        item     = new Dummy {
                NullableBool1 = expected
            };
            var property = StructurePropertyTestFactory.GetPropertyByPath <Dummy>("NullableBool1");

            var actual = property.GetValue(item);

            Assert.AreEqual(expected, actual);
        }
예제 #13
0
        public void GetIdValue_WhenGuidOnFirstLevel_ReturnsGuid()
        {
            var expected = Guid.Parse("4217F3B7-6DEB-4DFA-B195-D111C1297988");
            var item     = new GuidOnRoot {
                StructureId = expected
            };
            var property = StructurePropertyTestFactory.GetPropertyByPath <GuidOnRoot>("StructureId");

            var actual = property.GetValue(item);

            Assert.AreEqual(expected, actual);
        }
예제 #14
0
        public void GetIdValue_WhenNullableIntOnFirstLevel_ReturnsInt()
        {
            const int expectedInt = 42;
            var       item        = new NullableIdentityOnRoot {
                StructureId = expectedInt
            };
            var property = StructurePropertyTestFactory.GetPropertyByPath <NullableIdentityOnRoot>("StructureId");

            var actual = property.GetValue(item);

            Assert.AreEqual(expectedInt, actual);
        }
        public void GetValues_WhenSubItemsArrayIsNull_ReturnsNull()
        {
            var item = new Item {
                SubItems = null
            };
            var valueProp     = StructurePropertyTestFactory.GetPropertyByPath <Item>("SubItems.Value");
            var indexAccessor = IndexAccessorTestFactory.CreateFor(valueProp);

            var value = indexAccessor.GetValues(item);

            Assert.AreEqual(new string[] { null }, value);
        }
예제 #16
0
        public void GetValue_WhenNoAssignedNullableDateTimeExists_ReturnsNulledNullableDateTime()
        {
            var timeStampProperty = StructurePropertyTestFactory.GetPropertyByPath <ModelWithNullableDateTime>(TimeStampMemberName);
            var accessor          = new TimeStampAccessor(timeStampProperty);
            var model             = new ModelWithNullableDateTime {
                TimeStamp = null
            };

            var timeStamp = accessor.GetValue(model);

            Assert.IsNull(timeStamp);
        }
예제 #17
0
        public void GetValue_WhenAssignedDecimal_ReturnsAssignedValue()
        {
            const decimal expected = 1.33m;
            var           item     = new Dummy {
                Decimal1 = expected
            };
            var property = StructurePropertyTestFactory.GetPropertyByPath <Dummy>("Decimal1");

            var actual = property.GetValue(item);

            Assert.AreEqual(expected, actual);
        }
        public void GetIdValue_WhenIntOnFirstLevel_ReturnsInt()
        {
            const int expected = 42;
            var       item     = new IdentityOnRoot {
                Value = expected
            };
            var property = StructurePropertyTestFactory.GetPropertyByPath <IdentityOnRoot>("Value");

            var actual = property.GetValue(item);

            Assert.AreEqual(expected, actual);
        }
예제 #19
0
        public void GetValues_WhenSubItemsArrayIsNull_ReturnsNull()
        {
            var item = new Item {
                SubItems = null
            };
            var valueProp     = StructurePropertyTestFactory.GetPropertyByPath <Item>("SubItems.Value");
            var indexAccessor = IndexAccessorTestFactory.CreateFor(valueProp);

            var value = indexAccessor.GetValues(item);

            value.Should().BeNull();
        }
예제 #20
0
        public void GetValue_FromAssignedDateTime_ReturnsAssignedDateTime()
        {
            var initialValue = new DateTime(2010, 2, 3);
            var item         = new Dummy {
                DateTimeProp = initialValue
            };
            var property      = StructurePropertyTestFactory.GetPropertyByPath <Dummy>("DateTimeProp");
            var indexAccessor = IndexAccessorTestFactory.CreateFor(property);

            var retrievedValues = indexAccessor.GetValues(item);

            CollectionAssert.AreEqual(new[] { initialValue }, retrievedValues);
        }
예제 #21
0
        public void GetValues_FromAssignedString_ReturnsAssignedString()
        {
            const string initialValue = "Hello tester!";
            var          item         = new Dummy {
                StringProp = initialValue
            };
            var property      = StructurePropertyTestFactory.GetPropertyByPath <Dummy>("StringProp");
            var indexAccessor = IndexAccessorTestFactory.CreateFor(property);

            var retrievedValues = indexAccessor.GetValues(item);

            CollectionAssert.AreEqual(new[] { initialValue }, retrievedValues);
        }
예제 #22
0
        public void GetValues_FromNullableDecimalWithNullValue_ReturnsNull()
        {
            decimal?initialValue = null;
            var     item         = new Dummy {
                NullableDecimalProp = initialValue
            };
            var property      = StructurePropertyTestFactory.GetPropertyByPath <Dummy>("NullableDecimalProp");
            var indexAccessor = IndexAccessorTestFactory.CreateFor(property);

            var retrievedValues = indexAccessor.GetValues(item);

            Assert.IsNull(retrievedValues);
        }
예제 #23
0
        public void GetValues_FromAssignedNullableDecimal_ReturnsAssignedNullableDecimal()
        {
            decimal?initialValue = 13.34M;
            var     item         = new Dummy {
                NullableDecimalProp = initialValue
            };
            var property      = StructurePropertyTestFactory.GetPropertyByPath <Dummy>("NullableDecimalProp");
            var indexAccessor = IndexAccessorTestFactory.CreateFor(property);

            var retrievedValues = indexAccessor.GetValues(item);

            CollectionAssert.AreEqual(new[] { initialValue.GetValueOrDefault() }, retrievedValues);
        }
예제 #24
0
        public void GetValues_FromAssignedDecimal_ReturnsAssignedDecimal()
        {
            const decimal initialValue = 12.56M;
            var           item         = new Dummy {
                DecimalProp = initialValue
            };
            var property      = StructurePropertyTestFactory.GetPropertyByPath <Dummy>("DecimalProp");
            var indexAccessor = IndexAccessorTestFactory.CreateFor(property);

            var retrievedValues = indexAccessor.GetValues(item);

            CollectionAssert.AreEqual(new[] { initialValue }, retrievedValues);
        }
예제 #25
0
        public void GetValues_FromNullString_ReturnsNullString()
        {
            const string initialValue = null;
            var          item         = new Dummy {
                StringProp = initialValue
            };
            var property      = StructurePropertyTestFactory.GetPropertyByPath <Dummy>("StringProp");
            var indexAccessor = IndexAccessorTestFactory.CreateFor(property);

            var retrievedValues = indexAccessor.GetValues(item);

            Assert.IsNull(retrievedValues);
        }
예제 #26
0
        public void GetValue_WhenNoAssignedDateTimeExists_ReturnsMinValueDateTime()
        {
            var timeStampProperty = StructurePropertyTestFactory.GetPropertyByPath <ModelWithDateTime>(TimeStampMemberName);
            var accessor          = new TimeStampAccessor(timeStampProperty);
            var initialValue      = default(DateTime);
            var model             = new ModelWithDateTime {
                TimeStamp = initialValue
            };

            var timeStamp = accessor.GetValue(model);

            Assert.AreEqual(initialValue, timeStamp);
        }
예제 #27
0
        public void GetValue_WhenAssignedNullableDateTimeExists_ReturnsAssignedValue()
        {
            var timeStampProperty = StructurePropertyTestFactory.GetPropertyByPath <ModelWithNullableDateTime>(TimeStampMemberName);
            var accessor          = new TimeStampAccessor(timeStampProperty);
            var initialValue      = new DateTime(1970, 12, 13, 01, 02, 03);
            var model             = new ModelWithNullableDateTime {
                TimeStamp = initialValue
            };

            var timeStamp = accessor.GetValue(model);

            Assert.AreEqual(initialValue, timeStamp);
        }
        public void GetValues_FromAssignedInt_ReturnsAssignedInt()
        {
            const int initialValue = 12345;
            var       item         = new Dummy {
                IntProp = initialValue
            };
            var property      = StructurePropertyTestFactory.GetPropertyByPath <Dummy>("IntProp");
            var indexAccessor = IndexAccessorTestFactory.CreateFor(property);

            var retrievedValues = indexAccessor.GetValues(item);

            CollectionAssert.AreEqual(new[] { initialValue }, retrievedValues.Select(i => i.Value).ToArray());
        }
        public void SetValue_WhenAssigningPrimitiveValueToNonNullNullableProp_ValueIsAssigned()
        {
            const int newValue = 42;
            var       item     = new Item {
                NullableIntProp = 1
            };
            var property      = StructurePropertyTestFactory.GetPropertyByPath <Item>("NullableIntProp");
            var indexAccessor = IndexAccessorTestFactory.CreateFor(property);

            indexAccessor.SetValue(item, newValue);

            Assert.AreEqual(newValue, item.NullableIntProp);
        }
        public void SetValue_WhenAssigningStringValueToNullProp_ValueIsAssigned()
        {
            const string newValue = "Test";
            var          item     = new Item {
                StringProp = null
            };
            var property      = StructurePropertyTestFactory.GetPropertyByPath <Item>("StringProp");
            var indexAccessor = IndexAccessorTestFactory.CreateFor(property);

            indexAccessor.SetValue(item, newValue);

            Assert.AreEqual(newValue, item.StringProp);
        }