public void Check_Alias_Save_Test() { _saved = string.Empty; var writerMock = new Mock <IStreamWriter>(); writerMock.Setup(x => x.Write(It.IsAny <string>())).Callback <string>(x => { _saved = x; }); var writer = writerMock.Object; var directorySystemMock = new Mock <IDirectory>(); var directorySystem = directorySystemMock.Object; var fileSystemMock = new Mock <IFile>(); fileSystemMock.Setup(x => x.CreateText(It.IsAny <string>())).Returns(writer); var fileSystem = fileSystemMock.Object; var provider = new AliasProvider(directorySystem, fileSystem); var aliases = provider.GetAliases(); provider.Save(); Assert.Equal("{}", _saved); aliases.Add(new Alias { Key = "Key", Value = "Value" }); provider.Save(); Assert.Equal("{\"Key\":\"Value\"}", _saved); }
/// <inheritdoc/> protected override SqlProvider VisitAlias(AliasProvider provider) { var source = Compile(provider.Source); SqlSelect sourceSelect = source.Request.Statement; var sqlSelect = sourceSelect.ShallowClone(); var columns = sqlSelect.Columns.ToList(); sqlSelect.Columns.Clear(); for (int i = 0; i < columns.Count; i++) { var columnName = provider.Header.Columns[i].Name; columnName = ProcessAliasedName(columnName); var column = columns[i]; var columnRef = column as SqlColumnRef; var columnStub = column as SqlColumnStub; if (!ReferenceEquals(null, columnRef)) { sqlSelect.Columns.Add(SqlDml.ColumnRef(columnRef.SqlColumn, columnName)); } else if (!ReferenceEquals(null, columnStub)) { sqlSelect.Columns.Add(columnStub); } else { sqlSelect.Columns.Add(column, columnName); } } return(CreateProvider(sqlSelect, provider, source)); }
public void AliasColumns(AliasProvider provider) { if (owner.State.Predicates.Count > 0) { owner.State.Predicates = collectorHelper.GenericAliasColumns(provider, owner.State.Predicates); } }
protected override Provider VisitAlias(AliasProvider provider) { var source = VisitCompilable(provider.Source); var newProvider = source != provider.Source ? new AliasProvider(source, provider.Alias) : provider; calculateProviderCollector.AliasColumns(provider); predicateCollector.AliasColumns(provider); return(newProvider); }
public void Check_Empty_Alias_List_Is_Provided_On_NonExisting_File_Test() { var directorySystemMock = new Mock <IDirectory>(); var directorySystem = directorySystemMock.Object; var fileSystemMock = new Mock <IFile>(); var fileSystem = fileSystemMock.Object; var provider = new AliasProvider(directorySystem, fileSystem); List <Alias> aliases = provider.GetAliases().ToList(); Assert.NotNull(aliases); Assert.Equal(0, aliases.Count); }
public void AliasColumns(AliasProvider provider) { if (owner.State.CalculateProviders.Count > 0) { owner.State.CalculateProviders = collectorHelper.GenericAliasColumns(provider, owner.State.CalculateProviders); } if (owner.State.CalculateFilters.Count > 0) { owner.State.CalculateFilters = collectorHelper.GenericAliasColumns(provider, owner.State.CalculateFilters); } }
GenericAliasColumns <TDictKey, TPairKey>(AliasProvider provider, Dictionary <TDictKey, List <Pair <TPairKey, ColumnCollection> > > currentState) { var newFilters = new Dictionary <TDictKey, List <Pair <TPairKey, ColumnCollection> > >(currentState.Count); foreach (var providerPair in currentState) { var newProviderPairValue = new List <Pair <TPairKey, ColumnCollection> >(); foreach (var predicatePair in providerPair.Value) { var newPredicatePair = new Pair <TPairKey, ColumnCollection>( predicatePair.First, predicatePair.Second.Alias(provider.Alias)); newProviderPairValue.Add(newPredicatePair); } newFilters.Add(providerPair.Key, newProviderPairValue); } return(newFilters); }
public void Check_NotEmpty_Alias_List_Is_Provided_On_Existing_File_Test() { var readerMock = new Mock <IStreamReader>(); readerMock.Setup(x => x.ReadToEnd()).Returns("{ \"Key\": \"Value\" }"); var reader = readerMock.Object; var directorySystemMock = new Mock <IDirectory>(); var directorySystem = directorySystemMock.Object; var fileSystemMock = new Mock <IFile>(); fileSystemMock.Setup(x => x.Exists(It.IsAny <string>())).Returns(true); fileSystemMock.Setup(x => x.OpenText(It.IsAny <string>())).Returns(reader); var fileSystem = fileSystemMock.Object; var provider = new AliasProvider(directorySystem, fileSystem); List <Alias> aliases = provider.GetAliases().ToList(); Assert.NotNull(aliases); Assert.Equal(1, aliases.Count); Assert.Equal("Key", aliases[0].Key); Assert.Equal("Value", aliases[0].Value); }
/// <summary> /// Compiles <see cref="AliasProvider"/>. /// </summary> /// <param name="provider">Alias provider.</param> protected abstract TResult VisitAlias(AliasProvider provider);