public void GivenACustomField_WhenAdd_ThenAddToContext()
        {
            var expected = new PublicField { Id = 1 };

            Target.Add(expected);

            MockDbSet.AssertWasCalled(m => m.Add(expected));
        }
        public void GivenACustomField_WhenUpdate_ThenContextSetsModified()
        {
            var expected = new PublicField { Id = 1 };

            Target.Update(expected);

            MockContext.AssertWasCalled(m => m.SetModified(expected));
        }
        public void GivenACustomField_WhenRemove_ThenRemoveFromContext()
        {
            var item = new PublicField { Id = 1 };

            Target.Remove(item);

            MockDbSet.AssertWasCalled(m => m.Remove(item));
        }
        public void GivenPublicField_AndSortColumnIndexIs1_WhenInvokeSortSelector_ThenSortOnFieldType()
        {
            MockRequest.Expect(m => m["iSortCol_0"]).Return("1");
            string expected = "this is what I want!";
            PublicField customField = new PublicField { Name = "this is NOT what I want!!!!", CustomFieldType = new CustomFieldType { Name = expected } };
            PublicFieldClientDataTable target = new PublicFieldClientDataTable(MockRequest);

            var actual = target.SortSelector.Compile().Invoke(customField);

            Assert.AreEqual(expected, actual);
        }
        public void GivenModelNotModified_WhenCopyFrom_ThenModelStatelastModifyValuesNull()
        {
            CustomField expectedState = new PublicField
            {
                CreateTime = new DateTime(2005, 4, 30),
                CreatingUser = new User { DisplayName = "fredBob" }
            };
            CustomFieldModel target = new PublicFieldModel();

            target.CopyFrom(expectedState);

            Assert.IsNull(target.Audit.LastModifiedBy);
            Assert.IsFalse(target.Audit.LastModifyTime.HasValue);
        }
        public void GivenPublicField_WhenInvokeDataSelector_ThenIdPropertyMatches()
        {
            int expected = 7438095;
            PublicField customField = new PublicField
            {
                Id = expected,
                CustomFieldType = new CustomFieldType()
            };
            PublicFieldClientDataTable target = new PublicFieldClientDataTable(MockRequest);

            dynamic actual = target.DataSelector.Compile().Invoke(customField);

            Assert.AreEqual(expected, actual.Id);
        }
        public void GivenPublicField_WhenInvokeDataSelector_ThenCategoriesPropertyMatches()
        {
            string[] expected = new[] { "category1", "category2", "category3" };
            PublicField customField = new PublicField
            {
                Categories = expected.Select(c => new CustomFieldCategory { Name = c }).ToList(),
                CustomFieldType = new CustomFieldType()
            };
            PublicFieldClientDataTable target = new PublicFieldClientDataTable(MockRequest);

            dynamic actual = target.DataSelector.Compile().Invoke(customField);

            CollectionAssert.AreEqual(expected, ((IEnumerable<string>)actual.Categories).ToList());
        }
Example #8
0
        public void ShouldOverwriteAnArray()
        {
            var source = new PublicProperty <IEnumerable <decimal> >
            {
                Value = new[] { MinusOne, Zero }
            };

            var target = new PublicField <decimal[]>
            {
                Value = new[] { MinValue, MaxValue }
            };

            var originalTargetArray = target.Value;
            var result = Mapper.Map(source).Over(target);

            result.Value.ShouldNotBeSameAs(source.Value);
            result.Value.ShouldNotBeSameAs(originalTargetArray);
            result.Value.ShouldBe(MinusOne, Zero);
        }
Example #9
0
        public void ShouldOverwriteAndConvertACollection()
        {
            var source = new PublicProperty <IEnumerable <string> >
            {
                Value = new[] { Guid.NewGuid().ToString(), Guid.NewGuid().ToString() }
            };

            var target = new PublicField <ICollection <Guid> >
            {
                Value = new List <Guid> {
                    Guid.NewGuid(), Guid.NewGuid()
                }
            };

            var result = Mapper.Map(source).Over(target);

            result.Value.ShouldBeSameAs(target.Value);
            result.Value.ShouldBe(source.Value, r => r.ToString());
        }
        public void ShouldUseAConfiguredFactoryWithASimpleSourceType()
        {
            using (var mapper = Mapper.CreateNew())
            {
                mapper.WhenMapping
                .From <PublicField <string> >()
                .ToANew <PublicProperty <PublicCtor <string> > >()
                .Map(ctx => new PublicCtor <string>(ctx.Source.Value))
                .To(t => t.Value);

                var source = new PublicField <string> {
                    Value = "Hello!"
                };
                var result = mapper.Map(source).ToANew <PublicProperty <PublicCtor <string> > >();

                result.Value.ShouldNotBeNull();
                result.Value.Value.ShouldBe("Hello!");
            }
        }
        public void GivenModelHasAuditData_WhenCopyFrom_ThenModelStateSet()
        {
            CustomField expectedState = new PublicField
            {
                CreateTime = new DateTime(2005, 4, 30),
                CreatingUser = new User { DisplayName = "fredBob" },
                LastModifyTime = new DateTime(2010, 5, 13),
                LastModifyingUser = new User { DisplayName = "jimGeorge" }
            };
            CustomFieldModel target = new PublicFieldModel();

            target.CopyFrom(expectedState);

            AuditModel actualState = target.Audit;
            Assert.AreEqual(expectedState.CreateTime, actualState.CreateTime);
            Assert.AreEqual(expectedState.CreatingUser.DisplayName, actualState.CreatedBy);
            Assert.AreEqual(expectedState.LastModifyTime, actualState.LastModifyTime);
            Assert.AreEqual(expectedState.LastModifyingUser.DisplayName, actualState.LastModifiedBy);
        }
        public void ShouldCreateANewEnumerableOfComplexTypeArrays()
        {
            var source = new PublicField <IEnumerable <CustomerViewModel[]> >
            {
                Value = new List <CustomerViewModel[]>
                {
                    new[]
                    {
                        new CustomerViewModel {
                            Name = "Jack"
                        },
                        new CustomerViewModel {
                            Name = "Sparrow"
                        }
                    },
                    new[]
                    {
                        new CustomerViewModel {
                            Name = "Andy"
                        },
                        new CustomerViewModel {
                            Name = "Akiva"
                        },
                        new CustomerViewModel {
                            Name = "Jorma"
                        }
                    }
                }
            };

            var result = Mapper.Map(source).ToANew <PublicField <IList <ICollection <Customer> > > >();

            result.Value.Count.ShouldBe(2);

            result.Value.First().Count.ShouldBe(2);
            result.Value.First().First().Name.ShouldBe("Jack");
            result.Value.First().Second().Name.ShouldBe("Sparrow");

            result.Value.Second().Count.ShouldBe(3);
            result.Value.Second().First().Name.ShouldBe("Andy");
            result.Value.Second().Second().Name.ShouldBe("Akiva");
            result.Value.Second().Third().Name.ShouldBe("Jorma");
        }
        public void ShouldMapFromNestedMembers()
        {
            var source = new PublicField <Address>
            {
                Value = new Address
                {
                    Line1 = "One One One",
                    Line2 = "Two Two Two"
                }
            };

            var result = Mapper.Map(source).ToANew <PublicProperty <ExpandoObject> >();

            ((object)result.Value).ShouldNotBeNull();
            dynamic resultDynamic = result.Value;

            ((string)resultDynamic.Line1).ShouldBe("One One One");
            ((string)resultDynamic.Line2).ShouldBe("Two Two Two");
        }
        public void ShouldAllowACustomTargetFullEntryKeyForAnEnumerableSourceMember()
        {
            using (var mapper = Mapper.CreateNew())
            {
                mapper.WhenMapping
                .From <PublicField <int[]> >()
                .ToDictionariesWithValueType <int[]>()
                .MapMember(pf => pf.Value)
                .ToFullKey("Numbers");

                var source = new PublicField <int[]> {
                    Value = new[] { 4, 5, 6 }
                };
                var result = mapper.Map(source).ToANew <Dictionary <string, int[]> >();

                result.ShouldNotContainKey("Value");
                result["Numbers"].ShouldBe(4, 5, 6);
            }
        }
Example #15
0
        public void ShouldApplyACustomEnumerableElementPatternToASpecificSourceType()
        {
            using (var mapper = Mapper.CreateNew())
            {
                mapper.WhenMapping
                .From <Person>()
                .ToDictionaries
                .UseElementKeyPattern("(i)");

                var source = new PublicProperty <IEnumerable <Person> >
                {
                    Value = new Collection <Person>
                    {
                        new Person {
                            Name = "Sandra", Address = new Address {
                                Line1 = "Home"
                            }
                        },
                        new Person {
                            Name = "David", Address = new Address {
                                Line1 = "Home!"
                            }
                        }
                    }
                };
                var target = new PublicField <IDictionary <string, object> >
                {
                    Value = new Dictionary <string, object>()
                };
                var originalDictionary = target.Value;

                mapper.Map(source).OnTo(target);

                target.Value.ShouldBeSameAs(originalDictionary);

                target.Value["(0).Name"].ShouldBe("Sandra");
                target.Value["(0).Address.Line1"].ShouldBe("Home");

                target.Value["(1).Name"].ShouldBe("David");
                target.Value["(1).Address.Line1"].ShouldBe("Home!");
            }
        }
        public void ShouldMergeANullableIntArray()
        {
            var source = new PublicProperty <ICollection <long> >
            {
                Value = new List <long> {
                    2, 3
                }
            };

            var target = new PublicField <IList <int?> >
            {
                Value = new int?[] { 1, 2, null }
            };

            var originalArray = target.Value;
            var result        = Mapper.Map(source).OnTo(target);

            result.Value.ShouldNotBeSameAs(originalArray);
            result.Value.ShouldBe(1, 2, null, 3);
        }
        public void ShouldRestrictConfiguredConstantApplicationByTargetType()
        {
            using (var mapper = Mapper.CreateNew())
            {
                mapper.WhenMapping
                .From <PublicField <int> >()
                .To <PublicProperty <int> >()
                .Map(98765)
                .To(x => x.Value);

                var source = new PublicField <int> {
                    Value = 938726
                };
                var matchingTargetResult    = mapper.Map(source).ToANew <PublicProperty <int> >();
                var nonMatchingTargetResult = mapper.Map(source).ToANew <PublicSetMethod <int> >();

                matchingTargetResult.Value.ShouldBe(98765);
                nonMatchingTargetResult.Value.ShouldBe(source.Value);
            }
        }
Example #18
0
        public void GivenModelNotModified_AndViewModelAuditDataAlreadySet_WhenCopyFrom_ThenModelStatelastModifyValuesNull()
        {
            CustomField expectedState = new PublicField
            {
                CreateTime   = new DateTime(2005, 4, 30),
                CreatingUser = new User {
                    DisplayName = "fredBob"
                }
            };
            CustomFieldModel target = new PublicFieldModel();

            target.Audit = new AuditModel {
                LastModifiedBy = "bob", LastModifyTime = DateTime.Now
            };

            target.CopyFrom(expectedState);

            Assert.IsNull(target.Audit.LastModifiedBy);
            Assert.IsFalse(target.Audit.LastModifyTime.HasValue);
        }
Example #19
0
        public void ShouldCallAGlobalObjectCreatedCallbackWithAStruct()
        {
            using (var mapper = Mapper.CreateNew())
            {
                var createdInstance = default(object);

                mapper.After
                .CreatingInstances
                .Call(ctx => createdInstance = ctx.CreatedObject);

                var source = new PublicField <long> {
                    Value = 123456
                };
                var result = mapper.Map(source).ToANew <PublicCtorStruct <int> >();

                createdInstance.ShouldNotBeNull();
                createdInstance.ShouldBeOfType <PublicCtorStruct <int> >();
                result.Value.ShouldBe(123456);
            }
        }
Example #20
0
        public void ShouldMergeWithASpecifiedMapper()
        {
            using (var mapper = Mapper.CreateNew())
            {
                mapper.WhenMapping
                .From <PublicField <int> >()
                .OnTo <PublicField <string> >()
                .Map(ctx => ctx.Source.Value / 2)
                .To(pf => pf.Value);

                var source = new PublicField <int> {
                    Value = 20
                };
                var target = new PublicField <string>();

                source.MapUsing(mapper).OnTo(target);

                target.Value.ShouldBe("10");
            }
        }
        public void ShouldPopulateANonNullReadOnlyNestedMemberProperty()
        {
            using (var mapper = Mapper.CreateNew())
            {
                var address = new Address();

                mapper.CreateAReadOnlyPropertyUsing(address);

                var source = new PublicField <Address> {
                    Value = new Address {
                        Line1 = "Readonly populated!"
                    }
                };
                var result = mapper.Map(source).ToANew <PublicReadOnlyProperty <Address> >();

                result.Value.ShouldNotBeNull();
                result.Value.ShouldBeSameAs(address);
                result.Value.Line1.ShouldBe("Readonly populated!");
            }
        }
        public void ShouldMergeANullableGuidReadOnlyCollection()
        {
            var source = new PublicProperty <ICollection <Guid> >
            {
                Value = new List <Guid> {
                    Guid.NewGuid()
                }
            };

            var target = new PublicField <ReadOnlyCollection <Guid?> >
            {
                Value = new ReadOnlyCollection <Guid?>(new[] { Guid.Empty, default(Guid?), Guid.NewGuid() })
            };

            var originalCollection = target.Value;
            var result             = Mapper.Map(source).OnTo(target);

            result.Value.ShouldNotBeSameAs(originalCollection);
            result.Value.ShouldBe(target.Value.First(), default(Guid?), target.Value.Third(), source.Value.First());
        }
Example #23
0
        public void ShouldOverwriteWithASpecifiedMapper()
        {
            using (var mapper = Mapper.CreateNew())
            {
                mapper.WhenMapping
                .From <PublicField <int> >()
                .Over <PublicProperty <string> >()
                .Map(ctx => ctx.Source.Value + 10)
                .To(pf => pf.Value);

                var source = new PublicField <int> {
                    Value = 20
                };
                var target = new PublicProperty <string>();

                source.MapUsing(mapper).Over(target);

                target.Value.ShouldBe("30");
            }
        }
        public void ShouldMapFromNestedMembers()
        {
            var source = new PublicField <Address>
            {
                Value = new Address
                {
                    Line1 = "One One One",
                    Line2 = "Two Two Two"
                }
            };

            var result = Mapper.Map(source).ToANew <PublicProperty <ExpandoObject> >();

            Assert.NotNull(result.Value);

            dynamic resultValue = result.Value;

            Assert.Equal("One One One", resultValue.Line1);
            Assert.Equal("Two Two Two", resultValue.Line2);
        }
        public void ShouldApplyAToTargetSimpleTypeToANestedComplexTypeMember()
        {
            using (var mapper = Mapper.CreateNew())
            {
                mapper.WhenMapping
                .From <string>().To <PublicEnumerable <int> >()
                .Map(ctx => PublicEnumerable <int> .Parse(ctx.Source)).ToTarget();

                mapper.GetPlanFor <PublicField <string> >().ToANew <PublicField <PublicEnumerable <int> > >();

                var source = new PublicField <string> {
                    Value = "1,2,3"
                };
                var result = mapper.Map(source).ToANew <PublicField <PublicEnumerable <int> > >();

                result.ShouldNotBeNull();
                result.Value.ShouldNotBeNull();
                result.Value.ShouldBe(1, 2, 3);
            }
        }
        public void ShouldUseAConfiguredTwoParameterFactoryFunc()
        {
            using (var mapper = Mapper.CreateNew())
            {
                Func <long, DateTimeOffset, DateTimeOffset> factory =
                    (fileTime, existing) => DateTimeOffset.FromFileTime(fileTime);

                mapper.WhenMapping
                .From <long>()
                .To <DateTimeOffset>()
                .CreateInstancesUsing(factory);

                var source = new PublicField <long> {
                    Value = 1234567L
                };
                var result = mapper.Map(source).ToANew <PublicSetMethod <DateTimeOffset> >();

                result.Value.ShouldBe(DateTimeOffset.FromFileTime(1234567L));
            }
        }
        public void ShouldAllowOverlappingConditionalMemberSpecificDataSource()
        {
            using (var mapper = Mapper.CreateNew())
            {
                mapper.WhenMapping
                .From <PublicField <int> >().To <PublicProperty <string> >()
                .IfTargetMemberMatches(member => member.HasType <string>())
                .Map((pf, pp) => pf.Value == 1 ? "Yes" : "No")
                .ToTarget();

                mapper.WhenMapping
                .From <PublicField <int> >().To <PublicProperty <string> >()
                .If(ctx => ctx.Source.Value >= 100)
                .Map((pf, pp) => pf.Value >= 200 ? "JAH" : "NOPE")
                .To(pp => pp.Value);

                var matcherYesSource = new PublicField <int> {
                    Value = 1
                };
                var matcherYesResult = mapper.Map(matcherYesSource).ToANew <PublicProperty <string> >();
                matcherYesResult.Value.ShouldBe("Yes");

                var matcherNoSource = new PublicField <int> {
                    Value = 0
                };
                var matcherNoResult = mapper.Map(matcherNoSource).ToANew <PublicProperty <string> >();
                matcherNoResult.Value.ShouldBe("No");

                var dataSourceYesSource = new PublicField <int> {
                    Value = 1000
                };
                var dataSourceYesResult = mapper.Map(dataSourceYesSource).ToANew <PublicProperty <string> >();
                dataSourceYesResult.Value.ShouldBe("JAH");

                var dataSourceNoSource = new PublicField <int> {
                    Value = 150
                };
                var dataSourceNoResult = mapper.Map(dataSourceNoSource).ToANew <PublicProperty <string> >();
                dataSourceNoResult.Value.ShouldBe("NOPE");
            }
        }
        public void ShouldApplyACustomEnumerableElementPatternToASpecificDerivedSourceType()
        {
            using (var mapper = Mapper.CreateNew())
            {
                mapper.WhenMapping
                .From <Customer>()
                .ToDynamics
                .UseElementKeyPattern("(i)");

                var source = new PublicProperty <IEnumerable <Person> >
                {
                    Value = new List <Person>
                    {
                        new Person {
                            Name = "Sandra", Address = new Address {
                                Line1 = "Home"
                            }
                        },
                        new Customer {
                            Name = "David", Address = new Address {
                                Line1 = "Home!"
                            }
                        }
                    }
                };
                var originalExpando = new ExpandoObject();
                var target          = new PublicField <dynamic> {
                    Value = originalExpando
                };

                var result = (IDictionary <string, object>)mapper.Map(source).OnTo(target).Value;

                result.ShouldBeSameAs(originalExpando);

                result["_0_Name"].ShouldBe("Sandra");
                result["_0_Address_Line1"].ShouldBe("Home");

                result["(1)_Name"].ShouldBe("David");
                result["(1)_Address_Line1"].ShouldBe("Home!");
            }
        }
Example #29
0
        public void ShouldMapAComplexTypeEnumerableMemberFromItsSourceType()
        {
            var source = new PublicField <object>
            {
                Value = new Collection <object>
                {
                    new Customer {
                        Name = "Fred"
                    },
                    new Person {
                        Name = "Bob"
                    }
                }
            };
            var result = Mapper.Map(source).ToANew <PublicSetMethod <object> >();

            var resultValues = ((IEnumerable)result.Value).Cast <Person>().ToArray();

            resultValues.First().ShouldBeOfType <Customer>();
            resultValues.Second().ShouldBeOfType <Person>();
        }
        public void ShouldApplyACustomConfiguredMember()
        {
            using (var mapper = Mapper.CreateNew())
            {
                mapper.WhenMapping
                .FromDynamics
                .Over <PublicField <long> >()
                .Map((d, pf) => d.Count)
                .To(pf => pf.Value);

                dynamic source = new ExpandoObject();
                source.One = 1;
                source.Two = 2;

                var target = new PublicField <long>();

                mapper.Map(source).Over(target);

                Assert.Equal(2, target.Value);
            }
        }
        public void ShouldIgnoreSourcePropertiesByMemberTypeAndSourceType()
        {
            using (var mapper = Mapper.CreateNew())
            {
                mapper.WhenMapping
                .From <PublicProperty <string> >()
                .IgnoreSourceMembersWhere(member => member.IsProperty);

                var nonMatchingSource = new PublicField <string> {
                    Value = "xyz"
                };
                var nonMatchingResult = mapper.Map(nonMatchingSource).ToANew <PublicProperty <string> >();
                nonMatchingResult.Value.ShouldBe("xyz");

                var matchingSource = new PublicProperty <string> {
                    Value = "zyx"
                };
                var matchingResult = mapper.Map(matchingSource).ToANew <PublicField <string> >();
                matchingResult.Value.ShouldBeDefault();
            }
        }
Example #32
0
        public void ShouldHandleAnObjectMappingDataCreationException()
        {
            var thrownException = Should.Throw <MappingException>(() =>
            {
                using (var mapper = Mapper.CreateNew())
                {
                    mapper.After.MappingEnds.Call(Console.WriteLine);

                    var source = new PublicField <Product> {
                        Value = new Product()
                    };

                    mapper.Map(source).ToANew <ExceptionThrower <Product> >();
                }
            });

            thrownException.InnerException.ShouldNotBeNull();

            // ReSharper disable once PossibleNullReferenceException
            thrownException.InnerException.Message.ShouldContain("An exception occurred mapping");
        }
        public void ShouldMapADictionaryObjectValuesToNewDictionaryObjectValues()
        {
            var source = new PublicField <Dictionary <string, object> >()
            {
                Value = new Dictionary <string, object>
                {
                    ["key1"] = new object(),
                    ["key2"] = new object()
                }
            };

            var result = Mapper.Map(source).ToANew <PublicProperty <Dictionary <string, object> > >();

            result.Value.ShouldNotBeNull();
            result.Value.ShouldContainKey("key1");
            result.Value["key1"].ShouldBeOfType <object>();
            result.Value["key1"].ShouldNotBeSameAs(source.Value["key1"]);
            result.Value.ShouldContainKey("key2");
            result.Value["key2"].ShouldBeOfType <object>();
            result.Value["key2"].ShouldNotBeSameAs(source.Value["key2"]);
        }
        public void ShouldOverwriteAnIReadOnlyCollectionCollection()
        {
            var source = new PublicProperty <IEnumerable <decimal> >
            {
                Value = new[] { MinusOne, Zero }
            };

            var target = new PublicField <IReadOnlyCollection <decimal> >
            {
                Value = new Collection <decimal>(new[] { MinValue, MaxValue })
            };

            var preMappingCollection = target.Value;

            var result = Mapper.Map(source).Over(target);

            // (Collection<decimal> as ICollection<decimal>).IsReadOnly == true, so the
            // Collection does not get reused:
            result.Value.ShouldNotBeSameAs(preMappingCollection);
            result.Value.ShouldBe(MinusOne, Zero);
        }
        public void ShouldMapAToTargetEnumerableProjectionResultToANestedEnumerable()
        {
            using (var mapper = Mapper.CreateNew())
            {
                mapper.WhenMapping
                .From <Address[]>()
                .ToANew <Address[]>()
                .Map(ctx => ctx.Source.Select(CreateAddress).ToArray())
                .ToTarget();

                var source = new PublicField <Address[]>
                {
                    Value = new[]
                    {
                        new Address {
                            Line1 = "My house"
                        },
                        new Address {
                            Line1 = "Your house"
                        }
                    }
                };

                _addressCreationCount = 0;

                var result = mapper.Map(source).ToANew <PublicProperty <Address[]> >();

                result.Value.ShouldNotBeNull().Length.ShouldBe(4);
                result.Value.First().Line1.ShouldBe("My house");
                result.Value.First().Line2.ShouldBeNull();
                result.Value.Second().Line1.ShouldBe("Your house");
                result.Value.Second().Line2.ShouldBeNull();
                result.Value.Third().Line1.ShouldBe("Address 1");
                result.Value.Third().Line2.ShouldBe("My house");
                result.Value.Fourth().Line1.ShouldBe("Address 2");
                result.Value.Fourth().Line2.ShouldBe("Your house");

                _addressCreationCount.ShouldBe(2);
            }
        }
        public void ShouldUseACustomFullDictionaryKeyForANestedMember()
        {
            using (var mapper = Mapper.CreateNew())
            {
                mapper.WhenMapping
                .FromDictionaries
                .OnTo <PublicField <PublicProperty <decimal> > >()
                .MapFullKey("BoomDiddyMcBoom")
                .To(pf => pf.Value.Value);

                var source = new Dictionary <string, string> {
                    ["BoomDiddyMcBoom"] = "6476338"
                };
                var target = new PublicField <PublicProperty <decimal> >
                {
                    Value = new PublicProperty <decimal>()
                };
                var result = mapper.Map(source).OnTo(target);

                result.Value.Value.ShouldBe(6476338.00m);
            }
        }
        public void ShouldApplyACustomEnumerableElementPatternToASpecificTargetType()
        {
            using (var mapper = Mapper.CreateNew())
            {
                mapper.WhenMapping
                .Dictionaries
                .UseMemberNameSeparator("-")
                .UseElementKeyPattern("i")
                .AndWhenMapping
                .FromDictionariesWithValueType <string>()
                .OnTo <Address>()
                .MapMemberNameKey("StreetName")
                .To(a => a.Line1)
                .And
                .MapMemberNameKey("CityName")
                .To(a => a.Line2);

                var source = new Dictionary <string, string>
                {
                    ["Value0-StreetName"] = "Street Zero",
                    ["Value0-CityName"]   = "City Zero",
                    ["Value1-StreetName"] = "Street One",
                    ["Value1-CityName"]   = "City One"
                };

                var target = new PublicField <IEnumerable <Address> > {
                    Value = new List <Address>()
                };
                var result = mapper.Map(source).OnTo(target);

                result.Value.Count().ShouldBe(2);

                result.Value.First().Line1.ShouldBe("Street Zero");
                result.Value.First().Line2.ShouldBe("City Zero");

                result.Value.Second().Line1.ShouldBe("Street One");
                result.Value.Second().Line2.ShouldBe("City One");
            }
        }
        public void ShouldMapNestedMultiplyRecursiveRelationships()
        {
            var recursorOne = new MultipleRecursor {
                Name = "One"
            };
            var recursorTwo = new MultipleRecursor {
                Name = "Two"
            };

            recursorOne.ChildRecursor = recursorTwo;
            recursorTwo.ChildRecursor = recursorOne;

            var source = new PublicField <MultipleRecursor[]>
            {
                Value = new[] { recursorOne, recursorTwo }
            };

            var result = Mapper.Map(source).ToANew <PublicField <ReadOnlyCollection <MultipleRecursor> > >();

            result.ShouldNotBeNull();
            result.Value.Count.ShouldBe(2);

            var resultOne = result.Value.First();

            resultOne.ShouldNotBeSameAs(recursorOne);
            resultOne.Name.ShouldBe("One");
            resultOne.ChildRecursor.ShouldNotBeNull();
            resultOne.ChildRecursor.ShouldNotBeSameAs(recursorTwo);

            var resultTwo = result.Value.Second();

            resultTwo.ShouldNotBeSameAs(recursorTwo);
            resultTwo.Name.ShouldBe("Two");
            resultTwo.ChildRecursor.ShouldNotBeNull();
            resultTwo.ChildRecursor.ShouldNotBeSameAs(recursorOne);

            resultOne.ChildRecursor.ShouldBeSameAs(resultTwo);
            resultTwo.ChildRecursor.ShouldBeSameAs(resultOne);
        }
        private static void AddTypeField(
            IHTMLDiv parent,
            CompilationField type,
            Action<string> UpdateLocation
            )
        {
            var div = new IHTMLDiv().AttachTo(parent);

            div.style.marginTop = "0.1em";
            div.style.fontFamily = ScriptCoreLib.JavaScript.DOM.IStyle.FontFamilyEnum.Verdana;
            div.style.whiteSpace = ScriptCoreLib.JavaScript.DOM.IStyle.WhiteSpaceEnum.nowrap;


            var i = new PublicField().AttachTo(div);

            i.style.verticalAlign = "middle";
            i.style.marginRight = "0.5em";

            var s = new IHTMLAnchor { innerText = type.Name }.AttachTo(div);


            s.href = "#";
            s.style.textDecoration = "none";
            s.style.color = JSColor.System.WindowText;

            Action onclick = delegate
            {

            };

            s.onclick +=
                e =>
                {
                    e.PreventDefault();

                    s.focus();

                    UpdateLocation(type.Name);

                    onclick();
                };

            s.onfocus +=
                delegate
                {

                    s.style.backgroundColor = JSColor.System.Highlight;
                    s.style.color = JSColor.System.HighlightText;
                };

            s.onblur +=
                delegate
                {

                    s.style.backgroundColor = JSColor.None;
                    s.style.color = JSColor.System.WindowText;
                };


            onclick =
                delegate
                {
                    //var children = new IHTMLDiv().AttachTo(div);

                    //children.style.paddingLeft = "2em";

                    //a.GetTypes().ForEach(
                    //    (Current, Next) =>
                    //    {
                    //        AddType(GetNamespaceContainer(children, Current), Current, UpdateLocation);

                    //        ScriptCoreLib.Shared.Avalon.Extensions.AvalonSharedExtensions.AtDelay(
                    //            50,
                    //            Next
                    //        );
                    //    }
                    //);


                    var NextClickHide = default(Action);
                    var NextClickShow = default(Action);

                    NextClickHide =
                        delegate
                        {
                            //children.Hide();

                            onclick = NextClickShow;
                        };

                    NextClickShow =
                        delegate
                        {
                            //children.Show();

                            onclick = NextClickHide;
                        };


                    onclick = NextClickHide;
                };
        }
 private static bool AssertPropertiesMatch(PublicFieldModel expectedState, PublicField actualState)
 {
     Assert.IsNotNull(actualState);
     Assert.AreEqual(expectedState.FieldName, actualState.Name);
     Assert.AreEqual(expectedState.SelectedFieldTypeId, actualState.CustomFieldTypeId);
     CollectionAssert.AreEqual(expectedState.SelectedCategories.ToList(), actualState.Categories.Select(c => c.Id).ToList());
     return true;
 }
        public void WhenConstruct_ThenCreateTimeSet()
        {
            PublicField actual = new PublicField();

            Assert.IsTrue(actual.CreateTime.WithinTimeSpanOf(TimeSpan.FromMilliseconds(20), DateTime.Now));
        }
        public void WhenConstruct_ThenCategoriesNotNull()
        {
            var actual = new PublicField();

            Assert.IsNotNull(actual.Categories);
        }
 private List<CustomField> LoadCustomFieldList(Type t, EducationSecurityPrincipal user)
 {
     List<CustomField> customFields = new List<CustomField>();
     var studentIdField = new PublicField
     {
         Name = "Student Id"
     };
     MethodInfo generic = typeof(Queryable).GetMethod("OfType").MakeGenericMethod(new Type[] { t });
     var result = (IEnumerable<object>) generic.Invoke(null, new object[] { CustomFieldRepository.Items.OrderBy(c => c.Name) });
     var fields = result.OfType<CustomField>().ToList();
     foreach (var field in fields)
     {
         IPermission permission = PermissionFactory.Current.Create("UploadCustomFieldData", field);
         if (permission.TryGrantAccess(user))
         {
             customFields.Add(field);
         }
     }
     customFields.Insert(0, studentIdField);
     return customFields;
 }
        public void GivenPublicField_WhenInvokeDataSelector_ThenTypePropertyMatches()
        {
            string expected = "field type";
            PublicField customField = new PublicField
            {
                CustomFieldType = new CustomFieldType { Name = expected }
            };
            PublicFieldClientDataTable target = new PublicFieldClientDataTable(MockRequest);

            dynamic actual = target.DataSelector.Compile().Invoke(customField);

            Assert.AreEqual(expected, actual.Type);
        }
        public void GivenInvalidModel_WhenCopyFrom_ThenThrowException()
        {
            PublicField invalid = new PublicField { CreatingUser = new User() };

            Target.ExpectException<ArgumentException>(() => Target.CopyFrom(invalid));
        }
        public void GivenInvalidModel_WhenCopyTo_ThenThrowException()
        {
            PublicField invalid = new PublicField();

            Target.ExpectException<ArgumentException>(() => Target.CopyTo(invalid));
        }
        public void GivenPublicField_WhenInvokeSortSelector_ThenSortOnName()
        {
            string expected = "this is what I want!";
            PublicField customField = new PublicField { Name = expected };
            PublicFieldClientDataTable target = new PublicFieldClientDataTable(MockRequest);

            var actual = target.SortSelector.Compile().Invoke(customField);

            Assert.AreEqual(expected, actual);
        }