public ITeamAliasModel Update(ITeamAliasModel model) { // Validate model BusinessWorkflowBase.ValidateRequiredNullableID(model.Id); //BusinessWorkflowBase.ValidateRequiredString(model.Name, nameof(model.Name)); // Find existing entity // ReSharper disable once PossibleInvalidOperationException var existingEntity = TeamAliasesRepository.Get(model.Id.Value); // Check if we would be applying identical information, if we are, just return the original // ReSharper disable once SuspiciousTypeConversion.Global if (TeamAliasMapper.AreEqual(model, existingEntity)) { return(TeamAliasMapper.MapToModel(existingEntity)); } // Map model to an existing entity TeamAliasMapper.MapToEntity(model, ref existingEntity); existingEntity.UpdatedDate = BusinessWorkflowBase.GenDateTime; // Update it TeamAliasesRepository.Update(TeamAliasMapper.MapToEntity(model)); // Try to Save Changes TeamAliasesRepository.SaveChanges(); // Return the new value return(Get(existingEntity.Id)); }
public ITeamAliasModel Create(ITeamAliasModel model) { // Validate model BusinessWorkflowBase.ValidateIDIsNull(model.Id); //BusinessWorkflowBase.ValidateRequiredString(model.Name, nameof(model.Name)); // Search for an Existing Record (Don't allow Duplicates var results = Search(TeamAliasMapper.MapToSearchModel(model)); if (results.Any()) { return(results.First()); } // Return the first that matches // Map model to a new entity var newEntity = TeamAliasMapper.MapToEntity(model); newEntity.CreatedDate = BusinessWorkflowBase.GenDateTime; newEntity.UpdatedDate = null; newEntity.Active = true; // Add it TeamAliasesRepository.Add(newEntity); // Try to Save Changes TeamAliasesRepository.SaveChanges(); // Return the new value return(Get(newEntity.Id)); }
public void Verify_AreEqual_WithEqualObjects_ReturnsTrue() { // Arrange var mapper = new TeamAliasMapper(); var model = TeamAliasesMockingSetup.DoMockingSetupForTeamAliasModel(1); var entity = TeamAliasesMockingSetup.DoMockingSetupForTeamAlias(1); // Act var result = mapper.AreEqual(model.Object, entity.Object); // Assert Assert.True(result); }
public void Verify_AreEqual_WithDifferentObjects_ReturnsFalse() { // Arrange var mapper = new TeamAliasMapper(); var model = TeamAliasesMockingSetup.DoMockingSetupForTeamAliasModel(1); var entity = TeamAliasesMockingSetup.DoMockingSetupForTeamAlias(2); // Act var result = mapper.AreEqual(model.Object, entity.Object); // Assert Assert.False(result); }
public void Verify_MapToModelLite_AssignsLiteOnlyTeamAliasProperties() { // Arrange var mapper = new TeamAliasMapper(); var entity = TeamAliasesMockingSetup.DoMockingSetupForTeamAlias(); // Act var model = mapper.MapToModelLite(entity.Object); // Assert // <None> // Related Objects Assert.Equal(entity.Object.TeamId, model.TeamId); }
public void Verify_MapToEntity_AssignsTeamAliasProperties() { // Arrange var mapper = new TeamAliasMapper(); var model = TeamAliasesMockingSetup.DoMockingSetupForTeamAliasModel(); // Act var entity = mapper.MapToEntity(model.Object); // Assert // <None> // Related Objects Assert.Equal(model.Object.TeamId, entity.TeamId); // Associated Objects // <None> }
public void Verify_MapToSearchModel_AssignsTeamAliasSearchProperties() { // Arrange var mapper = new TeamAliasMapper(); var model = TeamAliasesMockingSetup.DoMockingSetupForTeamAliasModel(); // Act var searchModel = mapper.MapToSearchModel(model.Object); // Assert Assert.Equal(model.Object.TeamId, searchModel.TeamId); Assert.Equal(model.Object.Team?.CustomKey, searchModel.TeamCustomKey); Assert.Equal(model.Object.Team?.ApiDetailUrl, searchModel.TeamApiDetailUrl); Assert.Equal(model.Object.Team?.SiteDetailUrl, searchModel.TeamSiteDetailUrl); Assert.Equal(model.Object.Team?.Name, searchModel.TeamName); Assert.Equal(model.Object.Team?.ShortDescription, searchModel.TeamShortDescription); Assert.Equal(model.Object.Team?.Description, searchModel.TeamDescription); }
public ITeamAliasModel Get(string key) { BusinessWorkflowBase.ValidateRequiredKey(key); return(TeamAliasMapper.MapToModel(TeamAliasesRepository.Get(key))); }
public ITeamAliasModel Get(int id) { BusinessWorkflowBase.ValidateRequiredID(id); return(TeamAliasMapper.MapToModel(TeamAliasesRepository.Get(id))); }
public void Verify_MapToModelListing_AssignsListingOnlyTeamAliasProperties() { // Arrange var mapper = new TeamAliasMapper(); var entity = TeamAliasesMockingSetup.DoMockingSetupForTeamAlias(); // Act var model = mapper.MapToModelListing(entity.Object); // Assert // <None> // Related Objects Assert.Equal(entity.Object.TeamId, model.TeamId); // Return Entity }