private ContractResponse <MappingResponse> ConstructResponse(TEntity entity, CrossMappingRequest request) { if (entity != null) { var response = new MappingResponse(); this.AssignIdentifiers( entity, x => response.Mappings.Add(x), x => string.Equals(x.System.Name, request.TargetSystemName, StringComparison.InvariantCultureIgnoreCase) && x.Validity.ValidAt(request.ValidAt)); if (response.HasMultipleDefaultMapping() || response.HasMultipleMappingsWithNoDefault()) { return(new ContractResponse <MappingResponse> { Error = new ContractError { Type = ErrorType.Ambiguous }, IsValid = false }); } if (response.HasMutlipleMappingsWithOneDefault()) { response.Mappings = new MdmIdList() { response.Mappings.Where(x => x.DefaultReverseInd.HasValue && x.DefaultReverseInd.Value). First() }; } return(new ContractResponse <MappingResponse> { Contract = request.Version == entity.Version ? null : response, Version = entity.Version, }); } return(new ContractResponse <MappingResponse> { Error = new ContractError { Type = ErrorType.NotFound }, IsValid = false }); }
public void HasMutlipleMappingsWithOneDefault_should_return_true() { var mappingResponse = new MappingResponse() { Mappings = new MdmIdList() }; mappingResponse.Mappings.Add(new MdmId() { DefaultReverseInd = false }); mappingResponse.Mappings.Add(new MdmId() { DefaultReverseInd = false }); mappingResponse.Mappings.Add(new MdmId() { DefaultReverseInd = true }); Assert.IsTrue(mappingResponse.HasMutlipleMappingsWithOneDefault()); }