public void ConvertToDomainTypeTest()
        {
            var databaseUser = new DbModels.User {
                Id          = Guid.NewGuid(),
                FirstName   = "test",
                LastName    = "test",
                Country     = "UK",
                City        = "London",
                Street      = "Baker street",
                HouseNumber = "221B"
            };

            var databaseTask = new DbModels.Task {
                Id     = Guid.NewGuid(),
                Name   = "test",
                Time   = DateTime.Now,
                User   = databaseUser,
                UserId = databaseUser.Id
            };

            var mockUserMapper = new Mock <IUserDatabaseMapper>();

            var mockContext = new Mock <IDataContext>();

            var mapper = new TaskDatabaseMapper(mockUserMapper.Object);

            var result = mapper.ConvertToDomainType(databaseTask, mockContext.Object);

            Assert.AreEqual(databaseTask.Id, result.Id);
            Assert.AreEqual(databaseTask.Name, result.Name);
            Assert.AreEqual(databaseTask.Time, result.Time);
            Assert.AreEqual(databaseTask.User.Id, result.User.Id);
        }
        public void ConvertToDomainTypeWithLoadedUserTest()
        {
            var databaseUser = new DbModels.User {
                Id          = Guid.NewGuid(),
                FirstName   = "test",
                LastName    = "test",
                Country     = "UK",
                City        = "London",
                Street      = "Baker street",
                HouseNumber = "221B"
            };

            var databaseTask = new DbModels.Task {
                Id     = Guid.NewGuid(),
                Name   = "test",
                Time   = DateTime.Now,
                User   = databaseUser,
                UserId = databaseUser.Id
            };

            var mockContext = new Mock <IDataContext>();

            mockContext.Setup(x => x.IsLoaded(databaseTask, y => y.User)).Returns(true);

            var mockUserMapper = new Mock <IUserDatabaseMapper>();

            mockUserMapper.Setup(x => x.ConvertToDomainType(databaseTask.User, mockContext.Object))
            .Returns(new Domain.User.User {
                Id        = databaseTask.User.Id,
                FirstName = databaseTask.User.FirstName,
                LastName  = databaseTask.User.LastName,
                Address   = new Address {
                    Country     = databaseTask.User.Country,
                    City        = databaseTask.User.City,
                    Street      = databaseTask.User.Street,
                    HouseNumber = databaseTask.User.HouseNumber
                }
            });

            var mapper = new TaskDatabaseMapper(mockUserMapper.Object);

            var result = mapper.ConvertToDomainType(databaseTask, mockContext.Object);

            Assert.AreEqual(databaseTask.Id, result.Id);
            Assert.AreEqual(databaseTask.Name, result.Name);
            Assert.AreEqual(databaseTask.Time, result.Time);
            Assert.AreEqual(databaseTask.User.Id, result.User.Id);
            Assert.AreEqual(databaseTask.User.FirstName, result.User.FirstName);
            Assert.AreEqual(databaseTask.User.LastName, result.User.LastName);
            Assert.AreEqual(databaseTask.User.Country, result.User.Address.Country);
            Assert.AreEqual(databaseTask.User.City, result.User.Address.City);
            Assert.AreEqual(databaseTask.User.Street, result.User.Address.Street);
            Assert.AreEqual(databaseTask.User.HouseNumber, result.User.Address.HouseNumber);
        }
Beispiel #3
0
        public Domain.Task.Task ConvertToDomainType(DbModels.Task databaseType, IDataContext context)
        {
            var result = new Domain.Task.Task {
                Id   = databaseType.Id,
                Name = databaseType.Name,
                Time = databaseType.Time,
                User = new Domain.User.User {
                    Id = databaseType.UserId
                }
            };

            if (context.IsLoaded(databaseType, x => x.User))
            {
                result.User = _userMapper.ConvertToDomainType(databaseType.User, context);
            }

            return(result);
        }