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());
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 6
0
        public void Ctor_WhenStringNotOnFirstLevel_ThrowsSisoDbException()
        {
            var parent     = StructurePropertyTestFactory.GetRawProperty <Container>("NestedWithString");
            var idProperty = StructurePropertyTestFactory.GetRawProperty <StringDummy>("StructureId", parent);

            var ex = Assert.Throws <SisoDbException>(() => new IdAccessor(idProperty));

            Assert.AreEqual(ExceptionMessages.IdAccessor_InvalidLevel, ex.Message);
        }
Exemplo n.º 7
0
        public void GetValue_FromUnAssignedNullableGuidProperty_ReturnsNull()
        {
            var item     = new NullableGuidDummy();
            var property = StructurePropertyTestFactory.GetIdProperty <NullableGuidDummy>();

            var idAccessor    = new IdAccessor(property);
            var idViaAccessor = idAccessor.GetValue(item);

            Assert.IsTrue(idViaAccessor.IsEmpty);
        }
Exemplo n.º 8
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);
        }
        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);
        }
Exemplo n.º 10
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 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);
        }
        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);
        }
Exemplo n.º 14
0
        public void SetValue_ToNullableGuidProperty_ValueIsAssigned()
        {
            var id   = StructureId.Create(Guid.Parse("fc47a673-5a5b-419b-9a40-a756591aa7bf"));
            var item = new NullableGuidDummy();

            var property   = StructurePropertyTestFactory.GetIdProperty <NullableGuidDummy>();
            var idAccessor = new IdAccessor(property);

            idAccessor.SetValue(item, id);

            Assert.AreEqual(id.Value, item.StructureId);
        }
Exemplo n.º 15
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();
        }
Exemplo n.º 16
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);
        }
Exemplo n.º 17
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);
        }
        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);
        }
Exemplo n.º 19
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);
        }
Exemplo n.º 20
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);
        }
Exemplo n.º 21
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);
        }
Exemplo n.º 22
0
        public void SetValue_ToStringProperty_ValueIsAssigned()
        {
            var id   = StructureId.Create("Foo string id");
            var item = new StringDummy();

            var property   = StructurePropertyTestFactory.GetIdProperty <StringDummy>();
            var idAccessor = new IdAccessor(property);

            idAccessor.SetValue(item, id);

            Assert.AreEqual(id.Value, item.StructureId);
        }
Exemplo n.º 23
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);
        }
Exemplo n.º 24
0
        public void SetValue_of_long_ToNullableLongIdentityProperty_ValueIsAssigned()
        {
            var id   = StructureId.Create((long)42);
            var item = new NullableBigIdentityDummy();

            var property   = StructurePropertyTestFactory.GetIdProperty <NullableBigIdentityDummy>();
            var idAccessor = new IdAccessor(property);

            idAccessor.SetValue(item, id);

            Assert.AreEqual(id.Value, item.StructureId);
        }
Exemplo n.º 25
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);
        }
Exemplo n.º 26
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);
        }
Exemplo n.º 27
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);
        }
Exemplo n.º 28
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);
        }
Exemplo n.º 29
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);
        }
Exemplo n.º 30
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);
        }