public async Task SimpleAuthTest() { var database = new Butterfly.Core.Database.Memory.MemoryDatabase(); //var database = new Butterfly.MySql.MySqlDatabase("Server=127.0.0.1;Uid=test;Pwd=test!123;Database=butterfly_auth_test"); await TruncateData(database); await database.CreateFromResourceFileAsync(Assembly.GetExecutingAssembly(), "Butterfly.Core.Auth.Test.db.sql"); database.SetDefaultValue("id", tableName => Guid.NewGuid().ToString()); database.SetDefaultValue("created_at", tableName => DateTime.Now.ToUnixTimestamp()); database.SetDefaultValue("updated_at", tableName => DateTime.Now.ToUnixTimestamp()); database.AddInputPreprocessor(BaseDatabase.RemapTypeInputPreprocessor <DateTime>(dateTime => dateTime.ToUnixTimestamp())); AuthManager authManager = new AuthManager(database, onForgotPassword: user => { logger.Debug($"onForgotPassword():user={user}"); return(Task.FromResult(0)); }); UserRefToken registerAuthToken = await authManager.RegisterAsync(new { username = "******", first_name = "John", last_name = "Smith", email = "*****@*****.**", password = "******" }); AuthToken authToken = await authManager.AuthenticateAsync(UserRefTokenAuthenticator.AUTH_TYPE, registerAuthToken.id); await authManager.ForgotPasswordAsync("johnsmith"); await Task.Delay(30000); }
public async Task Parse() { IDatabase database = new Butterfly.Core.Database.Memory.MemoryDatabase(); await database.CreateFromResourceFileAsync(Assembly.GetExecutingAssembly(), "Butterfly.Core.Test.db.sql"); var tableRefs = StatementFromRef.ParseFromRefs(database, "employee_contact ec INNER JOIN employee e ON ec.employee_id=e.id AND 1=2 left JOIN department d on e.department_id=d.id and 1=2"); Assert.AreEqual(3, tableRefs.Length); Assert.AreEqual(tableRefs[0].table.Name, "employee_contact"); Assert.AreEqual(tableRefs[0].tableAlias, "ec"); Assert.AreEqual(tableRefs[1].table.Name, "employee"); Assert.AreEqual(tableRefs[1].tableAlias, "e"); Assert.AreEqual(tableRefs[2].table.Name, "department"); Assert.AreEqual(tableRefs[2].tableAlias, "d"); var selectStatement = new SelectStatement(database, "SELECT * FROM employee_contact WHERE contact_id=@contactId ORDER BY seq"); Assert.AreEqual("*", selectStatement.selectClause); Assert.AreEqual("employee_contact", selectStatement.fromClause); Assert.AreEqual("contact_id=@contactId", selectStatement.whereClause); Assert.AreEqual("seq", selectStatement.orderByClause); var selectStatement2 = new SelectStatement(database, @"SELECT ec.id FROM employee_contact ec INNER JOIN employee e ON ec.employee_id=e.id WHERE contact_id=@contactId ORDER BY seq"); Assert.AreEqual("ec.id", selectStatement2.selectClause); }
public static async Task SendPhoneNotifyMessage(INotifyMessageSender notifyMessageSender) { IDatabase database = new Butterfly.Core.Database.Memory.MemoryDatabase(); await database.CreateFromResourceFileAsync(Assembly.GetExecutingAssembly(), "Butterfly.Notify.Test.db.sql"); database.SetDefaultValue("id", tableName => Guid.NewGuid().ToString()); database.SetDefaultValue("created_at", tableName => DateTime.Now); var notifyMessageManager = new NotifyManager(database, phoneNotifyMessageSender: notifyMessageSender); notifyMessageManager.Start(); var notifyMessage = new NotifyMessage("+1 316 712 7412", "+1 316 555 1212", null, "Just testing", null); using (ITransaction transaction = await database.BeginTransactionAsync()) { await notifyMessageManager.Queue(transaction, notifyMessage); } await Task.Delay(200000); }
public static async Task SendEmailNotifyMessage(INotifyMessageSender notifyMessageSender) { IDatabase database = new Butterfly.Core.Database.Memory.MemoryDatabase(); await database.CreateFromResourceFileAsync(Assembly.GetExecutingAssembly(), "Butterfly.Notify.Test.db.sql"); database.SetDefaultValue("id", tableName => Guid.NewGuid().ToString()); database.SetDefaultValue("created_at", tableName => DateTime.Now); var notifyMessageManager = new NotifyManager(database, emailNotifyMessageSender: notifyMessageSender); notifyMessageManager.Start(); var notifyMessage = new NotifyMessage("*****@*****.**", "*****@*****.**", "Test SES", "Just testing", null); using (ITransaction transaction = await database.BeginTransactionAsync()) { await notifyMessageManager.Queue(transaction, notifyMessage); await transaction.CommitAsync(); } await Task.Delay(200000); }