public async void Missing_primary_key() { using (var testStore = SqliteTestStore.CreateScratch()) { testStore.ExecuteNonQuery("CREATE TABLE Alicia ( Keys TEXT );"); var results = await Generator.GenerateAsync(new ReverseEngineeringConfiguration { ConnectionString = testStore.Connection.ConnectionString, ProjectPath = "testout", ProjectRootNamespace = "E2E.Sqlite", UseFluentApiOnly = UseFluentApiOnly }); var errorMessage = SqliteDesignStrings.MissingPrimaryKey("Alicia"); var expectedLog = new LoggerMessages { Warn = { errorMessage } }; AssertLog(expectedLog); Assert.Contains(errorMessage, InMemoryFiles.RetrieveFileContents("testout", "Alicia.cs")); } }
public async Task Missing_primary_key() { using (var testStore = SqliteTestStore.CreateScratch()) { testStore.ExecuteNonQuery("CREATE TABLE Alicia ( Keys TEXT );"); var results = await Generator.GenerateAsync(new ReverseEngineeringConfiguration { ConnectionString = testStore.ConnectionString, ProjectPath = TestProjectPath, ProjectRootNamespace = "E2E.Sqlite", UseFluentApiOnly = UseFluentApiOnly, TableSelectionSet = TableSelectionSet.All }); var errorMessage = RelationalDesignStrings.UnableToGenerateEntityType("Alicia"); var expectedLog = new LoggerMessages { Warn = { RelationalDesignStrings.MissingPrimaryKey("Alicia"), errorMessage } }; AssertLog(expectedLog); Assert.Contains(errorMessage, InMemoryFiles.RetrieveFileContents(TestProjectFullPath, Path.GetFileName(results.ContextFile))); } }
public static void Log(string message, LoggerMessages loggerMessages) { switch (loggerMessages) { case LoggerMessages.Unknown: Console.ForegroundColor = ConsoleColor.Black; break; case LoggerMessages.Info: Console.ForegroundColor = ConsoleColor.Black; break; case LoggerMessages.Error: Console.ForegroundColor = ConsoleColor.Red; break; case LoggerMessages.Warning: Console.ForegroundColor = ConsoleColor.Yellow; break; default: goto case LoggerMessages.Unknown; } Console.WriteLine(message); }
/// <summary> /// Starts the server. /// </summary> public void Start() { GrpcServer.Start(); var port = GrpcServer.Ports.FirstOrDefault(); Logger.Info(LoggerMessages.ServerStartedMessage(port.Host, port.Port)); }
public void Dispose() { CloseServerAction.Invoke(); GrpcServer.ShutdownAsync().Wait(); var port = GrpcServer.Ports.FirstOrDefault(); Logger.Info(message: LoggerMessages.ServerClosedMessage(port.Host, port.Port)); }
public async void Principal_missing_primary_key() { using (var testStore = SqliteTestStore.GetOrCreateShared("NoPrincipalPk" + DbSuffix).AsTransient()) { testStore.ExecuteNonQuery(@"CREATE TABLE Dependent ( Id PRIMARY KEY, PrincipalId INT, FOREIGN KEY (PrincipalId) REFERENCES Principal(Id) ); CREATE TABLE Principal ( Id INT);"); testStore.Transaction.Commit(); var results = await Generator.GenerateAsync(new ReverseEngineeringConfiguration { ConnectionString = testStore.Connection.ConnectionString, ProjectPath = "testout", ProjectRootNamespace = "E2E.Sqlite", UseFluentApiOnly = UseFluentApiOnly, TableSelectionSet = TableSelectionSet.All }); var expectedLog = new LoggerMessages { Warn = { RelationalDesignStrings.MissingPrimaryKey("Principal"), RelationalDesignStrings.UnableToGenerateEntityType("Principal"), RelationalDesignStrings.ForeignKeyScaffoldErrorPrincipalTableScaffoldingError("Dependent(PrincipalId)", "Principal") } }; AssertLog(expectedLog); var expectedFileSet = new FileSet(new FileSystemFileService(), Path.Combine(ExpectedResultsParentDir, "NoPrincipalPk")) { Files = { "NoPrincipalPk" + DbSuffix + "Context.expected", "Dependent.expected", } }; var actualFileSet = new FileSet(InMemoryFiles, "testout") { Files = Enumerable.Repeat(results.ContextFile, 1).Concat(results.EntityTypeFiles).Select(Path.GetFileName).ToList() }; AssertEqualFileContents(expectedFileSet, actualFileSet); AssertCompile(actualFileSet); } }
/// <summary> /// Processes part of the HTTP request pipeline. /// </summary> /// <param name="context">The <see cref="HttpContext" /> of the current HTTP request.</param> /// <returns>An awaitable <see cref="Task" />.</returns> public Task InvokeAsync(HttpContext context) { var soap = context.GetSoapContext(); if (soap == null) { _next(context); // TODO: error? } if (soap?.Response != null) { LoggerMessages.LogShortCircuitingPipeline(Logger); return(Task.CompletedTask); } LoggerMessages.LogInvokingMiddleware(Logger, this.GetType()); return(InvokeAsync(soap).AsTask()); }
public async void Principal_missing_primary_key() { using (var testStore = SqliteTestStore.GetOrCreateShared("NoPrincipal").AsTransient()) { testStore.ExecuteNonQuery(@"CREATE TABLE Dependent ( Id PRIMARY KEY, PrincipalId INT, FOREIGN KEY (PrincipalId) REFERENCES Principal(Id) ); CREATE TABLE Principal ( Id INT);"); testStore.Transaction.Commit(); var results = await Generator.GenerateAsync(new ReverseEngineeringConfiguration { Provider = MetadataModelProvider, ConnectionString = testStore.Connection.ConnectionString, Namespace = "E2E.Sqlite", OutputPath = "testout" }); var expectedLog = new LoggerMessages { Warn = { Strings.MissingPrimaryKey("Principal"), Strings.ForeignKeyScaffoldError("Dependent","PrincipalId"), } }; AssertLog(expectedLog); var expectedFileSet = new FileSet(new FileSystemFileService(), "ReverseEngineering/Expected/NoPrincipalPk") { Files = { "ModelContext.expected", "Dependent.expected", "Principal.expected", } }; var actualFileSet = new FileSet(InMemoryFiles, "testout") { Files = results.Select(Path.GetFileName).ToList() }; AssertEqualFileContents(expectedFileSet, actualFileSet); AssertCompile(actualFileSet); } }
public async void It_uses_templates() { var dbContextFileName = "EntityFramework.Sqlite.Design." + ReverseEngineeringGenerator.DbContextTemplateFileName; var entityTypeFileName = "EntityFramework.Sqlite.Design." + ReverseEngineeringGenerator.EntityTypeTemplateFileName; var entityTemplate = "This is an entity type template! (For real)"; var contextTemplate = "Also a 100% legit template"; var outputDir = "gen"; var templatesDir = "templates"; using (var testStore = SqliteTestStore.CreateScratch()) { testStore.ExecuteNonQuery("CREATE TABLE RealMccoy ( Col1 text PRIMARY KEY); "); InMemoryFiles.OutputFile(templatesDir, dbContextFileName, contextTemplate); InMemoryFiles.OutputFile(templatesDir, entityTypeFileName, entityTemplate); var config = new ReverseEngineeringConfiguration { ConnectionString = testStore.Connection.ConnectionString, Provider = MetadataModelProvider, Namespace = "Test", OutputPath = outputDir, CustomTemplatePath = templatesDir }; var filePaths = await Generator.GenerateAsync(config); var expectedLog = new LoggerMessages { Info = { "Using custom template " + Path.Combine(templatesDir, dbContextFileName), "Using custom template " + Path.Combine(templatesDir, entityTypeFileName) } }; AssertLog(expectedLog); Assert.Equal(2, filePaths.Count); foreach (var fileName in filePaths.Select(Path.GetFileName)) { var fileContents = InMemoryFiles.RetrieveFileContents(outputDir, fileName); var contents = fileName.EndsWith("Context.cs") ? contextTemplate : entityTemplate; Assert.Equal(contents, fileContents); } } }
public async Task InvokeAsync(HttpContext context) { using (_logger.BeginScope($"Soap contract namespace: {_options.Namespace}")) using (_logger.BeginScope($"Soap contract name: {_options.Name}")) { await context.Request.EnableRewindAsync(); await using (context.Response.Buffer()) { using (var reader = XmlReader.Create(context.Request.Body)) { var request = Message.CreateMessage(reader, _options.MaxSizeOfHeaders, _version); if (request.Headers.Action == null) { request.Headers.Action = context.Request.Headers["SOAPAction"]; } LoggerMessages.LogIncomingRequest(_logger, ref request); var soap = new SoapContext <TService>(context, request, _version, _options); context.SetSoapContext(soap); try { await Next(context); } catch (TargetInvocationException ex) when(ex.InnerException is FaultException fault) { HandleFaultException(fault, soap); } catch (FaultException ex) { HandleFaultException(ex, soap); } if (soap?.Response == null) { return; // throw exception? } if (context.Response.Body.Length > 0) { return; // response manually written } var response = soap.Response; if (response.IsFault) { context.Response.StatusCode = 500; } else { context.Response.StatusCode = 200; } context.Response.ContentType = soap.ContentType; LoggerMessages.LogOutgoingResponse(_logger, ref response); using (var writer = XmlWriter.Create(context.Response.Body, new XmlWriterSettings { OmitXmlDeclaration = true, Encoding = new UTF8Encoding(false) })) response.WriteMessage(writer); context.Response.RegisterForDispose(request); context.Response.RegisterForDispose(response); } } } }