コード例 #1
0
        public void ConvertSingleRelationship()
        {
            var dto = new CatDataTransferObject
            {
                Fur = new FurDataTransferObject {
                    Description = "quite soft"
                }
            };
            var viewModel = dto.ToViewModel <CatViewModel>();

            Assert.IsNotNull(viewModel);
            Assert.IsNull(viewModel.Nickname);
            Assert.IsNull(viewModel.FavoriteFood);
            Assert.IsNotNull(viewModel.Fur);
            Assert.AreEqual(viewModel, viewModel.Fur !.ParentViewModel);
            Assert.AreEqual(viewModel, viewModel.Fur.RootViewModel);
            Assert.AreEqual(dto.Fur.Description, viewModel.Fur.Description);
            Assert.IsNull(viewModel.Paws);

            var reversedDto = viewModel.ToDto <CatDataTransferObject>();

            Assert.IsNotNull(reversedDto);
            Assert.IsNull(reversedDto.Nickname);
            Assert.IsNull(reversedDto.FavoriteFood);
            Assert.IsNotNull(reversedDto.Fur);
            Assert.AreEqual(viewModel.Fur.Description, reversedDto.Fur !.Description);
            Assert.IsNull(reversedDto.Paws);
        }
コード例 #2
0
        public void ConvertObservableRelationship()
        {
            var dto = new CatDataTransferObject
            {
                Paws = new List <PawDataTransferObject>(new[]
                {
                    new PawDataTransferObject {
                        Steps = 300
                    },
                    new PawDataTransferObject {
                        Steps = 300
                    },
                    new PawDataTransferObject {
                        Steps = 320
                    },
                    new PawDataTransferObject {
                        Steps = 320
                    }
                })
            };
            var viewModel = dto.ToViewModel <CatViewModel>();

            Assert.IsNotNull(viewModel);
            Assert.IsNull(viewModel.Nickname);
            Assert.IsNull(viewModel.FavoriteFood);
            Assert.IsNull(viewModel.Fur);
            Assert.IsNotNull(viewModel.Paws);
            Assert.AreEqual(dto.Paws.Count, viewModel.Paws !.Count);
            Assert.AreEqual(dto.Paws.ElementAt(0).Steps, viewModel.Paws[0].Steps);
            Assert.AreEqual(dto.Paws.ElementAt(1).Steps, viewModel.Paws[1].Steps);
            Assert.AreEqual(dto.Paws.ElementAt(2).Steps, viewModel.Paws[2].Steps);
            Assert.AreEqual(dto.Paws.ElementAt(3).Steps, viewModel.Paws[3].Steps);

            var reversedDto = viewModel.ToDto <CatDataTransferObject>();

            Assert.IsNotNull(reversedDto);
            Assert.IsNull(reversedDto.Nickname);
            Assert.IsNull(reversedDto.FavoriteFood);
            Assert.IsNull(reversedDto.Fur);
            Assert.IsNotNull(reversedDto.Paws);
            Assert.AreEqual(viewModel.Paws.Count, reversedDto.Paws !.Count);
            Assert.AreEqual(viewModel.Paws[0].Steps, reversedDto.Paws.ElementAt(0).Steps);
            Assert.AreEqual(viewModel.Paws[1].Steps, reversedDto.Paws.ElementAt(1).Steps);
            Assert.AreEqual(viewModel.Paws[2].Steps, reversedDto.Paws.ElementAt(2).Steps);
            Assert.AreEqual(viewModel.Paws[3].Steps, reversedDto.Paws.ElementAt(3).Steps);
        }
コード例 #3
0
        public void ConvertEmpty()
        {
            var dto       = new CatDataTransferObject();
            var viewModel = dto.ToViewModel <CatViewModel>();

            Assert.IsNotNull(viewModel);
            Assert.IsNull(viewModel.Nickname);
            Assert.IsNull(viewModel.FavoriteFood);
            Assert.IsNull(viewModel.Fur);
            Assert.IsNull(viewModel.Paws);

            var reversedDto = viewModel.ToDto <CatDataTransferObject>();

            Assert.IsNotNull(reversedDto);
            Assert.IsNull(reversedDto.Nickname);
            Assert.IsNull(reversedDto.FavoriteFood);
            Assert.IsNull(reversedDto.Fur);
            Assert.IsNull(reversedDto.Paws);
        }
コード例 #4
0
        public void ConvertSimple()
        {
            var dto = new CatDataTransferObject {
                Nickname = "Whiskers", FavoriteFood = new List <string> {
                    "Fish", "Mice"
                }
            };
            var viewModel = dto.ToViewModel <CatViewModel>();

            Assert.IsNotNull(viewModel);
            Assert.AreEqual(dto.Nickname, viewModel.Nickname);
            Assert.AreEqual(dto.FavoriteFood, viewModel.FavoriteFood);
            Assert.IsNull(viewModel.Fur);
            Assert.IsNull(viewModel.Paws);

            var reversedDto = viewModel.ToDto <CatDataTransferObject>();

            Assert.IsNotNull(reversedDto);
            Assert.AreEqual(viewModel.Nickname, reversedDto.Nickname);
            Assert.AreEqual(viewModel.FavoriteFood, reversedDto.FavoriteFood);
            Assert.IsNull(reversedDto.Fur);
            Assert.IsNull(reversedDto.Paws);
        }