コード例 #1
0
ファイル: GenericTests.cs プロジェクト: Dolfik1/Mappy
        public void Can_Map_And_Ignore_Keys_Case()
        {
            // Arrange
            var dictionary = new Dictionary <string, object>
            {
                { "CUSTOMERID", 1 },
                { "FIRSTNAME", "Bob" },
                { "LASTNAME", "Smith" },
                { "ORDERS_ORDERID", 1 },
                { "ORDERS_ORDERTOTAL", 50.50m }
            };


            var options = new MappyOptions(
                stringComparison: StringComparison.OrdinalIgnoreCase,
                useDefaultDictionaryComparer: false);


            var mappy = new Mappy(options);

            // Act
            var customer = mappy.Map <Customer>(dictionary);

            // Assert

            Assert.Equal(dictionary["CUSTOMERID"], customer.CustomerId);
            Assert.Equal(dictionary["FIRSTNAME"], customer.FirstName);
            Assert.Equal(dictionary["LASTNAME"], customer.LastName);

            Assert.Single(customer.Orders);
            Assert.Equal(dictionary["ORDERS_ORDERID"], customer.Orders.Single().OrderId);
            Assert.Equal(dictionary["ORDERS_ORDERTOTAL"], customer.Orders.Single().OrderTotal);
        }
コード例 #2
0
ファイル: IdAttributeTests.cs プロジェクト: Dolfik1/Mappy
        public void Can_Use_Custom_Identity_Attribute()
        {
            // Arrange
            var dictionary = new Dictionary <string, object>
            {
                { "SomeId", 1 },
                { "FirstName", "Bob" },
                { "LastName", "Smith" }
            };

            var dictionary2 = new Dictionary <string, object>
            {
                { "SomeId", 2 },
                { "FirstName", "Bob" },
                { "LastName", "Smith" }
            };


            var dictionary3 = new Dictionary <string, object>
            {
                { "SomeId", 2 },
                { "FirstName", "Bob" },
                { "LastName", "Smith" }
            };

            var options = new MappyOptions();
            var mappy   = new Mappy(options);

            var users = mappy.Map <User>(new List <Dictionary <string, object> >
            {
                dictionary,
                dictionary2
            }).ToList();

            Assert.Equal(2, users.Count);
            Assert.Equal(dictionary["SomeId"], users.First().SomeId);
        }