public void Verify_MapToModel_AssignsPersonProperties()
        {
            // Arrange
            var mapper = new PersonMapper();
            var entity = PeopleMockingSetup.DoMockingSetupForPerson();
            // Act
            var model = mapper.MapToModel(entity.Object);

            // Assert
            Assert.Equal(entity.Object.Hometown, model.Hometown);
            Assert.Equal(entity.Object.Country, model.Country);
            Assert.Equal(entity.Object.Email, model.Email);
            Assert.Equal(entity.Object.Website, model.Website);
            Assert.Equal(entity.Object.BirthDate, model.BirthDate);
            Assert.Equal(entity.Object.DeathDate, model.DeathDate);
            // Related Objects
            Assert.Equal(entity.Object.PrimaryImageFileId, model.PrimaryImageFileId);
            Assert.Equal(entity.Object.GenderId, model.GenderId);
            // Associated Objects
            Assert.Equal(entity.Object.CharactersCreated?.Count, model.CharactersCreated?.Count);
            Assert.Equal(entity.Object.PersonAliases?.Count, model.PersonAliases?.Count);
            Assert.Equal(entity.Object.IssuesWritten?.Count, model.IssuesWritten?.Count);
            Assert.Equal(entity.Object.MoviesProduced?.Count, model.MoviesProduced?.Count);
            Assert.Equal(entity.Object.MoviesWritten?.Count, model.MoviesWritten?.Count);
            Assert.Equal(entity.Object.PromosWritten?.Count, model.PromosWritten?.Count);
            Assert.Equal(entity.Object.StoryArcsWritten?.Count, model.StoryArcsWritten?.Count);
            Assert.Equal(entity.Object.VolumesWritten?.Count, model.VolumesWritten?.Count);
        }
        public void Verify_AreEqual_WithDifferentObjects_ReturnsFalse()
        {
            // Arrange
            var mapper = new PersonMapper();
            var model  = PeopleMockingSetup.DoMockingSetupForPersonModel(1);
            var entity = PeopleMockingSetup.DoMockingSetupForPerson(2);
            // Act
            var result = mapper.AreEqual(model.Object, entity.Object);

            // Assert
            Assert.False(result);
        }
        public void Verify_MapToSearchModelExtension_CallsMapToModel()
        {
            // Arrange
            var mockMapper = new Mock <PersonMapper>();

            mockMapper.Setup(x => x.MapToSearchModel(It.IsAny <IPersonModel>()));
            var mockModel = PeopleMockingSetup.DoMockingSetupForPersonModel(1);

            PersonMapperExtensions.OverrideMapper(mockMapper.Object);
            // Act
            mockModel.Object.MapToSearchModel();
            // Assert
            mockMapper.Verify(x => x.MapToSearchModel(It.IsAny <IPersonModel>()), Times.Once);
        }
        public void Verify_MapToModelListingExtension_CallsMapToModel()
        {
            // Arrange
            var mockMapper = new Mock <PersonMapper>();

            mockMapper.Setup(x => x.MapToModelListing(It.IsAny <IPerson>(), It.IsAny <int>()));
            var mockEntity = PeopleMockingSetup.DoMockingSetupForPerson(1);

            PersonMapperExtensions.OverrideMapper(mockMapper.Object);
            // Act
            mockEntity.Object.MapToModelListing();
            // Assert
            mockMapper.Verify(x => x.MapToModelListing(It.IsAny <IPerson>(), It.IsAny <int>()), Times.Once);
        }
        public void Verify_AreEqualExtension_CallsAreEqual()
        {
            // Arrange
            var mockMapper = new Mock <PersonMapper>();

            mockMapper.Setup(x => x.AreEqual(It.IsAny <IPersonModel>(), It.IsAny <IPerson>()));
            PersonMapperExtensions.OverrideMapper(mockMapper.Object);
            var mockModel  = PeopleMockingSetup.DoMockingSetupForPersonModel(1);
            var mockEntity = PeopleMockingSetup.DoMockingSetupForPerson(1);

            // Act
            mockModel.Object.AreEqual(mockEntity.Object);
            // Assert
            mockMapper.Verify(x => x.AreEqual(It.IsAny <IPersonModel>(), It.IsAny <IPerson>()), Times.Once);
        }
        public void Verify_MapToModelLite_AssignsLiteOnlyPersonProperties()
        {
            // Arrange
            var mapper = new PersonMapper();
            var entity = PeopleMockingSetup.DoMockingSetupForPerson();
            // Act
            var model = mapper.MapToModelLite(entity.Object);

            // Assert
            Assert.Equal(entity.Object.Hometown, model.Hometown);
            Assert.Equal(entity.Object.Country, model.Country);
            Assert.Equal(entity.Object.Email, model.Email);
            Assert.Equal(entity.Object.Website, model.Website);
            Assert.Equal(entity.Object.BirthDate, model.BirthDate);
            Assert.Equal(entity.Object.DeathDate, model.DeathDate);
            // Related Objects
            Assert.Equal(entity.Object.PrimaryImageFileId, model.PrimaryImageFileId);
            Assert.Equal(entity.Object.GenderId, model.GenderId);
        }
        public void Verify_MapToEntity_WithExistingEntity_AssignsPersonProperties()
        {
            // Arrange
            var mapper = new PersonMapper();
            var model  = PeopleMockingSetup.DoMockingSetupForPersonModel();
            // Act
            IPerson existingEntity = new Person {
                Id = 1
            };

            mapper.MapToEntity(model.Object, ref existingEntity);
            // Assert
            Assert.Equal(model.Object.Hometown, existingEntity.Hometown);
            Assert.Equal(model.Object.Country, existingEntity.Country);
            Assert.Equal(model.Object.Email, existingEntity.Email);
            Assert.Equal(model.Object.Website, existingEntity.Website);
            Assert.Equal(model.Object.BirthDate, existingEntity.BirthDate);
            Assert.Equal(model.Object.DeathDate, existingEntity.DeathDate);
            // Related Objects
            Assert.Equal(model.Object.PrimaryImageFileId, existingEntity.PrimaryImageFileId);
            Assert.Equal(model.Object.GenderId, existingEntity.GenderId);
            // Associated Objects
            model.VerifyGet(x => x.CharactersCreated, Times.Once);
            //Assert.Equal(model.Object.CharactersCreated?.Count, existingEntity.CharactersCreated?.Count);
            model.VerifyGet(x => x.PersonAliases, Times.Once);
            //Assert.Equal(model.Object.PersonAliases?.Count, existingEntity.PersonAliases?.Count);
            model.VerifyGet(x => x.IssuesWritten, Times.Once);
            //Assert.Equal(model.Object.IssuesWritten?.Count, existingEntity.IssuesWritten?.Count);
            model.VerifyGet(x => x.MoviesProduced, Times.Once);
            //Assert.Equal(model.Object.MoviesProduced?.Count, existingEntity.MoviesProduced?.Count);
            model.VerifyGet(x => x.MoviesWritten, Times.Once);
            //Assert.Equal(model.Object.MoviesWritten?.Count, existingEntity.MoviesWritten?.Count);
            model.VerifyGet(x => x.PromosWritten, Times.Once);
            //Assert.Equal(model.Object.PromosWritten?.Count, existingEntity.PromosWritten?.Count);
            model.VerifyGet(x => x.StoryArcsWritten, Times.Once);
            //Assert.Equal(model.Object.StoryArcsWritten?.Count, existingEntity.StoryArcsWritten?.Count);
            model.VerifyGet(x => x.VolumesWritten, Times.Once);
            //Assert.Equal(model.Object.VolumesWritten?.Count, existingEntity.VolumesWritten?.Count);
        }
        public void Verify_MapToSearchModel_AssignsPersonSearchProperties()
        {
            // Arrange
            var mapper = new PersonMapper();
            var model  = PeopleMockingSetup.DoMockingSetupForPersonModel();
            // Act
            var searchModel = mapper.MapToSearchModel(model.Object);

            // Assert
            Assert.Equal(model.Object.PrimaryImageFileId, searchModel.PrimaryImageFileId);
            Assert.Equal(model.Object.PrimaryImageFile?.CustomKey, searchModel.PrimaryImageFileCustomKey);
            Assert.Equal(model.Object.PrimaryImageFile?.ApiDetailUrl, searchModel.PrimaryImageFileApiDetailUrl);
            Assert.Equal(model.Object.PrimaryImageFile?.SiteDetailUrl, searchModel.PrimaryImageFileSiteDetailUrl);
            Assert.Equal(model.Object.PrimaryImageFile?.Name, searchModel.PrimaryImageFileName);
            Assert.Equal(model.Object.PrimaryImageFile?.ShortDescription, searchModel.PrimaryImageFileShortDescription);
            Assert.Equal(model.Object.PrimaryImageFile?.Description, searchModel.PrimaryImageFileDescription);
            Assert.Equal(model.Object.GenderId, searchModel.GenderId);
            Assert.Equal(model.Object.Gender?.CustomKey, searchModel.GenderCustomKey);
            Assert.Equal(model.Object.Gender?.ApiDetailUrl, searchModel.GenderApiDetailUrl);
            Assert.Equal(model.Object.Gender?.SiteDetailUrl, searchModel.GenderSiteDetailUrl);
            Assert.Equal(model.Object.Gender?.Name, searchModel.GenderName);
            Assert.Equal(model.Object.Gender?.ShortDescription, searchModel.GenderShortDescription);
            Assert.Equal(model.Object.Gender?.Description, searchModel.GenderDescription);
        }