Ejemplo n.º 1
0
        public void PropertyValuesWithSpecialTypes()
        {
            var provider = TestObjects.GetScopeProvider(Logger);

            using (var scope = provider.CreateScope())
            {
                var repository = CreateRepository((IScopeAccessor)provider, out var contentTypeRepository, out DataTypeRepository dataTypeDefinitionRepository);

                var editor = new DecimalPropertyEditor(Logger);
                var dtd    = new DataType(editor)
                {
                    Name = "test", DatabaseType = ValueStorageType.Decimal
                };
                dataTypeDefinitionRepository.Save(dtd);

                const string decimalPropertyAlias  = "decimalProperty";
                const string intPropertyAlias      = "intProperty";
                const string dateTimePropertyAlias = "datetimeProperty";
                var          dateValue             = new DateTime(2016, 1, 6);

                var propertyTypeCollection = new PropertyTypeCollection(true,
                                                                        new List <PropertyType>
                {
                    MockedPropertyTypes.CreateDecimalProperty(decimalPropertyAlias, "Decimal property", dtd.Id),
                    MockedPropertyTypes.CreateIntegerProperty(intPropertyAlias, "Integer property"),
                    MockedPropertyTypes.CreateDateTimeProperty(dateTimePropertyAlias, "DateTime property")
                });
                var contentType = MockedContentTypes.CreateSimpleContentType("umbTextpage1", "Textpage", propertyTypeCollection);
                contentTypeRepository.Save(contentType);

                // int and decimal values are passed in as strings as they would be from the backoffice UI
                var textpage = MockedContent.CreateSimpleContentWithSpecialDatabaseTypes(contentType, "*****@*****.**", -1, "100", "150", dateValue);

                repository.Save(textpage);
                scope.Complete();

                Assert.That(contentType.HasIdentity, Is.True);
                Assert.That(textpage.HasIdentity, Is.True);

                var persistedTextpage = repository.Get(textpage.Id);
                Assert.That(persistedTextpage.Name, Is.EqualTo(textpage.Name));
                Assert.AreEqual(100m, persistedTextpage.GetValue(decimalPropertyAlias));
                Assert.AreEqual(persistedTextpage.GetValue(decimalPropertyAlias), textpage.GetValue(decimalPropertyAlias));
                Assert.AreEqual(150, persistedTextpage.GetValue(intPropertyAlias));
                Assert.AreEqual(persistedTextpage.GetValue(intPropertyAlias), textpage.GetValue(intPropertyAlias));
                Assert.AreEqual(dateValue, persistedTextpage.GetValue(dateTimePropertyAlias));
                Assert.AreEqual(persistedTextpage.GetValue(dateTimePropertyAlias), textpage.GetValue(dateTimePropertyAlias));
            }
        }