/// <summary> /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to /// the same compatibility standards as public APIs. It may be changed or removed without notice in /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// </summary> public MigrationsOperations( IOperationReporter reporter, Assembly assembly, Assembly startupAssembly, string projectDir, string?rootNamespace, string?language, bool nullable, string[]?args) { _reporter = reporter; _assembly = assembly; _projectDir = projectDir; _rootNamespace = rootNamespace; _language = language; _nullable = nullable; _args = args ?? Array.Empty <string>(); _contextOperations = new DbContextOperations( reporter, assembly, startupAssembly, projectDir, rootNamespace, language, nullable, _args); _servicesBuilder = new DesignTimeServicesBuilder(assembly, startupAssembly, reporter, _args); }
public void ColumnValueIsCorrectlyDecrypted() { // Arrange var newCardNo = RandomNumbers(14); var credit = new CreditCard { CardNumber = newCardNo, CardType = "TestCard", ExpMonth = byte.Parse(RandomNumbers(1)), ExpYear = short.Parse("20" + RandomNumbers(2)), ModifiedDate = DateTime.UtcNow }; // Act while (_adventureWorksContext.CreditCards.Any(c => c.CardNumber == newCardNo)) { newCardNo = RandomNumbers(14); credit.CardNumber = newCardNo; } _adventureWorksContext.CreditCards.Add(credit); _adventureWorksContext.SaveChanges(); DbContextOperations <AdventureWorks2017Entities> .EncryptColumn("Sales.CreditCard", "CardNumber", "CardNumberEncrypted", "CreditCardID", "CardNumber", newCardNo); RefreshContext(_adventureWorksContext.CreditCards); // Assert Assert.Equal(_adventureWorksContext.CreditCards.FirstOrDefault(c => c.CardNumber == newCardNo).CardNumber, DbContextOperations <AdventureWorks2017Entities> .DecryptColumn("Sales.CreditCard", "CardNumberEncrypted", "CreditCardID", "CardNumber", newCardNo)); // Reverse _adventureWorksContext.CreditCards.Remove(_adventureWorksContext.CreditCards.FirstOrDefault(c => c.CardNumber == newCardNo)); _adventureWorksContext.SaveChanges(); }
public List <Tuple <string, string> > GenerateDebugView(string outputPath) { var result = new List <Tuple <string, string> >(); var assembly = Load(outputPath); if (assembly == null) { throw new ArgumentException("Unable to load project assembly"); } var reporter = new OperationReporter( new OperationReportHandler()); var operations = new DbContextOperations(reporter, assembly, assembly); var types = operations.GetContextTypes().ToList(); if (types.Count == 0) { throw new ArgumentException("No DbContext types found in the project"); } foreach (var type in types) { var dbContext = operations.CreateContext(types[0].Name); var debugView = dbContext.Model.AsModel().DebugView.View; result.Add(new Tuple <string, string>(type.Name, debugView)); } return(result); }
private List <Type> GetDbContextTypes(DbContextOperations operations) { var types = operations.GetContextTypes().ToList(); if (types.Count == 0) { throw new ArgumentException("No EF Core DbContext types found in the project"); } return(types); }
public void ValueIsCorrectlyEncrypted() { // Arrange var authHash = int.Parse(RandomNumbers(5)); var newCardNo = RandomNumbers(14); var encryptedValue = DbContextOperations <AdventureWorks2017Entities> .EncryptValue(newCardNo, authHash); var decryptedValue = DbContextOperations <AdventureWorks2017Entities> .DecryptValue(encryptedValue, authHash); // Assert Assert.Equal(newCardNo, decryptedValue); }
private DbContextOperations GetOperations(string outputPath) { var assembly = Load(outputPath); if (assembly == null) { throw new ArgumentException("Unable to load project assembly"); } var reporter = new OperationReporter( new OperationReportHandler()); var operations = new DbContextOperations(reporter, assembly, assembly); return(operations); }
private DbContext TryCreateContextUsingAppCode(Type dbContextType, Type startupType) { try { // Use EF design APIs to get the DBContext instance. var operationHandler = new OperationReportHandler(); var operationReporter = new OperationReporter(operationHandler); // EF infers the environment (Development/ Production) based on the environment variable // ASPNETCORE_ENVIRONMENT. This should already be set up by the CodeGeneration.Design process. var dbContextOperations = new DbContextOperations( operationReporter, dbContextType.GetTypeInfo().Assembly, startupType.GetTypeInfo().Assembly); var dbContextService = dbContextOperations.CreateContext(dbContextType.FullName); return(dbContextService); } catch (Exception ex) { throw ex.Unwrap(_logger); } }