コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }