Пример #1
0
        public void ConvertAndBack()
        {
            var dto = new AwesomeTransferDataObject {
                PersonName = "John"
            };

            Assert.AreEqual("John", dto.PersonName);
            Assert.AreEqual(default(int), dto.PersonAge);

            var viewModel = dto.ToViewModel <AwesomeViewModel>();

            Assert.IsNotNull(viewModel);
            Assert.IsInstanceOfType(viewModel, typeof(AwesomeViewModel));

            if (viewModel.Name == "John")
            {
                viewModel.Age = 33;
            }
            Assert.AreEqual("John", viewModel.Name);
            Assert.AreEqual(33, viewModel.Age);

            var dto2 = viewModel.ToDto <AwesomeTransferDataObject>();

            Assert.IsNotNull(dto2);
            Assert.IsInstanceOfType(dto2, typeof(AwesomeTransferDataObject));
            Assert.AreEqual("John", dto2.PersonName);
            Assert.AreEqual(33, dto2.PersonAge);
        }
Пример #2
0
        public void ConvertAndBack()
        {
            var dto = new AwesomeTransferDataObject {
                PersonName = "John"
            };

            Assert.AreEqual("John", dto.PersonName);
            Assert.AreEqual(default, dto.PersonAge);
Пример #3
0
        public void ToViewModelExceptions()
        {
            object?dto = null;

            Assert.ThrowsException <ArgumentNullException>(() => dto !.ToViewModel <AwesomeViewModel>());

            dto = new AwesomeTransferDataObject();
            Assert.ThrowsException <InvalidOperationException>(() => dto.ToViewModel <DummyViewModel>());
            Assert.ThrowsException <InvalidCastException>(() => dto.ToViewModel <Dummy2ViewModel>());
            Assert.ThrowsException <InvalidOperationException>(() => dto.ToViewModel <Dummy3ViewModel>());
        }